]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blobdiff - src/allmydata/scripts/stats_gatherer.py
bin/tahoe: clean up global-vs-subcommand arguments like --node-directory
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / scripts / stats_gatherer.py
index e799d4e8aac96cea7a534671e63c1150b23bb8c1..bdb357660043307b61d0cdba6aeeaf1cb772f1bd 100644 (file)
@@ -1,16 +1,14 @@
 
-import os
-from twisted.python import usage
+import os, sys
+from allmydata.scripts.common import BasedirOptions
+from allmydata.util.assertutil import precondition
+from allmydata.util.encodingutil import listdir_unicode, quote_output
 
-class CreateStatsGathererOptions(usage.Options):
-    optParameters = [
-        ["basedir", "C", None, "which directory to create the stats-gatherer in"],
-        ]
+class CreateStatsGathererOptions(BasedirOptions):
+    default_nodedir = None
 
-    def parseArgs(self, basedir=None):
-        if basedir is not None:
-            assert self["basedir"] is None
-            self["basedir"] = basedir
+    def getSynopsis(self):
+        return "Usage:  %s create-stats-gatherer [options] NODEDIR" % (self.command_name,)
 
 
 stats_gatherer_tac = """
@@ -26,15 +24,15 @@ application = service.Application('allmydata_stats_gatherer')
 g.setServiceParent(application)
 """
 
-def create_stats_gatherer(config):
-    err = config.stderr
+
+def create_stats_gatherer(config, out=sys.stdout, err=sys.stderr):
     basedir = config['basedir']
-    if not basedir:
-        print >>err, "a basedir was not provided, please use --basedir or -C"
-        return -1
+    # This should always be called with an absolute Unicode basedir.
+    precondition(isinstance(basedir, unicode), basedir)
+
     if os.path.exists(basedir):
-        if os.listdir(basedir):
-            print >>err, "The base directory \"%s\", which is \"%s\" is not empty." % (basedir, os.path.abspath(basedir))
+        if listdir_unicode(basedir):
+            print >>err, "The base directory %s is not empty." % quote_output(basedir)
             print >>err, "To avoid clobbering anything, I am going to quit now."
             print >>err, "Please use a different directory, or empty this one."
             return -1