1 patch for repository davidsarah@tahoe-lafs.org:/home/source/darcs/tahoe-lafs/ticket798: Mon Aug 2 05:30:04 GMT Daylight Time 2010 david-sarah@jacaranda.org * Basedir/node directory option improvements for ticket798 branch. addresses #188, #706, #715, #772, #890 New patches: [Basedir/node directory option improvements for ticket798 branch. addresses #188, #706, #715, #772, #890 david-sarah@jacaranda.org**20100802043004 Ignore-this: d19fc24349afa19833406518595bfdf7 ] { hunk ./src/allmydata/scripts/cli.py 3 import os.path, re, sys, fnmatch from twisted.python import usage -from allmydata.scripts.common import BaseOptions, get_aliases -from allmydata.util.encodingutil import argv_to_unicode, argv_to_abspath +from allmydata.scripts.common import BaseOptions, get_aliases, get_default_nodedir, DEFAULT_ALIAS +from allmydata.util.encodingutil import argv_to_unicode, argv_to_abspath, quote_output NODEURL_RE=re.compile("http(s?)://([^:]*)(:([1-9][0-9]*))?") hunk ./src/allmydata/scripts/cli.py 8 -class VDriveOptions(BaseOptions, usage.Options): +_default_nodedir = get_default_nodedir() + +class VDriveOptions(BaseOptions): optParameters = [ hunk ./src/allmydata/scripts/cli.py 12 - ["node-directory", "d", "~/.tahoe", - "Look here to find out which Tahoe node should be used for all " - "operations. The directory should either contain a full Tahoe node, " - "or a file named node.url which points to some other Tahoe node. " - "It should also contain a file named private/aliases which contains " - "the mapping from alias name to root dirnode URI." - ], + ["node-directory", "d", None, + "Specify which Tahoe node directory should be used. The directory " + "should either contain a full Tahoe node, or a file named node.url " + "that points to some other Tahoe node. It should also contain a file " + "named private/aliases which contains the mapping from alias name " + "to root dirnode URI." + ( + _default_nodedir and (" [default for most commands: " + quote_output(_default_nodedir) + "]") or "")], ["node-url", "u", None, "URL of the tahoe node to use, a URL like \"http://127.0.0.1:3456\". " "This overrides the URL found in the --node-directory ."], hunk ./src/allmydata/scripts/cli.py 27 ] def postOptions(self): - # compute a node-url from the existing options, put in self['node-url'] if self['node-directory']: hunk ./src/allmydata/scripts/cli.py 28 - if sys.platform == 'win32' and self['node-directory'] == '~/.tahoe': - from allmydata.windows import registry - self['node-directory'] = registry.get_base_dir_path() - else: - self['node-directory'] = argv_to_abspath(self['node-directory']) + self['node-directory'] = argv_to_abspath(self['node-directory']) + else: + self['node-directory'] = _default_nodedir + + # compute a node-url from the existing options, put in self['node-url'] if self['node-url']: if (not isinstance(self['node-url'], basestring) or not NODEURL_RE.match(self['node-url'])): hunk ./src/allmydata/scripts/cli.py 48 aliases = get_aliases(self['node-directory']) if self['dir-cap']: - aliases["tahoe"] = self['dir-cap'] + aliases[DEFAULT_ALIAS] = self['dir-cap'] self.aliases = aliases # maps alias name to dircap hunk ./src/allmydata/scripts/common.py 9 from allmydata.util.encodingutil import unicode_to_url, quote_output, argv_to_abspath from allmydata.util.fileutil import abspath_expanduser_unicode -class BaseOptions: + +_default_nodedir = None +if sys.platform == 'win32': + from allmydata.windows import registry + path = registry.get_base_dir_path() + if path: + precondition(isinstance(path, unicode), path) + _default_nodedir = abspath_expanduser_unicode(path) + +if _default_nodedir is None: + path = abspath_expanduser_unicode(u"~/.tahoe") + precondition(isinstance(path, unicode), path) + _default_nodedir = path + +def get_default_nodedir(): + return _default_nodedir + + +class BaseOptions(usage.Options): # unit tests can override these to point at StringIO instances stdin = sys.stdin stdout = sys.stdout hunk ./src/allmydata/scripts/common.py 37 ["quiet", "q", "Operate silently."], ["version", "V", "Display version numbers and exit."], ["version-and-path", None, "Display version numbers and paths to their locations and exit."], - ] + ] + optParameters = [ + ["node-directory", "d", None, "Specify which Tahoe node directory should be used." + ( + _default_nodedir and (" [default for most commands: " + quote_output(_default_nodedir) + "]") or "")], + ] def opt_version(self): import allmydata hunk ./src/allmydata/scripts/common.py 55 class BasedirMixin: - optFlags = [ - ["multiple", "m", "allow multiple basedirs to be specified at once"], - ] + default_nodedir = _default_nodedir + allow_multiple = True hunk ./src/allmydata/scripts/common.py 58 - def postOptions(self): - if not self.basedirs: - raise usage.UsageError(" parameter is required") - if self['basedir']: - del self['basedir'] - self['basedirs'] = self.basedirs + optParameters = [ + ["basedir", "C", None, "Same as --node-directory."], + ] + optFlags = [ + ["multiple", "m", "Specify multiple node directories at once"], + ] def parseArgs(self, *args): hunk ./src/allmydata/scripts/common.py 66 - self.basedirs = [] - if self['basedir']: - precondition(isinstance(self['basedir'], str), self['basedir']) - self.basedirs.append(argv_to_abspath(self['basedir'])) - if self['multiple']: - self.basedirs.extend(map(argv_to_abspath, args)) + if self['node-directory'] and self['basedir']: + raise usage.UsageError("The --node-directory (or -d) and --basedir (or -C) " + "options cannot both be used.") + + if self['node-directory'] or self['basedir']: + self.basedirs = [argv_to_abspath(self['node-directory'] or self['basedir'])] else: hunk ./src/allmydata/scripts/common.py 73 - if len(args) == 0 and not self.basedirs: - if sys.platform == 'win32': - from allmydata.windows import registry - rbdp = registry.get_base_dir_path() - if rbdp: - precondition(isinstance(registry.get_base_dir_path(), unicode), registry.get_base_dir_path()) - self.basedirs.append(rbdp) - else: - self.basedirs.append(abspath_expanduser_unicode(u"~/.tahoe")) - if len(args) > 0: - self.basedirs.append(argv_to_abspath(args[0])) - if len(args) > 1: - raise usage.UsageError("I wasn't expecting so many arguments") + self.basedirs = [] hunk ./src/allmydata/scripts/common.py 75 -class NoDefaultBasedirMixin(BasedirMixin): - def parseArgs(self, *args): - # create-client won't default to --basedir=~/.tahoe - self.basedirs = [] - if self['basedir']: - self.basedirs.append(argv_to_abspath(self['basedir'])) - if self['multiple']: + if self.allow_multiple and self['multiple']: self.basedirs.extend(map(argv_to_abspath, args)) else: if len(args) > 0: hunk ./src/allmydata/scripts/common.py 81 self.basedirs.append(argv_to_abspath(args[0])) if len(args) > 1: - raise usage.UsageError("I wasn't expecting so many arguments") + raise usage.UsageError("I wasn't expecting so many arguments." + + (self.allow_multiple and + " Use the --multiple option to specify more than one node directory." or "")) + + if len(args) == 0 and self.default_nodedir and not self.basedirs: + self.basedirs.append(self.default_nodedir) + elif len(args) > 0: + self.basedirs.append(argv_to_abspath(args[0])) + + def postOptions(self): if not self.basedirs: hunk ./src/allmydata/scripts/common.py 92 - raise usage.UsageError("--basedir must be provided") + raise usage.UsageError("A base directory for the node must be provided.") + del self['basedir'] + self['basedirs'] = self.basedirs + DEFAULT_ALIAS = u"tahoe" hunk ./src/allmydata/scripts/common.py 109 f = open(rootfile, "r") rootcap = f.read().strip() if rootcap: - aliases[u"tahoe"] = uri.from_string_dirnode(rootcap).to_string() + aliases[DEFAULT_ALIAS] = uri.from_string_dirnode(rootcap).to_string() except EnvironmentError: pass try: hunk ./src/allmydata/scripts/create_node.py 3 import os, sys -from twisted.python import usage -from allmydata.scripts.common import BasedirMixin, NoDefaultBasedirMixin +from allmydata.scripts.common import BasedirMixin, BaseOptions from allmydata.util.assertutil import precondition from allmydata.util.encodingutil import listdir_unicode, argv_to_unicode, quote_output import allmydata hunk ./src/allmydata/scripts/create_node.py 8 -class CreateClientOptions(BasedirMixin, usage.Options): +class CreateClientOptions(BasedirMixin, BaseOptions): optParameters = [ ("basedir", "C", None, "which directory to create the node in"), # we provide 'create-node'-time options for the most common hunk ./src/allmydata/scripts/create_node.py 25 ("no-storage", None, "do not offer storage service to other nodes"), ] -class CreateIntroducerOptions(NoDefaultBasedirMixin, usage.Options): +class CreateIntroducerOptions(BasedirMixin, BaseOptions): + default_nodedir = None + optParameters = [ ["basedir", "C", None, "which directory to create the introducer in"], ] hunk ./src/allmydata/scripts/keygen.py 3 import os, sys -from twisted.python import usage -#from allmydata.scripts.common import BasedirMixin, NoDefaultBasedirMixin -from allmydata.util.encodingutil import listdir_unicode, argv_to_abspath, quote_output +from allmydata.scripts.common import BasedirMixin, BaseOptions +from allmydata.util.encodingutil import listdir_unicode, quote_output + +class CreateKeyGeneratorOptions(BasedirMixin, BaseOptions): + default_nodedir = None + allow_multiple = False hunk ./src/allmydata/scripts/keygen.py 10 -class CreateKeyGeneratorOptions(usage.Options): optParameters = [ ["basedir", "C", None, "which directory to create the key-generator in"], hunk ./src/allmydata/scripts/keygen.py 12 - ] + ] keygen_tac = """ # -*- python -*- hunk ./src/allmydata/scripts/keygen.py 30 """ def create_key_generator(config, out=sys.stdout, err=sys.stderr): - if not config['basedir']: - print >>err, "a basedir was not provided, please use --basedir or -C" - return -1 - basedir = argv_to_abspath(config['basedir']) + basedir = config['basedirs'][0] if os.path.exists(basedir): if listdir_unicode(basedir): print >>err, "The base directory %s is not empty." % quote_output(basedir) hunk ./src/allmydata/scripts/startstop_node.py 3 import os, sys, signal, time -from twisted.python import usage -from allmydata.scripts.common import BasedirMixin +from allmydata.scripts.common import BasedirMixin, BaseOptions from allmydata.util import fileutil, find_exe hunk ./src/allmydata/scripts/startstop_node.py 6 -class StartOptions(BasedirMixin, usage.Options): +class StartOptions(BasedirMixin, BaseOptions): optParameters = [ ["basedir", "C", None, "which directory to start the node in"], ] hunk ./src/allmydata/scripts/startstop_node.py 15 ["syslog", None, "tell the node to log to syslog, not a file"], ] -class StopOptions(BasedirMixin, usage.Options): +class StopOptions(BasedirMixin, BaseOptions): optParameters = [ ["basedir", "C", None, "which directory to stop the node in"], ] hunk ./src/allmydata/scripts/startstop_node.py 20 -class RestartOptions(BasedirMixin, usage.Options): +class RestartOptions(BasedirMixin, BaseOptions): optParameters = [ ["basedir", "C", None, "which directory to restart the node in"], ] hunk ./src/allmydata/scripts/startstop_node.py 29 ["syslog", None, "tell the node to log to syslog, not a file"], ] -class RunOptions(usage.Options): +class RunOptions(BasedirMixin, BaseOptions): + default_nodedir = u"." + optParameters = [ ["basedir", "C", None, "which directory to run the node in, CWD by default"], ] hunk ./src/allmydata/test/test_runner.py 205 # make sure it rejects a missing basedir specification argv = ["create-key-generator"] - rc, out, err = self.run_tahoe(argv) - self.failIfEqual(rc, 0, str((out, err, rc))) - self.failUnlessEqual(out, "") - self.failUnless("a basedir was not provided" in err) + self.failUnlessRaises(usage.UsageError, + runner.runner, argv, + run_by_human=False) def test_stats_gatherer(self): basedir = self.workdir("test_stats_gatherer") } Context: [Makefile: change tahoe_lafs* globs to *tahoe* (in order to also catch allmydata-tahoe). Change 'clean' to no longer delete bundled egg directories for setuptools, setuptools-trial and darcver. david-sarah@jacaranda.org**20100802033536 Ignore-this: d2cb81aaf9da4151fc0a3f89efa1de73 ] [Makefile: fix 'clean' target to remove tahoe_lafs*.egg_info, and 'upload-tarballs' to upload tahoe_lafs* (instead of allmydata_tahoe*). Change 'upload-tarballs' to upload even for branches, and add 'upload-tarballs-trunkonly' that does what the name says. david-sarah@jacaranda.org**20100802031829 Ignore-this: d5765c6f51234b374fe32b3699e4fa1f ] [test_util.py: Python < 2.6 portability fix -- use .replace("1", "") instead of .translate(None, "1") david-sarah@jacaranda.org**20100802023210 Ignore-this: 2aa7e85362df25d3189c91633be9fdc2 ] [.darcs-boringfile: Tahoe egg-info directories are no longer called allmydata-tahoe.egg-info. david-sarah@jacaranda.org**20100802015019 Ignore-this: a48fc3388290700ad24e37c963c3f683 ] [test_runner.py: Fix error in message arguments to 'fail' calls. david-sarah@jacaranda.org**20100802013526 Ignore-this: 3bfdef19ae3cf993194811367da5d020 ] [Additional Unicode basedir changes for ticket798 branch. david-sarah@jacaranda.org**20100802010552 Ignore-this: 7090d8c6b04eb6275345a55e75142028 ] [Unicode basedir changes for ticket798 branch. david-sarah@jacaranda.org**20100801235310 Ignore-this: a00717eaeae8650847b5395801e04c45 ] [New files added by New Downloader. david-sarah@jacaranda.org**20100801234004 Ignore-this: f44a1622f92d3c5b8a7603f0295c3f63 ] [fileutil: change WindowsError to OSError in abspath_expanduser_unicode, because WindowsError might not exist. david-sarah@jacaranda.org**20100725222603 Ignore-this: e125d503670ed049a9ade0322faa0c51 ] [test_system: correct a failure in _test_runner caused by Unicode basedir patch on non-Unicode platforms. david-sarah@jacaranda.org**20100724032123 Ignore-this: 399b3953104fdd1bbed3f7564d163553 ] [Brian's New Downloader, for testing in 1.8beta. (rebased for ticket798 branch) david-sarah@jacaranda.org**20100801175522 Ignore-this: c4a9455865e13908e7c1bba4d5142c75 ] [Fix test failures due to Unicode basedir patches. david-sarah@jacaranda.org**20100725010318 Ignore-this: fe92cd439eb3e60a56c007ae452784ed ] [util.encodingutil: change quote_output to do less unnecessary escaping, and to use double-quotes more consistently when needed. This version avoids u-escaping for characters that are representable in the output encoding, when double quotes are used, and includes tests. fixes #1135 david-sarah@jacaranda.org**20100723075314 Ignore-this: b82205834d17db61612dd16436b7c5a2 ] [Replace uses of os.path.abspath with abspath_expanduser_unicode where necessary. This makes basedir paths consistently represented as Unicode. david-sarah@jacaranda.org**20100722001418 Ignore-this: 9f8cb706540e695550e0dbe303c01f52 ] [util.fileutil, test.test_util: add abspath_expanduser_unicode function, to work around . util.encodingutil: add a convenience function argv_to_abspath. david-sarah@jacaranda.org**20100721231507 Ignore-this: eee6904d1f65a733ff35190879844d08 ] [TAG tahoe-lafs-ticket798-1.7.1 zooko@zooko.com**20100801165549 Ignore-this: ab7966b17c0f091b4f532cc0cf518068 ] Patch bundle hash: 632304e342f5f910dc976a44eb8d2d23f5136b82