From 84e9440ed6bae340d0b4ff8813b59f60a10532f8 Mon Sep 17 00:00:00 2001 From: Ralf Ramsauer Date: Sun, 18 Mar 2018 16:35:09 +0100 Subject: [PATCH] doorlockd.py: remove argparse dependency by replacing its logic with flask's config parameter file. Signed-off-by: Ralf Ramsauer --- doorlockd-new/config.cfg | 2 ++ doorlockd-new/doorlockd.py | 14 ++++---------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/doorlockd-new/config.cfg b/doorlockd-new/config.cfg index 911fd3b..6322a90 100644 --- a/doorlockd-new/config.cfg +++ b/doorlockd-new/config.cfg @@ -2,3 +2,5 @@ DEBUG = True SECRET_KEY = 'foobar' BOOTSTRAP_SERVE_LOCAL = True + +SERIAL_PORT = '/dev/ttyS0' diff --git a/doorlockd-new/doorlockd.py b/doorlockd-new/doorlockd.py index a2664fb..03a13eb 100755 --- a/doorlockd-new/doorlockd.py +++ b/doorlockd-new/doorlockd.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 -import argparse import logging import sys @@ -30,7 +29,6 @@ date_fmt = '%Y-%m-%d %H:%M:%S' log_fmt = '%(asctime)-15s %(levelname)-8s %(message)s' log = logging.getLogger() -default_serial = '/dev/ttyS0' default_ldap_uri = 'ldaps://ldap1.binary.kitchen/ ' \ 'ldaps://ldap2.binary.kitchen/ ' \ 'ldaps://ldapm.binary.kitchen/' @@ -162,8 +160,8 @@ class DoorHandler: class Logic: - def __init__(self, device): - self.door_handler = DoorHandler(device) + def __init__(self): + self.door_handler = DoorHandler(webapp.config.get('SERIAL_PORT')) def _try_auth_ldap(self, user, password): log.info('Trying to LDAP auth (user, password) as user %s', user) @@ -265,16 +263,12 @@ def home(): if __name__ == '__main__': - parser = argparse.ArgumentParser('doorlockd', 'Binary Kitchen doorlockd') - parser.add_argument('-s', '--serial', default=default_serial, type=str) - args = parser.parse_args() - logging.basicConfig(level=log_level, stream=sys.stdout, format=log_fmt, datefmt=date_fmt) log.info('Starting doorlockd') - log.info('Using serial port: %s' % args.serial) + log.info('Using serial port: %s' % webapp.config.get('SERIAL_PORT')) - logic = Logic(args.serial) + logic = Logic() socketio.run(webapp, port=8080)