Skip to content
Snippets Groups Projects
Commit d35ecca0 authored by Nathan Hertz's avatar Nathan Hertz
Browse files

Updated logging to use pymygdala's LogHandler class.

parent 8ac9f861
No related branches found
No related tags found
No related merge requests found
...@@ -2,43 +2,36 @@ ...@@ -2,43 +2,36 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from pathlib import Path from pathlib import Path
from setuptools import setup 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() README = Path('README.md').read_text()
requires = [ requires = [
'pika>=1.1,<2',
'pycapo>=0.3.0,<1.0', '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 = [ # tests_require = [
'pytest>=5.4,<6.0' # 'pytest>=5.4,<6.0'
] # ]
setup( setup(
name=Path().absolute().name, name=Path().absolute().name,
version=VERSION, version=VERSION,
description='NRAO Archive Data Fetcher Script', description='Workspaces null executable.',
long_description=README, long_description=README,
author='NRAO SSA Team', author='NRAO SSA Team',
author_email='dms-ssa@nrao.edu', author_email='dms-ssa@nrao.edu',
url='TBD', url='TBD',
license="GPL", license="GPL",
install_requires=requires, install_requires=requires,
tests_require=tests_require, # tests_require=tests_require,
keywords=[], keywords=[],
packages=['datafetcher'], packages=['null'],
package_dir={'':'src'}, package_dir={'':'src'},
classifiers=[ classifiers=[
'Programming Language :: Python :: 3.8' 'Programming Language :: Python :: 3.8'
], ],
entry_points={ entry_points={
'console_scripts': ['datafetcher = datafetcher.commands:main'] 'console_scripts': ['null = null.null:main']
}, },
) )
...@@ -4,17 +4,22 @@ import time ...@@ -4,17 +4,22 @@ import time
import logging import logging
import argparse 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 {}""" _DESCRIPTION = """Workspaces null executable, a status capture test of the system. Version {}"""
# logging.basicConfig()
logger = logging.getLogger("null") logger = logging.getLogger("null")
logger.setLevel(logging.DEBUG) logger.setLevel(logging.INFO)
config = CapoConfig()
class Null: class Null:
def __init__(self, args, verbose): def __init__(self, args, verbose):
self.args = args self.args = args
self.verbose = verbose if verbose:
logger.setLevel(logging.DEBUG)
self.args_to_funcs = { self.args_to_funcs = {
'greeting': self.print_greeting, 'greeting': self.print_greeting,
'exit': self.exit_with_failure, 'exit': self.exit_with_failure,
...@@ -23,27 +28,20 @@ class Null: ...@@ -23,27 +28,20 @@ class Null:
} }
def print_greeting(self): def print_greeting(self):
logger.debug("Hello, world!") logger.info("Hello, world!")
if self.verbose: logger.debug("And goodbye, world...")
logger.debug("And goodbye, world...")
def exit_with_failure(self): 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') sys.exit('Exiting with status code -1')
def take_nap(self): def take_nap(self):
print(self.verbose) logger.debug("Going to sleep...")
if self.verbose:
print("wtf??")
logger.debug("Going to sleep...")
time.sleep(5) time.sleep(5)
if self.verbose: logger.debug("Waking up.")
logger.debug("Waking up.")
def dump_core(self): 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() os.abort()
def execute(self): def execute(self):
...@@ -54,10 +52,13 @@ class Null: ...@@ -54,10 +52,13 @@ class Null:
def make_arg_parser(): def make_arg_parser():
parser = argparse.ArgumentParser(description=_DESCRIPTION.format(version), parser = argparse.ArgumentParser(description=_DESCRIPTION.format(version),
formatter_class=argparse.RawTextHelpFormatter) 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', options.add_argument('-v', '--verbose', action='store_true',
required=False, dest='verbose', default=False, required=False, dest='verbose', default=False,
help='allow the program the gift of speech') 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 = parser.add_mutually_exclusive_group(required=False)
functions.add_argument('-g', '--greeting', action='store_true', functions.add_argument('-g', '--greeting', action='store_true',
required=False, dest='greeting', default=False, required=False, dest='greeting', default=False,
...@@ -73,10 +74,21 @@ def make_arg_parser(): ...@@ -73,10 +74,21 @@ def make_arg_parser():
help='abort program and dump core') help='abort program and dump core')
return parser return parser
def main(): def main():
arg_parser = make_arg_parser() arg_parser = make_arg_parser()
args = arg_parser.parse_args() 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 = Null(args, args.verbose)
null.execute() null.execute()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment