From: Ralf Jung Date: Thu, 17 Oct 2013 14:00:15 +0000 (+0200) Subject: Prepare for adding command-line arguments X-Git-Url: https://git.ralfj.de/saartuer.git/commitdiff_plain/41111d6443061891dd2ec7d5bf5ab856c0546fc0 Prepare for adding command-line arguments --- diff --git a/libtuer.py b/libtuer.py index 308179e..097a25a 100644 --- a/libtuer.py +++ b/libtuer.py @@ -6,6 +6,7 @@ import email.mime.text, email.utils syslogLevel = logging.INFO mailLevel = logging.CRITICAL # must be "larger" than syslog level! mailAddress = ['post+tuer'+'@'+'ralfj.de', 'vorstand@lists.hacksaar.de'] +printLevel = logging.DEBUG # Mail logging handler def sendeMail(subject, text, receivers, sender='sphinx@hacksaar.de', replyTo=None): @@ -27,18 +28,20 @@ def sendeMail(subject, text, receivers, sender='sphinx@hacksaar.de', replyTo=Non class Logger: def __init__ (self): self.syslog = logging.getLogger("tuerd") - self.syslog.setLevel(syslogLevel) + self.syslog.setLevel(logging.DEBUG) self.syslog.addHandler(logging.handlers.SysLogHandler(address = '/dev/log', facility = logging.handlers.SysLogHandler.LOG_LOCAL0)) def _log (self, lvl, what): thestr = "%s[%d]: %s" % ("tuerd", os.getpid(), what) # console log - print(thestr) + if lvl >= printLevel: + print(thestr) # syslog - self.syslog.log(lvl, thestr) + if lvl >= syslogLevel: + self.syslog.log(lvl, thestr) # mail log - if lvl >= mailLevel: + if lvl >= mailLevel and mailAddress is not None: sendeMail('Kritischer Türfehler', what, mailAddress) def debug(self, what): diff --git a/statemachine.py b/statemachine.py index 5226576..7c75a7a 100644 --- a/statemachine.py +++ b/statemachine.py @@ -30,7 +30,7 @@ ABOUTOPEN_NERVLIST = [(5, lambda : play_sound("flipswitch")), (5, lambda:play_so # Timeout we wait after the switch was switched to "Closed", until we assume nobody will open the door and we just lock it # ALso the time we wait after the door was opend, till we assume something went wrong and start nerving -LEAVE_TIMEOUT = 4 +LEAVE_TIMEOUT = 20 # play_sound constants SOUNDS_DIRECTORY = "/opt/tuer/sounds/" diff --git a/tuerd b/tuerd index 8c24cfd..5c91f92 100755 --- a/tuerd +++ b/tuerd @@ -2,6 +2,8 @@ import RPi.GPIO as GPIO import statemachine, actor, pins, tysock, waker from libtuer import logger +import argparse +# TODO: implement some arguments, e.g. --debug which does not send e-mails and prints debug stuff # initialize GPIO stuff GPIO.setmode(GPIO.BOARD)