dbus_client: make duration configurable
authorHelmut Grohne <helmut@subdivi.de>
Tue, 18 Jun 2013 21:37:33 +0000 (23:37 +0200)
committerHelmut Grohne <helmut@subdivi.de>
Tue, 18 Jun 2013 21:37:33 +0000 (23:37 +0200)
dbus_client.py

index ae2d628..1bec799 100755 (executable)
@@ -27,12 +27,15 @@ def wait_for_signal(proxy, signal):
 
 def main():
     parser = argparse.ArgumentParser(parents=[onoff.dbusutils.dbus_options])
+    parser.add_argument("--duration", type=int, default=10,
+                        help="how long to activate the device in seconds " +
+                        "(default: %(default)d")
     parser.add_argument("command", nargs=argparse.REMAINDER)
     args = parser.parse_args()
     DBusGMainLoop(set_as_default=True)
     proxy = onoff.dbusutils.get_dbus_proxy(args)
     if args.command:
-        st, fd = proxy.activatefd(10)
+        st, fd = proxy.activatefd(args.duration)
         fd = fd.take()
         os.dup2(fd, 254)
         os.close(fd)
@@ -42,7 +45,7 @@ def main():
             print("new state is %d" % st)
         os.execvp(args.command[0], args.command)
     else:
-        st = proxy.activatetime(10)
+        st = proxy.activatetime(args.duration)
         if st != ST_ACTIVE:
             print("state is %d waiting for signal" % st)
             st = wait_for_signal(proxy, "changestate")