-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 = """
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