Skip to content

Commit

Permalink
Added option to specify where CONFIG_FILE_LOCATION is when running mo…
Browse files Browse the repository at this point in the history
…nitor tools
  • Loading branch information
nmassey001 committed Jan 30, 2025
1 parent 1da2a25 commit 6711964
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
21 changes: 18 additions & 3 deletions nlds_utils/nlds_monitor.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#! /usr/bin/env python
# encoding: utf-8

import click
from datetime import datetime, timedelta

Expand All @@ -11,11 +14,12 @@
)
from nlds.rabbit.consumer import State
import nlds.server_config as CFG
from nlds.nlds_setup import CONFIG_FILE_LOCATION


def connect_to_monitor():
def connect_to_monitor(settings: str = CONFIG_FILE_LOCATION):
"""Connects to the monitor database"""
config = CFG.load_config()
config = CFG.load_config(settings)
db_engine = config["monitor_q"]["db_engine"]
db_options = config["monitor_q"]["db_options"]
db_options["echo"] = False
Expand Down Expand Up @@ -406,6 +410,13 @@ def construct_record_dict(
default=False,
help="Switch between ascending and descending order.",
)
@click.option(
"-S",
"--settings",
default="",
type=str,
help="The location of the settings file for NLDS.",
)
def view_jobs(
user,
group,
Expand All @@ -417,6 +428,7 @@ def view_jobs(
end_time,
complex,
order,
settings,
) -> None:
"""Returns all NLDS jobs filtered by user options."""

Expand All @@ -428,7 +440,10 @@ def view_jobs(
state, record_state = validate_inputs(start_time, end_time, state, record_state)

# Connect to the monitor database
session = connect_to_monitor()
if settings != "":
session = connect_to_monitor(settings)
else:
session = connect_to_monitor()
query = query_monitor_db(
session,
user,
Expand Down
5 changes: 3 additions & 2 deletions nlds_utils/reset_storage_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
from nlds_processors.catalog.catalog_models import Storage, File, Location
from nlds.details import PathDetails
import nlds.server_config as CFG
from nlds.nlds_setup import CONFIG_FILE_LOCATION


def _connect_to_catalog():
config = CFG.load_config()
def _connect_to_catalog(config_file_path: str = CONFIG_FILE_LOCATION):
config = CFG.load_config(config_file_path)

db_engine = config["catalog_q"]["db_engine"]
db_options = config["catalog_q"]["db_options"]
Expand Down
25 changes: 21 additions & 4 deletions nlds_utils/view_holding_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def print_file(file: File):
f"{integer_permissions_to_string(file.file_permissions)}"
)


def print_location(location: Location):
click.echo(f"{'':<6}│ │ │ ├─┐ {'id':<17}: {location.id}")
click.echo(f"{'':<6}│ │ │ │ ├─ {'type':<16}: {str(location.storage_type)}")
Expand All @@ -103,18 +104,21 @@ def print_location(location: Location):
click.echo(f"{'':<6}│ │ │ │ ├─ {'path':<16}: {location.path}")
click.echo(f"{'':<6}│ │ │ │ └─ {'access time':<16}: {location.access_time}")


def print_aggregation(aggregation: Aggregation):
click.echo(f"{'':<8}├─┐ {'id':<16}: {aggregation.id}")
click.echo(f"{'':<8}│ ├─ {'tarfile':<16}: {aggregation.tarname}")
click.echo(f"{'':<8}│ ├─ {'checksum':<16}: {aggregation.checksum}")
click.echo(f"{'':<8}│ └─ {'algorithm':<16}: {aggregation.algorithm}")


def print_file_compact_header():
click.echo(
f"{'':<6}{'':<4}{'Original Path':<48}{'User':<6}{'Group':<7}"
f"{'Size':<8}{'Type':<8}{'Location':<24}{'Aggregation':48}"
)


def print_file_compact(file: File, nlds_cat: object):
location_str = ""
for l in file.locations:
Expand Down Expand Up @@ -156,9 +160,18 @@ def print_file_compact(file: File, nlds_cat: object):
is_flag=True,
default=False,
type=bool,
help="Display in compact format, one file per line"
help="Display in compact format, one file per line.",
)
def view_holding(user: str, group: str, holding_id: int, compact: bool) -> None:
@click.option(
"-S",
"--settings",
default="",
type=str,
help="The location of the settings file for NLDS.",
)
def view_holding(
user: str, group: str, holding_id: int, compact: bool, settings: str
) -> None:
"""View the full Holding, including Transactions, Tags, Files, Locations and
Aggregations."""
if user is None:
Expand All @@ -167,8 +180,12 @@ def view_holding(user: str, group: str, holding_id: int, compact: bool) -> None:
raise click.UsageError("Error - group not specified")
if holding_id is None:
raise click.UsageError("Error - holding id not specified")

nlds_cat = _connect_to_catalog()

if settings != "":
nlds_cat = _connect_to_catalog(settings)
else:
nlds_cat = _connect_to_catalog()

nlds_cat.start_session()

holding = nlds_cat.get_holding(user=user, group=group, holding_id=holding_id)[0]
Expand Down

0 comments on commit 6711964

Please sign in to comment.