Skip to content

Commit

Permalink
improve logging for command line options
Browse files Browse the repository at this point in the history
  • Loading branch information
txoof committed Feb 9, 2024
1 parent 131c569 commit c7f7405
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 148 deletions.
80 changes: 63 additions & 17 deletions paperpi/paperpi.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,12 @@
" \n",
" # convert all config values to int, float, etc.\n",
" config = config_str_to_val(config)\n",
"\n",
" log_level = config['main'].get('log_level', 'INFO')\n",
" \n",
" logger.setLevel(log_level)\n",
" logging.root.setLevel(log_level) \n",
" \n",
" if cmd_args.options.version:\n",
" print(constants.VERSION_STRING)\n",
" return\n",
Expand All @@ -675,17 +680,17 @@
" Screen.list_compatible()\n",
" return\n",
" \n",
" if cmd_args.options.list_plugins:\n",
" get_help.get_help(plugin_path=Path(constants.BASE_DIRECTORY)/'plugins')\n",
" return\n",
" # if cmd_args.options.list_plugins:\n",
" # get_help.get_help(plugin_path=Path(constants.BASE_DIRECTORY)/'plugins')\n",
" # return\n",
" \n",
" if cmd_args.options.plugin_info:\n",
" get_help.get_help(cmd_args.options.plugin_info)\n",
" return\n",
" # if cmd_args.options.plugin_info:\n",
" # get_help.get_help(cmd_args.options.plugin_info)\n",
" # return\n",
" \n",
" if cmd_args.options.run_plugin_func:\n",
" run_module.run_module(cmd_args.options.run_plugin_func)\n",
" return \n",
" # if cmd_args.options.run_plugin_func:\n",
" # run_module.run_module(cmd_args.options.run_plugin_func)\n",
" # return \n",
"\n",
" if cmd_args.options.add_config:\n",
" try:\n",
Expand All @@ -707,14 +712,26 @@
" \n",
" log_level = config['main'].get('log_level', 'INFO')\n",
"\n",
" if cmd_args.options.list_plugins:\n",
" get_help.get_help(plugin_path=Path(constants.BASE_DIRECTORY)/'plugins')\n",
" return\n",
" \n",
" if cmd_args.options.plugin_info:\n",
" get_help.get_help(cmd_args.options.plugin_info)\n",
" return\n",
" \n",
" if cmd_args.options.run_plugin_func:\n",
" run_module.run_module(cmd_args.options.run_plugin_func)\n",
" return \n",
"\n",
"\n",
" \n",
" logger.info(f'********** {constants.APP_NAME} {constants.VERSION} Starting **********')\n",
" if cmd_args.options.main__daemon:\n",
" logger.info(f'{constants.APP_NAME} is running in daemon mode')\n",
" else:\n",
" logger.info(f'{constants.APP_NAME} is running in on-demand mode')\n",
" \n",
" logger.setLevel(log_level)\n",
" logging.root.setLevel(log_level)\n",
"\n",
"\n",
" \n",
" logger.debug(f'configuration:\\n{config}\\n\\n')\n",
Expand Down Expand Up @@ -775,6 +792,18 @@
" return exit_code"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5202f66c-fa4d-4bc2-a376-4ace6fe6610c",
"metadata": {},
"outputs": [],
"source": [
"# add test arguments here \n",
"# test_args = [\"--run_plugin_func\", \"lms_client.scan_servers\"]\n",
"test_args = []"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -784,15 +813,32 @@
"source": [
"if __name__ == \"__main__\":\n",
" # remove jupyter runtime junk for testing\n",
" try:\n",
"\n",
" if '-f' in sys.argv:\n",
" i = sys.argv.index('-f')\n",
" t = sys.argv[:i] + sys.argv[i+2:]\n",
" sys.argv = t\n",
" except ValueError:\n",
" pass\n",
" if 'jupyter/' in sys.argv[i+1]:\n",
" try:\n",
" t = sys.argv[:i] + sys.argv[i+2:]\n",
" sys.argv = t\n",
" except ValueError:\n",
" pass\n",
" for i in test_args:\n",
" if i not in sys.argv:\n",
" sys.argv.append(i)\n",
" \n",
" exit_code = main()\n",
" sys.exit(exit_code)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "110c373b-ec05-4344-b3af-f73c0d7b5d97",
"metadata": {},
"outputs": [],
"source": [
"sys.argv"
]
}
],
"metadata": {
Expand Down
64 changes: 47 additions & 17 deletions paperpi/paperpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,12 @@ def main():

# convert all config values to int, float, etc.
config = config_str_to_val(config)

log_level = config['main'].get('log_level', 'INFO')

logger.setLevel(log_level)
logging.root.setLevel(log_level)

if cmd_args.options.version:
print(constants.VERSION_STRING)
return
Expand All @@ -579,17 +584,17 @@ def main():
Screen.list_compatible()
return

if cmd_args.options.list_plugins:
get_help.get_help(plugin_path=Path(constants.BASE_DIRECTORY)/'plugins')
return
# if cmd_args.options.list_plugins:
# get_help.get_help(plugin_path=Path(constants.BASE_DIRECTORY)/'plugins')
# return

if cmd_args.options.plugin_info:
get_help.get_help(cmd_args.options.plugin_info)
return
# if cmd_args.options.plugin_info:
# get_help.get_help(cmd_args.options.plugin_info)
# return

if cmd_args.options.run_plugin_func:
run_module.run_module(cmd_args.options.run_plugin_func)
return
# if cmd_args.options.run_plugin_func:
# run_module.run_module(cmd_args.options.run_plugin_func)
# return

if cmd_args.options.add_config:
try:
Expand All @@ -611,14 +616,26 @@ def main():

log_level = config['main'].get('log_level', 'INFO')

if cmd_args.options.list_plugins:
get_help.get_help(plugin_path=Path(constants.BASE_DIRECTORY)/'plugins')
return

if cmd_args.options.plugin_info:
get_help.get_help(cmd_args.options.plugin_info)
return

if cmd_args.options.run_plugin_func:
run_module.run_module(cmd_args.options.run_plugin_func)
return



logger.info(f'********** {constants.APP_NAME} {constants.VERSION} Starting **********')
if cmd_args.options.main__daemon:
logger.info(f'{constants.APP_NAME} is running in daemon mode')
else:
logger.info(f'{constants.APP_NAME} is running in on-demand mode')

logger.setLevel(log_level)
logging.root.setLevel(log_level)



logger.debug(f'configuration:\n{config}\n\n')
Expand Down Expand Up @@ -679,13 +696,26 @@ def main():
return exit_code
# -

# add test arguments here
# test_args = ["--run_plugin_func", "lms_client.scan_servers"]
test_args = []

if __name__ == "__main__":
# remove jupyter runtime junk for testing
try:

if '-f' in sys.argv:
i = sys.argv.index('-f')
t = sys.argv[:i] + sys.argv[i+2:]
sys.argv = t
except ValueError:
pass
if 'jupyter/' in sys.argv[i+1]:
try:
t = sys.argv[:i] + sys.argv[i+2:]
sys.argv = t
except ValueError:
pass
for i in test_args:
if i not in sys.argv:
sys.argv.append(i)

exit_code = main()
sys.exit(exit_code)

sys.argv
Loading

0 comments on commit c7f7405

Please sign in to comment.