diff --git a/apps/cli/executables/null/setup.py b/apps/cli/executables/null/setup.py index 84415da77099fcd47dcf8120dd31be7b8a1f0b1c..9f835748d22ee2fd3e36ddaa4b40763b44a5acf8 100644 --- a/apps/cli/executables/null/setup.py +++ b/apps/cli/executables/null/setup.py @@ -2,43 +2,36 @@ # -*- coding: utf-8 -*- from pathlib import Path - from setuptools import setup -VERSION = open('_version.py').readlines()[-1].split()[-1].strip("\"'") +VERSION = open('src/null/_version.py').readlines()[-1].split()[-1].strip("\"'") README = Path('README.md').read_text() requires = [ - 'pika>=1.1,<2', 'pycapo>=0.3.0,<1.0', - 'beautifulsoup4>=4.9.1,<5.0', - 'lxml>=4.3.2,<5.0', - 'psycopg2>=2.8.5,<3.0', - 'pyopenssl>=19.1.0,<20.0', - 'requests>=2.23,<3.0' ] -tests_require = [ - 'pytest>=5.4,<6.0' -] +# tests_require = [ +# 'pytest>=5.4,<6.0' +# ] setup( name=Path().absolute().name, version=VERSION, - description='NRAO Archive Data Fetcher Script', + description='Workspaces null executable.', long_description=README, author='NRAO SSA Team', author_email='dms-ssa@nrao.edu', url='TBD', license="GPL", install_requires=requires, - tests_require=tests_require, + # tests_require=tests_require, keywords=[], - packages=['datafetcher'], + packages=['null'], package_dir={'':'src'}, classifiers=[ 'Programming Language :: Python :: 3.8' ], entry_points={ - 'console_scripts': ['datafetcher = datafetcher.commands:main'] + 'console_scripts': ['null = null.null:main'] }, ) diff --git a/apps/cli/executables/null/src/null/null.py b/apps/cli/executables/null/src/null/null.py index 282c1cc6bbe792ca32ce0757c6c699a41be2c97e..3835930926f4a7838ef86b05468abbdfd344d756 100644 --- a/apps/cli/executables/null/src/null/null.py +++ b/apps/cli/executables/null/src/null/null.py @@ -4,17 +4,22 @@ import time import logging import argparse -from _version import ___version___ as version +from pymygdala import LogHandler +from pycapo import CapoConfig +from ._version import ___version___ as version _DESCRIPTION = """Workspaces null executable, a status capture test of the system. Version {}""" +# logging.basicConfig() logger = logging.getLogger("null") -logger.setLevel(logging.DEBUG) +logger.setLevel(logging.INFO) +config = CapoConfig() class Null: def __init__(self, args, verbose): self.args = args - self.verbose = verbose + if verbose: + logger.setLevel(logging.DEBUG) self.args_to_funcs = { 'greeting': self.print_greeting, 'exit': self.exit_with_failure, @@ -23,27 +28,20 @@ class Null: } def print_greeting(self): - logger.debug("Hello, world!") - if self.verbose: - logger.debug("And goodbye, world...") + logger.info("Hello, world!") + logger.debug("And goodbye, world...") def exit_with_failure(self): - if self.verbose: - logger.error("Error purposefully induced.") + logger.error("Error purposefully induced.") sys.exit('Exiting with status code -1') def take_nap(self): - print(self.verbose) - if self.verbose: - print("wtf??") - logger.debug("Going to sleep...") + logger.debug("Going to sleep...") time.sleep(5) - if self.verbose: - logger.debug("Waking up.") + logger.debug("Waking up.") def dump_core(self): - if self.verbose: - logger.debug("Aborting and dumping core...", stack_info=True) + logger.debug("Aborting and dumping core...", stack_info=True) os.abort() def execute(self): @@ -54,10 +52,13 @@ class Null: def make_arg_parser(): parser = argparse.ArgumentParser(description=_DESCRIPTION.format(version), formatter_class=argparse.RawTextHelpFormatter) - options = parser.add_argument_group('options', 'settings for altered program behavior') + options = parser.add_argument_group('options', 'settings for altering program behavior') options.add_argument('-v', '--verbose', action='store_true', required=False, dest='verbose', default=False, help='allow the program the gift of speech') + options.add_argument('-P', '--profile', action='store', + required=True, dest='profile', default=False, + help='profile name to use, e.g. test, production') functions = parser.add_mutually_exclusive_group(required=False) functions.add_argument('-g', '--greeting', action='store_true', required=False, dest='greeting', default=False, @@ -73,10 +74,21 @@ def make_arg_parser(): help='abort program and dump core') return parser - def main(): arg_parser = make_arg_parser() args = arg_parser.parse_args() + handler = LogHandler(profile=args.profile, application='null_executable') + logger.addHandler(handler) + + # Shamelessly stolen from epilogue with a twist: allow for explict profile setting via the CL + if 'CAPO_PROFILE' not in os.environ and '' == args.profile: + # try to synthesize a profile from our installation root + profile = os.path.abspath(sys.argv[0]).split(os.path.sep)[-3] + os.environ['CAPO_PROFILE'] = profile + print('No CAPO_PROFILE explicitly set, synthesizing {0} by path'.format(str(profile))) + elif '' != args.profile: + os.environ['CAPO_PROFILE'] = args.profile + null = Null(args, args.verbose) null.execute()