diff --git a/src/allmydata/scripts/common.py b/src/allmydata/scripts/common.py
index 96879b6..5eb3147 100644
a
|
b
|
class BaseOptions(usage.Options): |
53 | 53 | |
54 | 54 | class BasedirMixin: |
55 | 55 | default_nodedir = _default_nodedir |
56 | | allow_multiple = True |
57 | 56 | |
58 | 57 | optParameters = [ |
59 | 58 | ["basedir", "C", None, "Same as --node-directory."], |
60 | 59 | ] |
61 | | optFlags = [ |
62 | | ["multiple", "m", "Specify multiple node directories at once."], |
63 | | ] |
64 | 60 | |
65 | | def parseArgs(self, *args): |
| 61 | def parseArgs(self, basedir=None): |
66 | 62 | if self['node-directory'] and self['basedir']: |
67 | 63 | raise usage.UsageError("The --node-directory (or -d) and --basedir (or -C) " |
68 | 64 | "options cannot both be used.") |
69 | 65 | |
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']) |
72 | 72 | 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 |
87 | 75 | |
88 | 76 | def postOptions(self): |
89 | | if not self.basedirs: |
| 77 | if not self['basedir']: |
90 | 78 | raise usage.UsageError("A base directory for the node must be provided.") |
91 | | del self['basedir'] |
92 | | self['basedirs'] = self.basedirs |
93 | 79 | |
94 | 80 | |
95 | 81 | DEFAULT_ALIAS = u"tahoe" |
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): |
89 | 89 | c.write("\n") |
90 | 90 | |
91 | 91 | |
92 | | def create_node(basedir, config, out=sys.stdout, err=sys.stderr): |
| 92 | def create_node(config, out=sys.stdout, err=sys.stderr): |
| 93 | basedir = config['basedir'] |
93 | 94 | # This should always be called with an absolute Unicode basedir. |
94 | 95 | precondition(isinstance(basedir, unicode), basedir) |
95 | 96 | |
… |
… |
def create_node(basedir, config, out=sys.stdout, err=sys.stderr): |
144 | 145 | print >>out, " The node cannot connect to a grid without it." |
145 | 146 | if not config.get("nickname", ""): |
146 | 147 | print >>out, " Please set [node]nickname= in tahoe.cfg" |
| 148 | return 0 |
147 | 149 | |
148 | | |
149 | | def create_client(basedir, config, out=sys.stdout, err=sys.stderr): |
| 150 | def create_client(config, out=sys.stdout, err=sys.stderr): |
150 | 151 | config['no-storage'] = True |
151 | | return create_node(basedir, config, out=out, err=err) |
| 152 | return create_node(config, out=out, err=err) |
152 | 153 | |
153 | 154 | |
154 | | def create_introducer(basedir, config, out=sys.stdout, err=sys.stderr): |
| 155 | def create_introducer(config, out=sys.stdout, err=sys.stderr): |
| 156 | basedir = config['basedir'] |
155 | 157 | # This should always be called with an absolute Unicode basedir. |
156 | 158 | precondition(isinstance(basedir, unicode), basedir) |
157 | 159 | |
… |
… |
def create_introducer(basedir, config, out=sys.stdout, err=sys.stderr): |
173 | 175 | c.close() |
174 | 176 | |
175 | 177 | print >>out, "Introducer created in %s" % quote_output(basedir) |
| 178 | return 0 |
176 | 179 | |
177 | 180 | |
178 | 181 | subCommands = [ |
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") |
29 | 29 | k.setServiceParent(application) |
30 | 30 | """ |
31 | 31 | |
32 | | def create_key_generator(basedir, config, out=sys.stdout, err=sys.stderr): |
| 32 | def create_key_generator(config, out=sys.stdout, err=sys.stderr): |
| 33 | basedir = config['basedir'] |
33 | 34 | # This should always be called with an absolute Unicode basedir. |
34 | 35 | precondition(isinstance(basedir, unicode), basedir) |
35 | 36 | |
diff --git a/src/allmydata/scripts/runner.py b/src/allmydata/scripts/runner.py
index 96333de..1cd8a71 100644
a
|
b
|
def runner(argv, |
87 | 87 | so.stderr = stderr |
88 | 88 | so.stdin = stdin |
89 | 89 | |
90 | | rc = 0 |
91 | 90 | 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) |
95 | 92 | elif command in startstop_node.dispatch: |
96 | 93 | rc = startstop_node.dispatch[command](so, stdout, stderr) |
97 | 94 | elif command in debug.dispatch: |
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): |
22 | 22 | |
23 | 23 | class RunOptions(BasedirMixin, BaseOptions): |
24 | 24 | default_nodedir = u"." |
25 | | allow_multiple = False |
26 | 25 | |
27 | 26 | optParameters = [ |
28 | 27 | ["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]"], |
30 | 28 | ] |
31 | 29 | |
32 | | def do_start(basedir, opts, out=sys.stdout, err=sys.stderr): |
| 30 | def start(opts, out=sys.stdout, err=sys.stderr): |
| 31 | basedir = opts['basedir'] |
33 | 32 | print >>out, "STARTING", quote_output(basedir) |
34 | 33 | if not os.path.isdir(basedir): |
35 | 34 | 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): |
65 | 64 | # we'll never get here. If application setup fails (e.g. ImportError), |
66 | 65 | # run() will raise an exception. |
67 | 66 | |
68 | | def do_stop(basedir, out=sys.stdout, err=sys.stderr): |
| 67 | def stop(config, out=sys.stdout, err=sys.stderr): |
| 68 | basedir = config['basedir'] |
69 | 69 | print >>out, "STOPPING", quote_output(basedir) |
70 | 70 | pidfile = os.path.join(basedir, "twistd.pid") |
71 | 71 | if not os.path.exists(pidfile): |
… |
… |
def do_stop(basedir, out=sys.stdout, err=sys.stderr): |
121 | 121 | # we define rc=1 to mean "I think something is still running, sorry" |
122 | 122 | return 1 |
123 | 123 | |
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 | | |
136 | 124 | def 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) |
140 | 126 | if rc == 2: |
141 | 127 | print >>stderr, "ignoring couldn't-stop" |
142 | 128 | rc = 0 |
143 | 129 | if rc: |
144 | 130 | print >>stderr, "not restarting" |
145 | 131 | 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) |
149 | 133 | |
150 | 134 | def run(config, stdout, stderr): |
151 | 135 | from twisted.internet import reactor |
152 | 136 | from twisted.python import log, logfile |
153 | 137 | from allmydata import client |
154 | 138 | |
155 | | basedir = config['basedirs'][0] |
| 139 | basedir = config['basedir'] |
156 | 140 | precondition(isinstance(basedir, unicode), basedir) |
157 | 141 | |
158 | 142 | if not os.path.isdir(basedir): |
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) |
26 | 26 | """ |
27 | 27 | |
28 | 28 | |
29 | | def create_stats_gatherer(basedir, config, out=sys.stdout, err=sys.stderr): |
| 29 | def create_stats_gatherer(config, out=sys.stdout, err=sys.stderr): |
| 30 | basedir = config['basedir'] |
30 | 31 | # This should always be called with an absolute Unicode basedir. |
31 | 32 | precondition(isinstance(basedir, unicode), basedir) |
32 | 33 | |
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): |
246 | 246 | self.failUnless(os.path.exists(n3)) |
247 | 247 | self.failUnless(os.path.exists(os.path.join(n3, tac))) |
248 | 248 | |
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 |
263 | 250 | argv = [command, "basedir", "extraarg"] |
264 | 251 | self.failUnlessRaises(usage.UsageError, |
265 | 252 | runner.runner, argv, |