Changeset f952532 in trunk
- Timestamp:
- 2010-08-02T04:30:04Z (15 years ago)
- Branches:
- master
- Children:
- 54a9ba8
- Parents:
- 16647b4
- Location:
- src/allmydata
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/allmydata/scripts/cli.py ¶
r16647b4 rf952532 1 1 import os.path, re, sys, fnmatch 2 2 from twisted.python import usage 3 from allmydata.scripts.common import BaseOptions, get_aliases 4 from allmydata.util.encodingutil import argv_to_unicode, argv_to_abspath 3 from allmydata.scripts.common import BaseOptions, get_aliases, get_default_nodedir, DEFAULT_ALIAS 4 from allmydata.util.encodingutil import argv_to_unicode, argv_to_abspath, quote_output 5 5 6 6 NODEURL_RE=re.compile("http(s?)://([^:]*)(:([1-9][0-9]*))?") 7 7 8 class VDriveOptions(BaseOptions, usage.Options): 8 _default_nodedir = get_default_nodedir() 9 10 class VDriveOptions(BaseOptions): 9 11 optParameters = [ 10 ["node-directory", "d", "~/.tahoe",11 " Look here to find out which Tahoe node should be used for all"12 " operations. The directory should either contain a full Tahoe node,"13 " or a file named node.url which points to some other Tahoe node."14 " It should also contain a file named private/aliases which contains"15 "t he mapping from alias name to root dirnode URI."16 ],12 ["node-directory", "d", None, 13 "Specify which Tahoe node directory should be used. The directory " 14 "should either contain a full Tahoe node, or a file named node.url " 15 "that points to some other Tahoe node. It should also contain a file " 16 "named private/aliases which contains the mapping from alias name " 17 "to root dirnode URI." + ( 18 _default_nodedir and (" [default for most commands: " + quote_output(_default_nodedir) + "]") or "")], 17 19 ["node-url", "u", None, 18 20 "URL of the tahoe node to use, a URL like \"http://127.0.0.1:3456\". " … … 23 25 24 26 def postOptions(self): 27 if self['node-directory']: 28 self['node-directory'] = argv_to_abspath(self['node-directory']) 29 else: 30 self['node-directory'] = _default_nodedir 31 25 32 # compute a node-url from the existing options, put in self['node-url'] 26 if self['node-directory']:27 if sys.platform == 'win32' and self['node-directory'] == '~/.tahoe':28 from allmydata.windows import registry29 self['node-directory'] = registry.get_base_dir_path()30 else:31 self['node-directory'] = argv_to_abspath(self['node-directory'])32 33 if self['node-url']: 33 34 if (not isinstance(self['node-url'], basestring) … … 45 46 aliases = get_aliases(self['node-directory']) 46 47 if self['dir-cap']: 47 aliases[ "tahoe"] = self['dir-cap']48 aliases[DEFAULT_ALIAS] = self['dir-cap'] 48 49 self.aliases = aliases # maps alias name to dircap 49 50 -
TabularUnified src/allmydata/scripts/common.py ¶
r16647b4 rf952532 7 7 from allmydata.util.fileutil import abspath_expanduser_unicode 8 8 9 class BaseOptions: 9 10 _default_nodedir = None 11 if sys.platform == 'win32': 12 from allmydata.windows import registry 13 path = registry.get_base_dir_path() 14 if path: 15 precondition(isinstance(path, unicode), path) 16 _default_nodedir = abspath_expanduser_unicode(path) 17 18 if _default_nodedir is None: 19 path = abspath_expanduser_unicode(u"~/.tahoe") 20 precondition(isinstance(path, unicode), path) 21 _default_nodedir = path 22 23 def get_default_nodedir(): 24 return _default_nodedir 25 26 27 class BaseOptions(usage.Options): 10 28 # unit tests can override these to point at StringIO instances 11 29 stdin = sys.stdin … … 17 35 ["version", "V", "Display version numbers and exit."], 18 36 ["version-and-path", None, "Display version numbers and paths to their locations and exit."], 19 ] 37 ] 38 optParameters = [ 39 ["node-directory", "d", None, "Specify which Tahoe node directory should be used." + ( 40 _default_nodedir and (" [default for most commands: " + quote_output(_default_nodedir) + "]") or "")], 41 ] 20 42 21 43 def opt_version(self): … … 31 53 32 54 class BasedirMixin: 55 default_nodedir = _default_nodedir 56 allow_multiple = True 57 58 optParameters = [ 59 ["basedir", "C", None, "Same as --node-directory."], 60 ] 33 61 optFlags = [ 34 ["multiple", "m", "allow multiple basedirs to be specified at once"], 35 ] 36 37 def postOptions(self): 38 if not self.basedirs: 39 raise usage.UsageError("<basedir> parameter is required") 40 if self['basedir']: 41 del self['basedir'] 42 self['basedirs'] = self.basedirs 62 ["multiple", "m", "Specify multiple node directories at once"], 63 ] 43 64 44 65 def parseArgs(self, *args): 45 self.basedirs = []46 if self['basedir']:47 precondition(isinstance(self['basedir'], str), self['basedir'])48 self.basedirs.append(argv_to_abspath(self['basedir'])) 49 if self[' multiple']:50 self.basedirs .extend(map(argv_to_abspath, args))66 if self['node-directory'] and self['basedir']: 67 raise usage.UsageError("The --node-directory (or -d) and --basedir (or -C) " 68 "options cannot both be used.") 69 70 if self['node-directory'] or self['basedir']: 71 self.basedirs = [argv_to_abspath(self['node-directory'] or self['basedir'])] 51 72 else: 52 if len(args) == 0 and not self.basedirs: 53 if sys.platform == 'win32': 54 from allmydata.windows import registry 55 rbdp = registry.get_base_dir_path() 56 if rbdp: 57 precondition(isinstance(registry.get_base_dir_path(), unicode), registry.get_base_dir_path()) 58 self.basedirs.append(rbdp) 59 else: 60 self.basedirs.append(abspath_expanduser_unicode(u"~/.tahoe")) 61 if len(args) > 0: 62 self.basedirs.append(argv_to_abspath(args[0])) 63 if len(args) > 1: 64 raise usage.UsageError("I wasn't expecting so many arguments") 65 66 class NoDefaultBasedirMixin(BasedirMixin): 67 def parseArgs(self, *args): 68 # create-client won't default to --basedir=~/.tahoe 69 self.basedirs = [] 70 if self['basedir']: 71 self.basedirs.append(argv_to_abspath(self['basedir'])) 72 if self['multiple']: 73 self.basedirs = [] 74 75 if self.allow_multiple and self['multiple']: 73 76 self.basedirs.extend(map(argv_to_abspath, args)) 74 77 else: … … 76 79 self.basedirs.append(argv_to_abspath(args[0])) 77 80 if len(args) > 1: 78 raise usage.UsageError("I wasn't expecting so many arguments") 81 raise usage.UsageError("I wasn't expecting so many arguments." + 82 (self.allow_multiple and 83 " Use the --multiple option to specify more than one node directory." or "")) 84 85 if len(args) == 0 and self.default_nodedir and not self.basedirs: 86 self.basedirs.append(self.default_nodedir) 87 elif len(args) > 0: 88 self.basedirs.append(argv_to_abspath(args[0])) 89 90 def postOptions(self): 79 91 if not self.basedirs: 80 raise usage.UsageError("--basedir must be provided") 92 raise usage.UsageError("A base directory for the node must be provided.") 93 del self['basedir'] 94 self['basedirs'] = self.basedirs 95 81 96 82 97 DEFAULT_ALIAS = u"tahoe" … … 92 107 rootcap = f.read().strip() 93 108 if rootcap: 94 aliases[ u"tahoe"] = uri.from_string_dirnode(rootcap).to_string()109 aliases[DEFAULT_ALIAS] = uri.from_string_dirnode(rootcap).to_string() 95 110 except EnvironmentError: 96 111 pass -
TabularUnified src/allmydata/scripts/create_node.py ¶
r16647b4 rf952532 1 1 2 2 import os, sys 3 from twisted.python import usage 4 from allmydata.scripts.common import BasedirMixin, NoDefaultBasedirMixin 3 from allmydata.scripts.common import BasedirMixin, BaseOptions 5 4 from allmydata.util.assertutil import precondition 6 5 from allmydata.util.encodingutil import listdir_unicode, argv_to_unicode, quote_output 7 6 import allmydata 8 7 9 class CreateClientOptions(BasedirMixin, usage.Options):8 class CreateClientOptions(BasedirMixin, BaseOptions): 10 9 optParameters = [ 11 10 ("basedir", "C", None, "which directory to create the node in"), … … 24 23 ] 25 24 26 class CreateIntroducerOptions(NoDefaultBasedirMixin, usage.Options): 25 class CreateIntroducerOptions(BasedirMixin, BaseOptions): 26 default_nodedir = None 27 27 28 optParameters = [ 28 29 ["basedir", "C", None, "which directory to create the introducer in"], -
TabularUnified src/allmydata/scripts/keygen.py ¶
r16647b4 rf952532 1 1 2 2 import os, sys 3 from twisted.python import usage 4 #from allmydata.scripts.common import BasedirMixin, NoDefaultBasedirMixin 5 from allmydata.util.encodingutil import listdir_unicode, argv_to_abspath, quote_output 3 from allmydata.scripts.common import BasedirMixin, BaseOptions 4 from allmydata.util.encodingutil import listdir_unicode, quote_output 6 5 7 class CreateKeyGeneratorOptions(usage.Options): 6 class CreateKeyGeneratorOptions(BasedirMixin, BaseOptions): 7 default_nodedir = None 8 allow_multiple = False 9 8 10 optParameters = [ 9 11 ["basedir", "C", None, "which directory to create the key-generator in"], 10 12 ] 11 13 12 14 keygen_tac = """ … … 26 28 27 29 def create_key_generator(config, out=sys.stdout, err=sys.stderr): 28 if not config['basedir']: 29 print >>err, "a basedir was not provided, please use --basedir or -C" 30 return -1 31 basedir = argv_to_abspath(config['basedir']) 30 basedir = config['basedirs'][0] 32 31 if os.path.exists(basedir): 33 32 if listdir_unicode(basedir): -
TabularUnified src/allmydata/scripts/startstop_node.py ¶
r16647b4 rf952532 1 1 2 2 import os, sys, signal, time 3 from twisted.python import usage 4 from allmydata.scripts.common import BasedirMixin 3 from allmydata.scripts.common import BasedirMixin, BaseOptions 5 4 from allmydata.util import fileutil, find_exe 6 5 7 class StartOptions(BasedirMixin, usage.Options):6 class StartOptions(BasedirMixin, BaseOptions): 8 7 optParameters = [ 9 8 ["basedir", "C", None, "which directory to start the node in"], … … 14 13 ] 15 14 16 class StopOptions(BasedirMixin, usage.Options):15 class StopOptions(BasedirMixin, BaseOptions): 17 16 optParameters = [ 18 17 ["basedir", "C", None, "which directory to stop the node in"], 19 18 ] 20 19 21 class RestartOptions(BasedirMixin, usage.Options):20 class RestartOptions(BasedirMixin, BaseOptions): 22 21 optParameters = [ 23 22 ["basedir", "C", None, "which directory to restart the node in"], … … 28 27 ] 29 28 30 class RunOptions(usage.Options): 29 class RunOptions(BasedirMixin, BaseOptions): 30 default_nodedir = u"." 31 31 32 optParameters = [ 32 33 ["basedir", "C", None, "which directory to run the node in, CWD by default"], -
TabularUnified src/allmydata/test/test_runner.py ¶
r16647b4 rf952532 203 203 # make sure it rejects a missing basedir specification 204 204 argv = ["create-key-generator"] 205 rc, out, err = self.run_tahoe(argv) 206 self.failIfEqual(rc, 0, str((out, err, rc))) 207 self.failUnlessEqual(out, "") 208 self.failUnless("a basedir was not provided" in err) 205 self.failUnlessRaises(usage.UsageError, 206 runner.runner, argv, 207 run_by_human=False) 209 208 210 209 def test_stats_gatherer(self):
Note: See TracChangeset
for help on using the changeset viewer.