[tor-commits] [ooni-probe/master] ooniprobe_agent: fix behavior when no command is specified

art at torproject.org art at torproject.org
Mon Sep 19 12:14:25 UTC 2016


commit 300660ff9873d45d78e54b4a9c09c7c659afe6f5
Author: Simone Basso <bassosimone at gmail.com>
Date:   Mon Sep 19 11:02:17 2016 +0200

    ooniprobe_agent: fix behavior when no command is specified
---
 ooni/scripts/ooniprobe_agent.py | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/ooni/scripts/ooniprobe_agent.py b/ooni/scripts/ooniprobe_agent.py
index 4c97f5e..49694eb 100644
--- a/ooni/scripts/ooniprobe_agent.py
+++ b/ooni/scripts/ooniprobe_agent.py
@@ -12,6 +12,7 @@ from twisted.python import usage
 from ooni.utils import log, is_process_running
 from ooni.settings import config
 from ooni.agent.agent import AgentService
+from ooni import __version__
 
 
 class StartOoniprobeAgentPlugin:
@@ -38,6 +39,10 @@ class RunOptions(usage.Options):
     pass
 
 class AgentOptions(usage.Options):
+
+    synopsis = """%s [options] command
+    """ % (os.path.basename(sys.argv[0]),)
+
     subCommands = [
         ['start', None, StartOptions, "Start the ooniprobe-agent in the "
                                       "background"],
@@ -45,9 +50,17 @@ class AgentOptions(usage.Options):
         ['status', None, StatusOptions, "Show status of the ooniprobe-agent"],
         ['run', None, RunOptions, "Run the ooniprobe-agent in the foreground"]
     ]
+
     def postOptions(self):
         self.twistd_args = []
 
+    def opt_version(self):
+        """
+        Display the ooniprobe version and exit.
+        """
+        print("ooniprobe-agent version:", __version__)
+        sys.exit(0)
+
 def start_agent(options=None):
     config.set_paths()
     config.initialize_ooni_home()
@@ -188,8 +201,9 @@ def run():
     options = AgentOptions()
     options.parseOptions()
 
-    if options.subCommand == "run":
-        options.twistd_args += ("--nodaemon",)
+    if options.subCommand == None:
+        print(options)
+        return
 
     if options.subCommand == "stop":
         return stop_agent()
@@ -197,6 +211,9 @@ def run():
     if options.subCommand == "status":
         return status_agent()
 
+    if options.subCommand == "run":
+        options.twistd_args += ("--nodaemon",)
+
     return start_agent(options)
 
 if __name__ == "__main__":





More information about the tor-commits mailing list