Prepare for adding command-line arguments
authorRalf Jung <post@ralfj.de>
Thu, 17 Oct 2013 14:00:15 +0000 (16:00 +0200)
committerRalf Jung <post@ralfj.de>
Thu, 17 Oct 2013 14:00:15 +0000 (16:00 +0200)
libtuer.py
statemachine.py
tuerd

index 308179ee01568679d3b2096f6a9a29c1ccdd7789..097a25abb6894eb1079cfe26802f7fd876d0ebe8 100644 (file)
@@ -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):
index 522657637b9731d236b853889db6f9af5a362395..7c75a7a273868cfc3f684d0f4df6214d4c1f761e 100644 (file)
@@ -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 8c24cfd81777ae4b34f178a0b553a0514bdd5077..5c91f92a6f3f117b076dfe96d20ebe3297f4a689 100755 (executable)
--- 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)