Ticket #1262: remove-m.diff

File remove-m.diff, 9.5 KB (added by warner, at 2010-11-27T09:08:19Z)

remove --multiple/-m from all CLI commands, clean up basedir processing

  • src/allmydata/scripts/common.py

    diff --git a/src/allmydata/scripts/common.py b/src/allmydata/scripts/common.py
    index 96879b6..5eb3147 100644
    a b class BaseOptions(usage.Options): 
    5353
    5454class BasedirMixin:
    5555    default_nodedir = _default_nodedir
    56     allow_multiple = True
    5756
    5857    optParameters = [
    5958        ["basedir", "C", None, "Same as --node-directory."],
    6059    ]
    61     optFlags = [
    62         ["multiple", "m", "Specify multiple node directories at once."],
    63     ]
    6460
    65     def parseArgs(self, *args):
     61    def parseArgs(self, basedir=None):
    6662        if self['node-directory'] and self['basedir']:
    6763            raise usage.UsageError("The --node-directory (or -d) and --basedir (or -C) "
    6864                                   "options cannot both be used.")
    6965
    70         if self['node-directory'] or self['basedir']:
    71             self.basedirs = [argv_to_abspath(self['node-directory'] or self['basedir'])]
     66        if basedir:
     67            b = argv_to_abspath(basedir)
     68        elif self['basedir']:
     69            b = argv_to_abspath(self['basedir'])
     70        elif self['node-directory']:
     71            b = argv_to_abspath(self['node-directory'])
    7272        else:
    73             self.basedirs = []
    74 
    75         if self.allow_multiple and self['multiple']:
    76             self.basedirs.extend(map(argv_to_abspath, args))
    77         else:
    78             if len(args) > 1:
    79                 raise usage.UsageError("I wasn't expecting so many arguments." +
    80                     (self.allow_multiple and
    81                      " Use the --multiple option to specify more than one node directory." or ""))
    82 
    83             if len(args) == 0 and self.default_nodedir and not self.basedirs:
    84                 self.basedirs.append(self.default_nodedir)
    85             elif len(args) > 0:
    86                 self.basedirs.append(argv_to_abspath(args[0]))
     73            b = self.default_nodedir
     74        self['basedir'] = b
    8775
    8876    def postOptions(self):
    89         if not self.basedirs:
     77        if not self['basedir']:
    9078            raise usage.UsageError("A base directory for the node must be provided.")
    91         del self['basedir']
    92         self['basedirs'] = self.basedirs
    9379
    9480
    9581DEFAULT_ALIAS = u"tahoe"
  • src/allmydata/scripts/create_node.py

    diff --git a/src/allmydata/scripts/create_node.py b/src/allmydata/scripts/create_node.py
    index d12c028..8f8e785 100644
    a b def write_node_config(c, config): 
    8989    c.write("\n")
    9090
    9191
    92 def create_node(basedir, config, out=sys.stdout, err=sys.stderr):
     92def create_node(config, out=sys.stdout, err=sys.stderr):
     93    basedir = config['basedir']
    9394    # This should always be called with an absolute Unicode basedir.
    9495    precondition(isinstance(basedir, unicode), basedir)
    9596
    def create_node(basedir, config, out=sys.stdout, err=sys.stderr): 
    144145        print >>out, " The node cannot connect to a grid without it."
    145146    if not config.get("nickname", ""):
    146147        print >>out, " Please set [node]nickname= in tahoe.cfg"
     148    return 0
    147149
    148 
    149 def create_client(basedir, config, out=sys.stdout, err=sys.stderr):
     150def create_client(config, out=sys.stdout, err=sys.stderr):
    150151    config['no-storage'] = True
    151     return create_node(basedir, config, out=out, err=err)
     152    return create_node(config, out=out, err=err)
    152153
    153154
    154 def create_introducer(basedir, config, out=sys.stdout, err=sys.stderr):
     155def create_introducer(config, out=sys.stdout, err=sys.stderr):
     156    basedir = config['basedir']
    155157    # This should always be called with an absolute Unicode basedir.
    156158    precondition(isinstance(basedir, unicode), basedir)
    157159
    def create_introducer(basedir, config, out=sys.stdout, err=sys.stderr): 
    173175    c.close()
    174176
    175177    print >>out, "Introducer created in %s" % quote_output(basedir)
     178    return 0
    176179
    177180
    178181subCommands = [
  • src/allmydata/scripts/keygen.py

    diff --git a/src/allmydata/scripts/keygen.py b/src/allmydata/scripts/keygen.py
    index c1d0978..f2f7809 100644
    a b application = service.Application("allmydata_key_generator") 
    2929k.setServiceParent(application)
    3030"""
    3131
    32 def create_key_generator(basedir, config, out=sys.stdout, err=sys.stderr):
     32def create_key_generator(config, out=sys.stdout, err=sys.stderr):
     33    basedir = config['basedir']
    3334    # This should always be called with an absolute Unicode basedir.
    3435    precondition(isinstance(basedir, unicode), basedir)
    3536
  • src/allmydata/scripts/runner.py

    diff --git a/src/allmydata/scripts/runner.py b/src/allmydata/scripts/runner.py
    index 96333de..1cd8a71 100644
    a b def runner(argv, 
    8787    so.stderr = stderr
    8888    so.stdin = stdin
    8989
    90     rc = 0
    9190    if command in create_dispatch:
    92         f = create_dispatch[command]
    93         for basedir in so.basedirs:
    94             rc = f(basedir, so, stdout, stderr) or rc
     91        rc = create_dispatch[command](so, stdout, stderr)
    9592    elif command in startstop_node.dispatch:
    9693        rc = startstop_node.dispatch[command](so, stdout, stderr)
    9794    elif command in debug.dispatch:
  • src/allmydata/scripts/startstop_node.py

    diff --git a/src/allmydata/scripts/startstop_node.py b/src/allmydata/scripts/startstop_node.py
    index bc2616e..893f2f3 100644
    a b class RestartOptions(BasedirMixin, BaseOptions): 
    2222
    2323class RunOptions(BasedirMixin, BaseOptions):
    2424    default_nodedir = u"."
    25     allow_multiple = False
    2625
    2726    optParameters = [
    2827        ["node-directory", "d", None, "Specify the directory of the node to be run. [default, for 'tahoe run' only: current directory]"],
    29         ["multiple", "m", None, "['tahoe run' cannot accept multiple node directories]"],
    3028    ]
    3129
    32 def do_start(basedir, opts, out=sys.stdout, err=sys.stderr):
     30def start(opts, out=sys.stdout, err=sys.stderr):
     31    basedir = opts['basedir']
    3332    print >>out, "STARTING", quote_output(basedir)
    3433    if not os.path.isdir(basedir):
    3534        print >>err, "%s does not look like a directory at all" % quote_output(basedir)
    def do_start(basedir, opts, out=sys.stdout, err=sys.stderr): 
    6564    # we'll never get here. If application setup fails (e.g. ImportError),
    6665    # run() will raise an exception.
    6766
    68 def do_stop(basedir, out=sys.stdout, err=sys.stderr):
     67def stop(config, out=sys.stdout, err=sys.stderr):
     68    basedir = config['basedir']
    6969    print >>out, "STOPPING", quote_output(basedir)
    7070    pidfile = os.path.join(basedir, "twistd.pid")
    7171    if not os.path.exists(pidfile):
    def do_stop(basedir, out=sys.stdout, err=sys.stderr): 
    121121    # we define rc=1 to mean "I think something is still running, sorry"
    122122    return 1
    123123
    124 def start(config, stdout, stderr):
    125     rc = 0
    126     for basedir in config['basedirs']:
    127         rc = do_start(basedir, config, stdout, stderr) or rc
    128     return rc
    129 
    130 def stop(config, stdout, stderr):
    131     rc = 0
    132     for basedir in config['basedirs']:
    133         rc = do_stop(basedir, stdout, stderr) or rc
    134     return rc
    135 
    136124def restart(config, stdout, stderr):
    137     rc = 0
    138     for basedir in config['basedirs']:
    139         rc = do_stop(basedir, stdout, stderr) or rc
     125    rc = stop(config, stdout, stderr)
    140126    if rc == 2:
    141127        print >>stderr, "ignoring couldn't-stop"
    142128        rc = 0
    143129    if rc:
    144130        print >>stderr, "not restarting"
    145131        return rc
    146     for basedir in config['basedirs']:
    147         rc = do_start(basedir, config, stdout, stderr) or rc
    148     return rc
     132    return start(config, stdout, stderr)
    149133
    150134def run(config, stdout, stderr):
    151135    from twisted.internet import reactor
    152136    from twisted.python import log, logfile
    153137    from allmydata import client
    154138
    155     basedir = config['basedirs'][0]
     139    basedir = config['basedir']
    156140    precondition(isinstance(basedir, unicode), basedir)
    157141
    158142    if not os.path.isdir(basedir):
  • src/allmydata/scripts/stats_gatherer.py

    diff --git a/src/allmydata/scripts/stats_gatherer.py b/src/allmydata/scripts/stats_gatherer.py
    index 0764bfc..54113ea 100644
    a b g.setServiceParent(application) 
    2626"""
    2727
    2828
    29 def create_stats_gatherer(basedir, config, out=sys.stdout, err=sys.stderr):
     29def create_stats_gatherer(config, out=sys.stdout, err=sys.stderr):
     30    basedir = config['basedir']
    3031    # This should always be called with an absolute Unicode basedir.
    3132    precondition(isinstance(basedir, unicode), basedir)
    3233
  • src/allmydata/test/test_runner.py

    diff --git a/src/allmydata/test/test_runner.py b/src/allmydata/test/test_runner.py
    index 6a49f6b..a87911e 100644
    a b class CreateNode(unittest.TestCase): 
    246246        self.failUnless(os.path.exists(n3))
    247247        self.failUnless(os.path.exists(os.path.join(n3, tac)))
    248248
    249         # test the --multiple form
    250         n4 = os.path.join(basedir, command + "-n4")
    251         n5 = os.path.join(basedir, command + "-n5")
    252         argv = ["--quiet", command, "--multiple", n4, n5]
    253         rc, out, err = self.run_tahoe(argv)
    254         self.failUnlessEqual(err, "")
    255         self.failUnlessEqual(out, "")
    256         self.failUnlessEqual(rc, 0)
    257         self.failUnless(os.path.exists(n4))
    258         self.failUnless(os.path.exists(os.path.join(n4, tac)))
    259         self.failUnless(os.path.exists(n5))
    260         self.failUnless(os.path.exists(os.path.join(n5, tac)))
    261 
    262         # make sure it rejects too many arguments without --multiple
     249        # make sure it rejects too many arguments
    263250        argv = [command, "basedir", "extraarg"]
    264251        self.failUnlessRaises(usage.UsageError,
    265252                              runner.runner, argv,