implement a debug mode
authorRalf Jung <post@ralfj.de>
Wed, 23 Oct 2013 16:51:25 +0000 (18:51 +0200)
committerRalf Jung <post@ralfj.de>
Wed, 23 Oct 2013 16:51:25 +0000 (18:51 +0200)
libtuer.py
tuerd

index 097a25abb6894eb1079cfe26802f7fd876d0ebe8..1789b90ce8c9307f22e06d9d5cdfe3623c456988 100644 (file)
@@ -10,7 +10,8 @@ printLevel  = logging.DEBUG
 
 # Mail logging handler
 def sendeMail(subject, text, receivers, sender='sphinx@hacksaar.de', replyTo=None):
-       if not isinstance(type(receivers), list): receivers = [receivers]
+       assert isinstance(receivers, list)
+       if not len(receivers): return # nothing to do
        # construct content
        msg = email.mime.text.MIMEText(text.encode('UTF-8'), 'plain', 'UTF-8')
        msg['Subject'] = subject
diff --git a/tuerd b/tuerd
index 5c91f92a6f3f117b076dfe96d20ebe3297f4a689..1bee788341c776acbb894475409707ea2e78a611 100755 (executable)
--- a/tuerd
+++ b/tuerd
@@ -3,7 +3,16 @@ 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
+
+# Parse arguments
+parser = argparse.ArgumentParser(description='Run a door')
+parser.add_argument("-d", "--debug",
+                                       action="store_true", dest="debug",
+                                       help="Don't send emails")
+args = parser.parse_args()
+if args.debug:
+       import libtuer
+       libtuer.mailAddress = []
 
 # initialize GPIO stuff
 GPIO.setmode(GPIO.BOARD)