diff --git a/README.md b/README.md
index a6ae291f..362a514f 100644
--- a/README.md
+++ b/README.md
@@ -245,6 +245,28 @@ usage: grep_ioc KEYWORD [hutch]
+
grep_pv |
diff --git a/scripts/constants.py b/scripts/constants.py
new file mode 100644
index 00000000..d2ca8e11
--- /dev/null
+++ b/scripts/constants.py
@@ -0,0 +1,27 @@
+# -*- coding: utf-8 -*-
+"""
+Constants used in grep_more_ioc and getPVAliases
+"""
+###############################################################################
+# %% Imports
+###############################################################################
+
+import glob as gb
+
+###############################################################################
+# %% Constants
+###############################################################################
+
+# Check the directories for the iocmanager config file
+VALID_HUTCH = sorted([d for d in gb.glob('/cds/group/pcds/pyps/config'
+ + '/*/')
+ if gb.glob(d + 'iocmanager.cfg')])
+# Trim to 3 letter hutch code, include 'all' = '*'
+VALID_HUTCH = ['all'] + [s.rsplit(r'/', maxsplit=2)[-2] for s in VALID_HUTCH]
+
+# Keys from iocmanager. Found in /cds/group/pcds/config/*/iocmanager/utils.py
+# Update this as needed
+DEF_IMGR_KEYS = ['procmgr_config', 'hosts', 'dir', 'id', 'cmd',
+ 'flags', 'port', 'host', 'disable', 'history',
+ 'delay', 'alias', 'hard']
+
\ No newline at end of file
diff --git a/scripts/getPVAliases.py b/scripts/getPVAliases.py
index dbf32112..7474238f 100644
--- a/scripts/getPVAliases.py
+++ b/scripts/getPVAliases.py
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
"""
A script for gathering alias associations from an IOC
-@author: aberges
"""
###############################################################################
# %% Imports
@@ -18,29 +17,15 @@
search_file, simple_prompt)
from prettytable import PrettyTable
-###############################################################################
-# %% Constants
-###############################################################################
-
-VALID_HUTCH = sorted([s for s
- in next(os.walk('/cds/group/pcds/pyps/config'))[1]
- if '.' not in s]+['all'])
-# Keys from iocmanager. Found in /cds/group/pcds/config/*/iocmanager/utils.py
-# Update this as needed
-DEF_IMGR_KEYS = ['procmgr_config', 'hosts', 'dir', 'id', 'cmd',
- 'flags', 'port', 'host', 'disable', 'history',
- 'delay', 'alias', 'hard']
-
###############################################################################
# %% Functions
###############################################################################
-def request_file_dest(prompt: str,
- default: str = os.getcwd(),) -> str:
+def request_dir(prompt: str,
+ default: str = os.getcwd(),) -> str:
"""
Requests the user for a destination to save a file.
- Tests if the resultant path exists and makes the directory if necessary.
Parameters
----------
@@ -70,25 +55,6 @@ def request_file_dest(prompt: str,
return result
-def flatten_list(input_list: list[list]) -> list[str]:
- """
- Flatten a 2D lists and find its unique values.
- Note: loses order due to set() call. sear
-
- Parameters
- ----------
- input_list: list[list]
- The 2D list to flatten.
-
- Returns
- -------
- list
- The list of unique elements from the 2D input_list
- """
- _result = [e for lst in input_list for e in lst]
- return list(set(_result))
-
-
def build_table(input_data: list[dict], columns: list[str] = None,
**kwargs) -> PrettyTable:
"""
@@ -226,16 +192,16 @@ def show_temp_table(input_data: list, col_list: list):
# parser obj configuration
parser = argparse.ArgumentParser(
prog='gatherPVAliases',
- description="""gathers all record <-> alias associations from a child's
- ioc.cfg, st.cmd, and parent ioc.cfg.""",
- epilog='')
+ description="gathers all record <-> alias associations from a child's "
+ "ioc.cfg, st.cmd, and parent ioc.cfg.",
+ epilog='')
# main command arguments
parser.add_argument('patt', type=str)
parser.add_argument('hutch', type=str)
parser.add_argument('-d', '--dry_run', action='store_true',
default=False,
- help='''Forces a dry run for the script.
- No files are saved.''')
+ help="Forces a dry run for the script. "
+ "No files are saved.")
###############################################################################
# %% Main
@@ -356,8 +322,8 @@ def main():
# write to file, else do nothing
if (len(final_output) > 0) & (args.dry_run is False):
- dest = request_file_dest('Choose base file destination',
- default_dest)
+ dest = request_dir('Choose base file destination',
+ default_dest)
# make sure the destination exists and mkdir if it doesn't
if os.path.exists(dest) is False:
print(Fore.LIGHTBLUE_EX
diff --git a/scripts/getPVAliases.sh b/scripts/getPVAliases.sh
index d62b6b94..1f5bb1f4 100755
--- a/scripts/getPVAliases.sh
+++ b/scripts/getPVAliases.sh
@@ -1,4 +1,6 @@
#!/usr/bin/bash
# execute python script
-/cds/group/pcds/pyps/conda/py39/envs/pcds-5.8.2/bin/python "$ENG_TOOLS_SCRIPTS/getPVAliases.py" "$@"
+THIS_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
+
+/cds/group/pcds/pyps/conda/py39/envs/pcds-5.8.2/bin/python "${THIS_DIR}/getPVAliases.py" "$@"
diff --git a/scripts/grep_more_ioc.py b/scripts/grep_more_ioc.py
index a86432fc..126ab42d 100644
--- a/scripts/grep_more_ioc.py
+++ b/scripts/grep_more_ioc.py
@@ -1,6 +1,6 @@
-"""A tool for enhancing the grep_ioc CLI tool for ECS-Delivery team
-enginer = aberges
-version = 1.0.6
+# -*- coding: utf-8 -*-
+"""
+A tool for enhancing the grep_ioc CLI tool for ECS-Delivery team
"""
###############################################################################
# %% Imports
@@ -15,6 +15,7 @@
from shutil import get_terminal_size
import pandas as pd
+from constants import (DEF_IMGR_KEYS, VALID_HUTCH)
from colorama import Fore, Style
###############################################################################
@@ -25,19 +26,6 @@
pd.set_option("display.max_rows", 1000)
-###############################################################################
-# %% Constants
-###############################################################################
-
-VALID_HUTCH = sorted([s for s
- in next(os.walk('/cds/group/pcds/pyps/config'))[1]
- if '.' not in s]+['all'])
-# Keys from iocmanager. Found in /cds/group/pcds/config/*/iocmanager/utils.py
-# Update this as needed
-DEF_IMGR_KEYS = ['procmgr_config', 'hosts', 'dir', 'id', 'cmd',
- 'flags', 'port', 'host', 'disable', 'history',
- 'delay', 'alias', 'hard']
-
###############################################################################
# %% Functions
###############################################################################
@@ -90,10 +78,14 @@ def search_file(*, file: str, output: list = None,
def print_skip_comments(file: str):
"""Prints contents of a file while ignoring comments"""
- with open(file, 'r', encoding='utf_8') as _f:
- for line in _f.readlines():
- if not line.strip().startswith('#'):
- print(line.strip())
+ try:
+ with open(file, 'r', encoding='utf_8') as _f:
+ for line in _f.readlines():
+ if not line.strip().startswith('#'):
+ print(line.strip())
+ except FileNotFoundError:
+ print(f'{Fore.RED}Could not open {Style.RESET_ALL}{file}'
+ + f' {Fore.RED}does not exist{Style.RESET_ALL}')
def simple_prompt(prompt: str, default: str = 'N'):
@@ -323,9 +315,9 @@ def build_parser():
help='Flag for excluding based'
+ ' on the "disabled" state.')
# subparsers
- subparsers = (parser
- .add_subparsers(help='Follow-up commands after grep_ioc '
- + 'executes'))
+ subparsers = parser.add_subparsers(
+ help='Follow-up commands after grep_ioc executes'
+ )
# --------------------------------------------------------------------------- #
# print subarguments
# --------------------------------------------------------------------------- #
@@ -350,7 +342,7 @@ def build_parser():
print_frame.add_argument('-s', '--print_dirs', action='store_true',
default=False,
help='Prints the child & parent IOC'
- + 'directories as the final output')
+ + ' directories as the final output')
# --------------------------------------------------------------------------- #
# search subarguments
# --------------------------------------------------------------------------- #
@@ -365,7 +357,7 @@ def build_parser():
metavar='PATT')
search.add_argument('-q', '--quiet', action='store_true', default=False,
help='Surpresses file warning for paths that do not'
- + 'exist.')
+ + ' exist.')
search.add_argument('-o', '--only_search', action='store_true',
default=False,
help="Don't print the dataframe, just search results.")
diff --git a/scripts/grep_more_ioc.sh b/scripts/grep_more_ioc.sh
index c9451236..c20c434e 100755
--- a/scripts/grep_more_ioc.sh
+++ b/scripts/grep_more_ioc.sh
@@ -1,4 +1,6 @@
#!/usr/bin/bash
# execute python script
-/cds/group/pcds/pyps/conda/py39/envs/pcds-5.8.4/bin/python "$ENG_TOOLS_SCRIPTS/grep_more_ioc.py" "$@"
+THIS_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
+
+/cds/group/pcds/pyps/conda/py39/envs/pcds-5.8.4/bin/python "${THIS_DIR}/grep_more_ioc.py" "$@"
|