Commit 2fe728db authored by Valentin Reis's avatar Valentin Reis

[Feature] Added commandline arguments, config file management, power logging to

the nrm daemon.
parent 86a82d99
......@@ -9,6 +9,7 @@ six = "==1.11.0"
pyzmq = "==16.0.4"
tornado = "==4.5.3"
numpy = "*"
argparse = "*"
[dev-packages]
pytest = "*"
......
#!/usr/bin/env python2
import argparse
import json
import sys
import nrm
import nrm.daemon
def main(argv=None):
if argv is None:
argv = sys.argv
conf_parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter,
add_help=False
)
conf_parser.add_argument("-c", "--configuration",
help="Specify a config json-formatted config file that use any \
CLI option. Any actually provided command-line options \
will silently override a corresponding value from the \
configuration file, if it exists.", metavar="FILE")
conf_parser.add_argument("-d","--print_defaults", action='store_true'
, help="Print the default configuration file.")
args, remaining_argv = conf_parser.parse_known_args()
defaults = { "log":"/tmp/argo_daemon.log"
, "log_power":"/tmp/argo_daemon_power.log" }
if args.print_defaults:
print defaults
return(0)
if args.configuration:
defaults.update(json.load(open(args.configuration)))
parser = argparse.ArgumentParser( parents=[conf_parser])
parser.set_defaults(**defaults)
parser.add_argument("--log", help="Main log file.",metavar="FILE")
parser.add_argument("--log_power", help="Power data log file (High throughput).",metavar="FILE")
args = parser.parse_args(remaining_argv)
nrm.daemon.runner(config=args)
return(0)
if __name__ == "__main__":
nrm.daemon.runner()
sys.exit(main())
{
"log":"/tmp/daemon_log.log"
"log_power":"/tmp/daemon_power.log"
}
......@@ -20,11 +20,12 @@ RPC_MSG = MSGTYPES['up_rpc_rep']
PUB_MSG = MSGTYPES['up_pub']
logger = logging.getLogger('nrm')
logger_power = logging.getLogger('power')
class Daemon(object):
def __init__(self):
def __init__(self, config):
self.target = 100.0
self.config = config
def do_downstream_receive(self, parts):
logger.info("receiving downstream message: %r", parts)
......@@ -316,8 +317,22 @@ class Daemon(object):
ioloop.IOLoop.current().start()
def runner():
def runner(config):
ioloop.install()
logging.basicConfig(level=logging.DEBUG)
daemon = Daemon()
logger.setLevel(logging.DEBUG)
logger_power.setLevel(logging.DEBUG)
if config.log:
print("Logging to %s" %config.log)
logger.addHandler(logging.FileHandler(config.log))
if config.log_power:
print("Logging power data to %s" %config.log_power)
formatter=logging.Formatter('%(message)s')
handler=logging.FileHandler(config.log_power)
handler.setFormatter(formatter)
logger_power.addHandler(handler)
daemon = Daemon(config)
daemon.main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment