Ticket #166: fix-args.diff
File fix-args.diff, 42.4 KB (added by warner, at 2012-05-31T21:55:55Z) |
---|
-
src/allmydata/scripts/admin.py
diff --git a/src/allmydata/scripts/admin.py b/src/allmydata/scripts/admin.py index 581224d..1a6c985 100644
a b 1 1 2 2 from twisted.python import usage 3 from allmydata.scripts.common import BaseOptions 3 4 4 class GenerateKeypairOptions( usage.Options):5 class GenerateKeypairOptions(BaseOptions): 5 6 def getSynopsis(self): 6 7 return "Usage: tahoe admin generate-keypair" 7 8 8 9 def getUsage(self, width=None): 9 t = usage.Options.getUsage(self, width)10 t = BaseOptions.getUsage(self, width) 10 11 t += """ 11 12 Generate a public/private keypair, dumped to stdout as two lines of ASCII.. 12 13 … … def print_keypair(options): 20 21 print >>out, "private:", privkey_vs 21 22 print >>out, "public:", pubkey_vs 22 23 23 class DerivePubkeyOptions( usage.Options):24 class DerivePubkeyOptions(BaseOptions): 24 25 def parseArgs(self, privkey): 25 26 self.privkey = privkey 26 27 … … class DerivePubkeyOptions(usage.Options): 28 29 return "Usage: tahoe admin derive-pubkey PRIVKEY" 29 30 30 31 def getUsage(self, width=None): 31 t = usage.Options.getUsage(self, width)32 t = BaseOptions.getUsage(self, width) 32 33 t += """ 33 34 Given a private (signing) key that was previously generated with 34 35 generate-keypair, derive the public key and print it to stdout. … … def derive_pubkey(options): 45 46 print >>out, "public:", pubkey_vs 46 47 return 0 47 48 48 class AdminCommand( usage.Options):49 class AdminCommand(BaseOptions): 49 50 subCommands = [ 50 51 ("generate-keypair", None, GenerateKeypairOptions, 51 52 "Generate a public/private keypair, write to stdout."), … … class AdminCommand(usage.Options): 58 59 def getSynopsis(self): 59 60 return "Usage: tahoe admin SUBCOMMAND" 60 61 def getUsage(self, width=None): 61 t = usage.Options.getUsage(self, width)62 t = BaseOptions.getUsage(self, width) 62 63 t += """ 63 64 Please run e.g. 'tahoe admin generate-keypair --help' for more details on 64 65 each subcommand. -
src/allmydata/scripts/cli.py
diff --git a/src/allmydata/scripts/cli.py b/src/allmydata/scripts/cli.py index bb48ef4..e26b401 100644
a b 1 1 import os.path, re, fnmatch 2 2 from twisted.python import usage 3 from allmydata.scripts.common import BaseOptions, get_aliases, get_default_nodedir, DEFAULT_ALIAS 3 from allmydata.scripts.common import get_aliases, get_default_nodedir, \ 4 DEFAULT_ALIAS, BaseOptions 4 5 from allmydata.util.encodingutil import argv_to_unicode, argv_to_abspath, quote_output 5 6 6 7 NODEURL_RE=re.compile("http(s?)://([^:]*)(:([1-9][0-9]*))?") … … _default_nodedir = get_default_nodedir() 9 10 10 11 class VDriveOptions(BaseOptions): 11 12 optParameters = [ 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 '" + os.path.join('private', 'aliases') + "' which contains the "17 "mapping from alias name to root dirnode URI." + (18 _default_nodedir and (" [default: " + quote_output(_default_nodedir) + "]") or "")],19 13 ["node-url", "u", None, 20 "Specify the URL of the Tahoe gateway node, such as 'http://127.0.0.1:3456'. " 14 "Specify the URL of the Tahoe gateway node, such as " 15 "'http://127.0.0.1:3456'. " 21 16 "This overrides the URL found in the --node-directory ."], 22 17 ["dir-cap", None, None, 23 18 "Specify which dirnode URI should be used as the 'tahoe' alias."] 24 19 ] 25 20 26 21 def postOptions(self): 27 if self['node-directory']: 28 self['node-directory'] = argv_to_abspath(self['node-directory']) 22 self["quiet"] = self.parent["quiet"] 23 if self.parent['node-directory']: 24 self['node-directory'] = argv_to_abspath(self.parent['node-directory']) 29 25 else: 30 26 self['node-directory'] = _default_nodedir 31 27 -
src/allmydata/scripts/common.py
diff --git a/src/allmydata/scripts/common.py b/src/allmydata/scripts/common.py index cd545c3..25de448 100644
a b def get_default_nodedir(): 25 25 26 26 27 27 class BaseOptions(usage.Options): 28 # unit tests can override these to point at StringIO instances29 stdin = sys.stdin30 stdout = sys.stdout31 stderr = sys.stderr32 33 optFlags = [34 ["quiet", "q", "Operate silently."],35 ["version", "V", "Display version numbers."],36 ["version-and-path", None, "Display version numbers and paths to their locations."],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 ]42 43 28 def __init__(self): 44 29 super(BaseOptions, self).__init__() 45 30 self.command_name = os.path.basename(sys.argv[0]) 46 31 if self.command_name == 'trial': 47 32 self.command_name = 'tahoe' 48 33 34 # Only allow "tahoe --version", not e.g. "tahoe start --version" 49 35 def opt_version(self): 50 import allmydata 51 print >>self.stdout, allmydata.get_package_versions_string(debug=True) 52 self.no_command_needed = True 36 raise usage.UsageError("--version not allowed on subcommands") 53 37 54 def opt_version_and_path(self): 55 import allmydata 56 print >>self.stdout, allmydata.get_package_versions_string(show_paths=True, debug=True) 57 self.no_command_needed = True 58 59 60 class BasedirMixin: 38 class BasedirOptions(BaseOptions): 61 39 default_nodedir = _default_nodedir 62 40 63 41 optParameters = [ … … class BasedirMixin: 65 43 ] 66 44 67 45 def parseArgs(self, basedir=None): 68 if self['node-directory'] and self['basedir']: 69 raise usage.UsageError("The --node-directory (or -d) and --basedir (or -C) " 70 "options cannot both be used.") 46 if self.parent['node-directory'] and self['basedir']: 47 raise usage.UsageError("The --node-directory (or -d) and --basedir (or -C) options cannot both be used.") 48 if self.parent['node-directory'] and basedir: 49 raise usage.UsageError("The --node-directory (or -d) option and a basedir argumnent cannot both be used.") 50 if self['basedir'] and basedir: 51 raise usage.UsageError("The --basedir (or -C) option and a basedir argument cannot both be used.") 71 52 72 53 if basedir: 73 54 b = argv_to_abspath(basedir) 74 55 elif self['basedir']: 75 56 b = argv_to_abspath(self['basedir']) 76 elif self ['node-directory']:77 b = argv_to_abspath(self ['node-directory'])78 el se:57 elif self.parent['node-directory']: 58 b = argv_to_abspath(self.parent['node-directory']) 59 elif self.default_nodedir: 79 60 b = self.default_nodedir 61 else: 62 raise usage.UsageError("No default basedir available, you must provide one with --node-directory, --basedir, or a basedir argument") 80 63 self['basedir'] = b 81 64 82 65 def postOptions(self): -
src/allmydata/scripts/create_node.py
diff --git a/src/allmydata/scripts/create_node.py b/src/allmydata/scripts/create_node.py index 7e9dcf7..893bf08 100644
a b 1 1 2 2 import os, sys 3 from allmydata.scripts.common import Basedir Mixin, BaseOptions3 from allmydata.scripts.common import BasedirOptions 4 4 from allmydata.util.assertutil import precondition 5 5 from allmydata.util.encodingutil import listdir_unicode, argv_to_unicode, quote_output 6 6 import allmydata 7 7 8 class CreateClientOptions(Basedir Mixin, BaseOptions):8 class CreateClientOptions(BasedirOptions): 9 9 optParameters = [ 10 10 # we provide 'create-node'-time options for the most common 11 11 # configuration knobs. The rest can be controlled by editing … … class CreateNodeOptions(CreateClientOptions): 29 29 return "Usage: %s create-node [options] [NODEDIR]" % (self.command_name,) 30 30 31 31 32 class CreateIntroducerOptions(Basedir Mixin, BaseOptions):32 class CreateIntroducerOptions(BasedirOptions): 33 33 default_nodedir = None 34 34 35 optParameters = [36 ["node-directory", "d", None, "Specify which directory the introducer should be created in. [no default]"],37 ]38 39 35 def getSynopsis(self): 40 36 return "Usage: %s create-introducer [options] NODEDIR" % (self.command_name,) 41 37 -
src/allmydata/scripts/debug.py
diff --git a/src/allmydata/scripts/debug.py b/src/allmydata/scripts/debug.py index f7749cd..cb8e986 100644
a b from twisted.python import usage, failure 6 6 from twisted.internet import defer 7 7 from twisted.scripts import trial as twisted_trial 8 8 from foolscap.logging import cli as foolscap_cli 9 from allmydata.scripts.common import BaseOptions 9 10 10 11 11 class DumpOptions( usage.Options):12 class DumpOptions(BaseOptions): 12 13 def getSynopsis(self): 13 14 return "Usage: tahoe debug dump-share SHARE_FILENAME" 14 15 … … class DumpOptions(usage.Options): 18 19 ] 19 20 20 21 def getUsage(self, width=None): 21 t = usage.Options.getUsage(self, width)22 t = BaseOptions.getUsage(self, width) 22 23 t += """ 23 24 Print lots of information about the given share, by parsing the share's 24 25 contents. This includes share type, lease information, encoding parameters, … … def dump_MDMF_share(m, length, options): 405 406 406 407 407 408 408 class DumpCapOptions( usage.Options):409 class DumpCapOptions(BaseOptions): 409 410 def getSynopsis(self): 410 411 return "Usage: tahoe debug dump-cap [options] FILECAP" 411 412 optParameters = [ … … class DumpCapOptions(usage.Options): 420 421 self.cap = cap 421 422 422 423 def getUsage(self, width=None): 423 t = usage.Options.getUsage(self, width)424 t = BaseOptions.getUsage(self, width) 424 425 t += """ 425 426 Print information about the given cap-string (aka: URI, file-cap, dir-cap, 426 427 read-cap, write-cap). The URI string is parsed and unpacked. This prints the … … def dump_uri_instance(u, nodeid, secret, out, show_header=True): 607 608 else: 608 609 print >>out, "unknown cap type" 609 610 610 class FindSharesOptions( usage.Options):611 class FindSharesOptions(BaseOptions): 611 612 def getSynopsis(self): 612 613 return "Usage: tahoe debug find-shares STORAGE_INDEX NODEDIRS.." 613 614 … … class FindSharesOptions(usage.Options): 617 618 self.nodedirs = map(argv_to_abspath, nodedirs) 618 619 619 620 def getUsage(self, width=None): 620 t = usage.Options.getUsage(self, width)621 t = BaseOptions.getUsage(self, width) 621 622 t += """ 622 623 Locate all shares for the given storage index. This command looks through one 623 624 or more node directories to find the shares. It returns a list of filenames, … … def find_shares(options): 657 658 return 0 658 659 659 660 660 class CatalogSharesOptions( usage.Options):661 class CatalogSharesOptions(BaseOptions): 661 662 """ 662 663 663 664 """ … … class CatalogSharesOptions(usage.Options): 671 672 return "Usage: tahoe debug catalog-shares NODEDIRS.." 672 673 673 674 def getUsage(self, width=None): 674 t = usage.Options.getUsage(self, width)675 t = BaseOptions.getUsage(self, width) 675 676 t += """ 676 677 Locate all shares in the given node directories, and emit a one-line summary 677 678 of each share. Run it like this: … … def catalog_shares_one_abbrevdir(si_s, si_dir, now, out, err): 879 880 print >>err, "Error processing %s" % quote_output(si_dir) 880 881 failure.Failure().printTraceback(err) 881 882 882 class CorruptShareOptions( usage.Options):883 class CorruptShareOptions(BaseOptions): 883 884 def getSynopsis(self): 884 885 return "Usage: tahoe debug corrupt-share SHARE_FILENAME" 885 886 … … class CorruptShareOptions(usage.Options): 888 889 ] 889 890 890 891 def getUsage(self, width=None): 891 t = usage.Options.getUsage(self, width)892 t = BaseOptions.getUsage(self, width) 892 893 t += """ 893 894 Corrupt the given share by flipping a bit. This will cause a 894 895 verifying/downloading client to log an integrity-check failure incident, and … … def corrupt_share(options): 959 960 960 961 961 962 962 class ReplOptions( usage.Options):963 class ReplOptions(BaseOptions): 963 964 def getSynopsis(self): 964 965 return "Usage: tahoe debug repl" 965 966 … … def flogtool(config): 1042 1043 return foolscap_cli.run_flogtool() 1043 1044 1044 1045 1045 class DebugCommand( usage.Options):1046 class DebugCommand(BaseOptions): 1046 1047 subCommands = [ 1047 1048 ["dump-share", None, DumpOptions, 1048 1049 "Unpack and display the contents of a share (uri_extension and leases)."], … … class DebugCommand(usage.Options): 1060 1061 def getSynopsis(self): 1061 1062 return "" 1062 1063 def getUsage(self, width=None): 1063 #t = usage.Options.getUsage(self, width)1064 #t = BaseOptions.getUsage(self, width) 1064 1065 t = """Usage: tahoe debug SUBCOMMAND 1065 1066 Subcommands: 1066 1067 tahoe debug dump-share Unpack and display the contents of a share. -
src/allmydata/scripts/keygen.py
diff --git a/src/allmydata/scripts/keygen.py b/src/allmydata/scripts/keygen.py index 1f5c30f..5b1c9ab 100644
a b 1 1 2 2 import os, sys 3 from allmydata.scripts.common import Basedir Mixin, BaseOptions3 from allmydata.scripts.common import BasedirOptions 4 4 from allmydata.util.assertutil import precondition 5 5 from allmydata.util.encodingutil import listdir_unicode, quote_output 6 6 7 class CreateKeyGeneratorOptions(Basedir Mixin, BaseOptions):7 class CreateKeyGeneratorOptions(BasedirOptions): 8 8 default_nodedir = None 9 9 10 optParameters = [11 ["node-directory", "d", None, "Specify which directory the key-generator should be created in. [no default]"],12 ]13 14 10 def getSynopsis(self): 15 11 return "Usage: %s create-key-generator [options] NODEDIR" % (self.command_name,) 16 12 -
src/allmydata/scripts/runner.py
diff --git a/src/allmydata/scripts/runner.py b/src/allmydata/scripts/runner.py index e66f8d3..e4eb67e 100644
a b 1 1 2 import sys2 import os, sys 3 3 from cStringIO import StringIO 4 4 5 5 from twisted.python import usage 6 6 7 from allmydata.scripts.common import BaseOptions7 from allmydata.scripts.common import get_default_nodedir 8 8 from allmydata.scripts import debug, create_node, startstop_node, cli, keygen, stats_gatherer, admin 9 9 from allmydata.util.encodingutil import quote_output, get_io_encoding 10 10 … … def GROUP(s): 15 15 return [("\n" + s, None, None, None)] 16 16 17 17 18 class Options(BaseOptions, usage.Options): 18 _default_nodedir = get_default_nodedir() 19 20 NODEDIR_HELP = ("Specify which Tahoe node directory should be used. The " 21 "directory should either contain a full Tahoe node, or a " 22 "file named node.url that points to some other Tahoe node. " 23 "It should also contain a file named '" 24 + os.path.join('private', 'aliases') + 25 "' which contains the mapping from alias name to root " 26 "dirnode URI.") 27 if _default_nodedir: 28 NODEDIR_HELP += " [default for most commands: " + quote_output(_default_nodedir) + "]" 29 30 class Options(usage.Options): 31 # unit tests can override these to point at StringIO instances 32 stdin = sys.stdin 33 stdout = sys.stdout 34 stderr = sys.stderr 35 19 36 synopsis = "\nUsage: tahoe <command> [command options]" 20 37 subCommands = ( GROUP("Administration") 21 38 + create_node.subCommands … … class Options(BaseOptions, usage.Options): 30 47 + cli.subCommands 31 48 ) 32 49 50 optFlags = [ 51 ["quiet", "q", "Operate silently."], 52 ["version", "V", "Display version numbers."], 53 ["version-and-path", None, "Display version numbers and paths to their locations."], 54 ] 55 optParameters = [ 56 ["node-directory", "d", None, NODEDIR_HELP], 57 ] 58 59 def opt_version(self): 60 import allmydata 61 print >>self.stdout, allmydata.get_package_versions_string(debug=True) 62 self.no_command_needed = True 63 64 def opt_version_and_path(self): 65 import allmydata 66 print >>self.stdout, allmydata.get_package_versions_string(show_paths=True, debug=True) 67 self.no_command_needed = True 68 69 def getSynopsis(self): 70 return "\nUsage: tahoe [global-options] <command> [command-options]" 71 33 72 def getUsage(self, **kwargs): 34 73 t = usage.Options.getUsage(self, **kwargs) 35 74 return t + "\nPlease run 'tahoe <command> --help' for more details on each command.\n" -
src/allmydata/scripts/startstop_node.py
diff --git a/src/allmydata/scripts/startstop_node.py b/src/allmydata/scripts/startstop_node.py index 5045bd6..36138e0 100644
a b 1 1 2 2 import os, sys, signal, time 3 from allmydata.scripts.common import Basedir Mixin, BaseOptions3 from allmydata.scripts.common import BasedirOptions 4 4 from allmydata.util import fileutil 5 5 from allmydata.util.assertutil import precondition 6 6 from allmydata.util.encodingutil import listdir_unicode, quote_output 7 7 8 8 9 class StartOptions(Basedir Mixin, BaseOptions):9 class StartOptions(BasedirOptions): 10 10 optFlags = [ 11 11 ["profile", "p", "Run under the Python profiler, putting results in 'profiling_results.prof'."], 12 12 ["syslog", None, "Tell the node to log to syslog, not a file."], … … class StartOptions(BasedirMixin, BaseOptions): 16 16 return "Usage: %s start [options] [NODEDIR]" % (self.command_name,) 17 17 18 18 19 class StopOptions(Basedir Mixin, BaseOptions):19 class StopOptions(BasedirOptions): 20 20 def getSynopsis(self): 21 21 return "Usage: %s stop [options] [NODEDIR]" % (self.command_name,) 22 22 23 23 24 class RestartOptions(Basedir Mixin, BaseOptions):24 class RestartOptions(BasedirOptions): 25 25 optFlags = [ 26 26 ["profile", "p", "Run under the Python profiler, putting results in 'profiling_results.prof'."], 27 27 ["syslog", None, "Tell the node to log to syslog, not a file."], … … class RestartOptions(BasedirMixin, BaseOptions): 31 31 return "Usage: %s restart [options] [NODEDIR]" % (self.command_name,) 32 32 33 33 34 class RunOptions(Basedir Mixin, BaseOptions):34 class RunOptions(BasedirOptions): 35 35 default_nodedir = u"." 36 36 37 optParameters = [38 ["node-directory", "d", None, "Specify the directory of the node to be run. [default, for 'tahoe run' only: current directory]"],39 ]40 41 37 def getSynopsis(self): 42 38 return "Usage: %s run [options] [NODEDIR]" % (self.command_name,) 43 39 -
src/allmydata/scripts/stats_gatherer.py
diff --git a/src/allmydata/scripts/stats_gatherer.py b/src/allmydata/scripts/stats_gatherer.py index 230d4a9..bdb3576 100644
a b 1 1 2 2 import os, sys 3 from allmydata.scripts.common import Basedir Mixin, BaseOptions3 from allmydata.scripts.common import BasedirOptions 4 4 from allmydata.util.assertutil import precondition 5 5 from allmydata.util.encodingutil import listdir_unicode, quote_output 6 6 7 class CreateStatsGathererOptions(Basedir Mixin, BaseOptions):7 class CreateStatsGathererOptions(BasedirOptions): 8 8 default_nodedir = None 9 9 10 optParameters = [11 ["node-directory", "d", None, "Specify which directory the stats-gatherer should be created in. [no default]"],12 ]13 14 10 def getSynopsis(self): 15 11 return "Usage: %s create-stats-gatherer [options] NODEDIR" % (self.command_name,) 16 12 -
src/allmydata/test/test_cli.py
diff --git a/src/allmydata/test/test_cli.py b/src/allmydata/test/test_cli.py index c88d00b..d0906a2 100644
a b from allmydata.util.fileutil import abspath_expanduser_unicode 42 42 43 43 timeout = 480 # deep_check takes 360s on Zandr's linksys box, others take > 240s 44 44 45 def parse_options(basedir, command, args): 46 o = runner.Options() 47 o.parseOptions(["--node-directory", basedir, command] + args) 48 while hasattr(o, "subOptions"): 49 o = o.subOptions 50 return o 45 51 46 52 class CLITestMixin(ReallyEqualMixin): 47 53 def do_cli(self, verb, *args, **kwargs): 48 54 nodeargs = [ 49 55 "--node-directory", self.get_clientdir(), 50 56 ] 51 argv = [verb] + nodeargs+ list(args)57 argv = nodeargs + [verb] + list(args) 52 58 stdin = kwargs.get("stdin", "") 53 59 stdout, stderr = StringIO(), StringIO() 54 60 d = threads.deferToThread(runner.runner, argv, run_by_human=False, … … class CLITestMixin(ReallyEqualMixin): 71 77 72 78 73 79 class CLI(CLITestMixin, unittest.TestCase): 74 # this test case only looks at argument-processing and simple stuff.75 def test_options(self):76 fileutil.rm_dir("cli/test_options")77 fileutil.make_dirs("cli/test_options")78 fileutil.make_dirs("cli/test_options/private")79 fileutil.write("cli/test_options/node.url", "http://localhost:8080/\n")80 filenode_uri = uri.WriteableSSKFileURI(writekey="\x00"*16,81 fingerprint="\x00"*32)82 private_uri = uri.DirectoryURI(filenode_uri).to_string()83 fileutil.write("cli/test_options/private/root_dir.cap", private_uri + "\n")84 o = cli.ListOptions()85 o.parseOptions(["--node-directory", "cli/test_options"])86 self.failUnlessReallyEqual(o['node-url'], "http://localhost:8080/")87 self.failUnlessReallyEqual(o.aliases[DEFAULT_ALIAS], private_uri)88 self.failUnlessReallyEqual(o.where, u"")89 90 o = cli.ListOptions()91 o.parseOptions(["--node-directory", "cli/test_options",92 "--node-url", "http://example.org:8111/"])93 self.failUnlessReallyEqual(o['node-url'], "http://example.org:8111/")94 self.failUnlessReallyEqual(o.aliases[DEFAULT_ALIAS], private_uri)95 self.failUnlessReallyEqual(o.where, u"")96 97 o = cli.ListOptions()98 o.parseOptions(["--node-directory", "cli/test_options",99 "--dir-cap", "root"])100 self.failUnlessReallyEqual(o['node-url'], "http://localhost:8080/")101 self.failUnlessReallyEqual(o.aliases[DEFAULT_ALIAS], "root")102 self.failUnlessReallyEqual(o.where, u"")103 104 o = cli.ListOptions()105 other_filenode_uri = uri.WriteableSSKFileURI(writekey="\x11"*16,106 fingerprint="\x11"*32)107 other_uri = uri.DirectoryURI(other_filenode_uri).to_string()108 o.parseOptions(["--node-directory", "cli/test_options",109 "--dir-cap", other_uri])110 self.failUnlessReallyEqual(o['node-url'], "http://localhost:8080/")111 self.failUnlessReallyEqual(o.aliases[DEFAULT_ALIAS], other_uri)112 self.failUnlessReallyEqual(o.where, u"")113 114 o = cli.ListOptions()115 o.parseOptions(["--node-directory", "cli/test_options",116 "--dir-cap", other_uri, "subdir"])117 self.failUnlessReallyEqual(o['node-url'], "http://localhost:8080/")118 self.failUnlessReallyEqual(o.aliases[DEFAULT_ALIAS], other_uri)119 self.failUnlessReallyEqual(o.where, u"subdir")120 121 o = cli.ListOptions()122 self.failUnlessRaises(usage.UsageError,123 o.parseOptions,124 ["--node-directory", "cli/test_options",125 "--node-url", "NOT-A-URL"])126 127 o = cli.ListOptions()128 o.parseOptions(["--node-directory", "cli/test_options",129 "--node-url", "http://localhost:8080"])130 self.failUnlessReallyEqual(o["node-url"], "http://localhost:8080/")131 132 o = cli.ListOptions()133 o.parseOptions(["--node-directory", "cli/test_options",134 "--node-url", "https://localhost/"])135 self.failUnlessReallyEqual(o["node-url"], "https://localhost/")136 137 80 def _dump_cap(self, *args): 138 81 config = debug.DumpCapOptions() 139 82 config.stdout,config.stderr = StringIO(), StringIO() … … class Help(unittest.TestCase): 703 646 class CreateAlias(GridTestMixin, CLITestMixin, unittest.TestCase): 704 647 705 648 def _test_webopen(self, args, expected_url): 706 woo = cli.WebopenOptions()707 all_args = ["--node-directory", self.get_clientdir()] + list(args)708 woo.parseOptions(all_args)649 o = runner.Options() 650 o.parseOptions(["--node-directory", self.get_clientdir(), "webopen"] 651 + list(args)) 709 652 urls = [] 710 rc = cli.webopen( woo, urls.append)653 rc = cli.webopen(o, urls.append) 711 654 self.failUnlessReallyEqual(rc, 0) 712 655 self.failUnlessReallyEqual(len(urls), 1) 713 656 self.failUnlessReallyEqual(urls[0], expected_url) … … class Backup(GridTestMixin, CLITestMixin, StallMixin, unittest.TestCase): 2674 2617 fileutil.make_dirs(basedir) 2675 2618 nodeurl_path = os.path.join(basedir, 'node.url') 2676 2619 fileutil.write(nodeurl_path, 'http://example.net:2357/') 2620 def parse(args): return parse_options(basedir, "backup", args) 2677 2621 2678 2622 # test simple exclude 2679 backup_options = cli.BackupOptions() 2680 backup_options.parseOptions(['--exclude', '*lyx', '--node-directory', 2681 basedir, 'from', 'to']) 2623 backup_options = parse(['--exclude', '*lyx', 'from', 'to']) 2682 2624 filtered = list(backup_options.filter_listdir(root_listdir)) 2683 2625 self._check_filtering(filtered, root_listdir, (u'lib.a', u'_darcs', u'subdir'), 2684 2626 (u'nice_doc.lyx',)) 2685 2627 # multiple exclude 2686 backup_options = cli.BackupOptions() 2687 backup_options.parseOptions(['--exclude', '*lyx', '--exclude', 'lib.?', '--node-directory', 2688 basedir, 'from', 'to']) 2628 backup_options = parse(['--exclude', '*lyx', '--exclude', 'lib.?', 'from', 'to']) 2689 2629 filtered = list(backup_options.filter_listdir(root_listdir)) 2690 2630 self._check_filtering(filtered, root_listdir, (u'_darcs', u'subdir'), 2691 2631 (u'nice_doc.lyx', u'lib.a')) 2692 2632 # vcs metadata exclusion 2693 backup_options = cli.BackupOptions() 2694 backup_options.parseOptions(['--exclude-vcs', '--node-directory', 2695 basedir, 'from', 'to']) 2633 backup_options = parse(['--exclude-vcs', 'from', 'to']) 2696 2634 filtered = list(backup_options.filter_listdir(subdir_listdir)) 2697 2635 self._check_filtering(filtered, subdir_listdir, (u'another_doc.lyx', u'run_snake_run.py',), 2698 2636 (u'CVS', u'.svn', u'_darcs')) … … class Backup(GridTestMixin, CLITestMixin, StallMixin, unittest.TestCase): 2700 2638 exclusion_string = "_darcs\n*py\n.svn" 2701 2639 excl_filepath = os.path.join(basedir, 'exclusion') 2702 2640 fileutil.write(excl_filepath, exclusion_string) 2703 backup_options = cli.BackupOptions() 2704 backup_options.parseOptions(['--exclude-from', excl_filepath, '--node-directory', 2705 basedir, 'from', 'to']) 2641 backup_options = parse(['--exclude-from', excl_filepath, 'from', 'to']) 2706 2642 filtered = list(backup_options.filter_listdir(subdir_listdir)) 2707 2643 self._check_filtering(filtered, subdir_listdir, (u'another_doc.lyx', u'CVS'), 2708 2644 (u'.svn', u'_darcs', u'run_snake_run.py')) 2709 2645 # test BackupConfigurationError 2710 2646 self.failUnlessRaises(cli.BackupConfigurationError, 2711 backup_options.parseOptions, 2712 ['--exclude-from', excl_filepath + '.no', '--node-directory', 2713 basedir, 'from', 'to']) 2647 parse, 2648 ['--exclude-from', excl_filepath + '.no', 'from', 'to']) 2714 2649 2715 2650 # test that an iterator works too 2716 backup_options = cli.BackupOptions() 2717 backup_options.parseOptions(['--exclude', '*lyx', '--node-directory', 2718 basedir, 'from', 'to']) 2651 backup_options = parse(['--exclude', '*lyx', 'from', 'to']) 2719 2652 filtered = list(backup_options.filter_listdir(iter(root_listdir))) 2720 2653 self._check_filtering(filtered, root_listdir, (u'lib.a', u'_darcs', u'subdir'), 2721 2654 (u'nice_doc.lyx',)) … … class Backup(GridTestMixin, CLITestMixin, StallMixin, unittest.TestCase): 2732 2665 fileutil.make_dirs(basedir) 2733 2666 nodeurl_path = os.path.join(basedir, 'node.url') 2734 2667 fileutil.write(nodeurl_path, 'http://example.net:2357/') 2668 def parse(args): return parse_options(basedir, "backup", args) 2735 2669 2736 2670 # test simple exclude 2737 backup_options = cli.BackupOptions() 2738 backup_options.parseOptions(['--exclude', doc_pattern_arg, '--node-directory', 2739 basedir, 'from', 'to']) 2671 backup_options = parse(['--exclude', doc_pattern_arg, 'from', 'to']) 2740 2672 filtered = list(backup_options.filter_listdir(root_listdir)) 2741 2673 self._check_filtering(filtered, root_listdir, (u'lib.a', u'_darcs', u'subdir'), 2742 2674 (nice_doc,)) 2743 2675 # multiple exclude 2744 backup_options = cli.BackupOptions() 2745 backup_options.parseOptions(['--exclude', doc_pattern_arg, '--exclude', 'lib.?', '--node-directory', 2746 basedir, 'from', 'to']) 2676 backup_options = parse(['--exclude', doc_pattern_arg, '--exclude', 'lib.?', 'from', 'to']) 2747 2677 filtered = list(backup_options.filter_listdir(root_listdir)) 2748 2678 self._check_filtering(filtered, root_listdir, (u'_darcs', u'subdir'), 2749 2679 (nice_doc, u'lib.a')) … … class Backup(GridTestMixin, CLITestMixin, StallMixin, unittest.TestCase): 2751 2681 exclusion_string = doc_pattern_arg + "\nlib.?" 2752 2682 excl_filepath = os.path.join(basedir, 'exclusion') 2753 2683 fileutil.write(excl_filepath, exclusion_string) 2754 backup_options = cli.BackupOptions() 2755 backup_options.parseOptions(['--exclude-from', excl_filepath, '--node-directory', 2756 basedir, 'from', 'to']) 2684 backup_options = parse(['--exclude-from', excl_filepath, 'from', 'to']) 2757 2685 filtered = list(backup_options.filter_listdir(root_listdir)) 2758 2686 self._check_filtering(filtered, root_listdir, (u'_darcs', u'subdir'), 2759 2687 (nice_doc, u'lib.a')) 2760 2688 2761 2689 # test that an iterator works too 2762 backup_options = cli.BackupOptions() 2763 backup_options.parseOptions(['--exclude', doc_pattern_arg, '--node-directory', 2764 basedir, 'from', 'to']) 2690 backup_options = parse(['--exclude', doc_pattern_arg, 'from', 'to']) 2765 2691 filtered = list(backup_options.filter_listdir(iter(root_listdir))) 2766 2692 self._check_filtering(filtered, root_listdir, (u'lib.a', u'_darcs', u'subdir'), 2767 2693 (nice_doc,)) … … class Backup(GridTestMixin, CLITestMixin, StallMixin, unittest.TestCase): 2772 2698 fileutil.make_dirs(basedir) 2773 2699 nodeurl_path = os.path.join(basedir, 'node.url') 2774 2700 fileutil.write(nodeurl_path, 'http://example.net:2357/') 2701 def parse(args): return parse_options(basedir, "backup", args) 2775 2702 2776 2703 # ensure that tilde expansion is performed on exclude-from argument 2777 2704 exclude_file = u'~/.tahoe/excludes.dummy' 2778 backup_options = cli.BackupOptions()2779 2705 2780 2706 mock.return_value = StringIO() 2781 backup_options.parseOptions(['--exclude-from', unicode_to_argv(exclude_file), 2782 '--node-directory', basedir, 'from', 'to']) 2707 parse(['--exclude-from', unicode_to_argv(exclude_file), 'from', 'to']) 2783 2708 self.failUnlessIn(((abspath_expanduser_unicode(exclude_file),), {}), mock.call_args_list) 2784 2709 2785 2710 def test_ignore_symlinks(self): … … class Webopen(GridTestMixin, CLITestMixin, unittest.TestCase): 3628 3553 _cleanup(None) 3629 3554 raise 3630 3555 return d 3556 3557 class Options(unittest.TestCase): 3558 # this test case only looks at argument-processing and simple stuff. 3559 3560 def parse(self, args, stdout=None): 3561 o = runner.Options() 3562 if stdout is not None: 3563 o.stdout = stdout 3564 o.parseOptions(args) 3565 while hasattr(o, "subOptions"): 3566 o = o.subOptions 3567 return o 3568 3569 def test_list(self): 3570 fileutil.rm_dir("cli/test_options") 3571 fileutil.make_dirs("cli/test_options") 3572 fileutil.make_dirs("cli/test_options/private") 3573 fileutil.write("cli/test_options/node.url", "http://localhost:8080/\n") 3574 filenode_uri = uri.WriteableSSKFileURI(writekey="\x00"*16, 3575 fingerprint="\x00"*32) 3576 private_uri = uri.DirectoryURI(filenode_uri).to_string() 3577 fileutil.write("cli/test_options/private/root_dir.cap", private_uri + "\n") 3578 def parse2(args): return parse_options("cli/test_options", "ls", args) 3579 o = parse2([]) 3580 self.failUnlessEqual(o['node-url'], "http://localhost:8080/") 3581 self.failUnlessEqual(o.aliases[DEFAULT_ALIAS], private_uri) 3582 self.failUnlessEqual(o.where, u"") 3583 3584 o = parse2(["--node-url", "http://example.org:8111/"]) 3585 self.failUnlessEqual(o['node-url'], "http://example.org:8111/") 3586 self.failUnlessEqual(o.aliases[DEFAULT_ALIAS], private_uri) 3587 self.failUnlessEqual(o.where, u"") 3588 3589 o = parse2(["--dir-cap", "root"]) 3590 self.failUnlessEqual(o['node-url'], "http://localhost:8080/") 3591 self.failUnlessEqual(o.aliases[DEFAULT_ALIAS], "root") 3592 self.failUnlessEqual(o.where, u"") 3593 3594 other_filenode_uri = uri.WriteableSSKFileURI(writekey="\x11"*16, 3595 fingerprint="\x11"*32) 3596 other_uri = uri.DirectoryURI(other_filenode_uri).to_string() 3597 o = parse2(["--dir-cap", other_uri]) 3598 self.failUnlessEqual(o['node-url'], "http://localhost:8080/") 3599 self.failUnlessEqual(o.aliases[DEFAULT_ALIAS], other_uri) 3600 self.failUnlessEqual(o.where, u"") 3601 3602 o = parse2(["--dir-cap", other_uri, "subdir"]) 3603 self.failUnlessEqual(o['node-url'], "http://localhost:8080/") 3604 self.failUnlessEqual(o.aliases[DEFAULT_ALIAS], other_uri) 3605 self.failUnlessEqual(o.where, u"subdir") 3606 3607 self.failUnlessRaises(usage.UsageError, parse2, 3608 ["--node-url", "NOT-A-URL"]) 3609 3610 o = parse2(["--node-url", "http://localhost:8080"]) 3611 self.failUnlessEqual(o["node-url"], "http://localhost:8080/") 3612 3613 o = parse2(["--node-url", "https://localhost/"]) 3614 self.failUnlessEqual(o["node-url"], "https://localhost/") 3615 3616 def test_version(self): 3617 # "tahoe --version" dumps text to stdout and exits 3618 stdout = StringIO() 3619 self.failUnlessRaises(SystemExit, self.parse, ["--version"], stdout) 3620 self.failUnlessIn("allmydata-tahoe", stdout.getvalue()) 3621 # but "tahoe SUBCOMMAND --version" should be rejected 3622 self.failUnlessRaises(usage.UsageError, self.parse, 3623 ["start", "--version"]) 3624 self.failUnlessRaises(usage.UsageError, self.parse, 3625 ["start", "--version-and-path"]) 3626 3627 def test_quiet(self): 3628 # accepted as an overall option, but not on subcommands 3629 o = self.parse(["--quiet", "start"]) 3630 self.failUnless(o.parent["quiet"]) 3631 self.failUnlessRaises(usage.UsageError, self.parse, 3632 ["start", "--quiet"]) 3633 3634 def test_basedir(self): 3635 # accept a --node-directory option before the verb, or a --basedir 3636 # option after, or a basedir argument after, but none in the wrong 3637 # place, and not more than one of the three. 3638 o = self.parse(["start"]) 3639 self.failUnlessEqual(o["basedir"], os.path.expanduser("~/.tahoe")) 3640 o = self.parse(["start", "here"]) 3641 self.failUnlessEqual(o["basedir"], os.path.abspath("here")) 3642 o = self.parse(["start", "--basedir", "there"]) 3643 self.failUnlessEqual(o["basedir"], os.path.abspath("there")) 3644 o = self.parse(["--node-directory", "there", "start"]) 3645 self.failUnlessEqual(o["basedir"], os.path.abspath("there")) 3646 3647 self.failUnlessRaises(usage.UsageError, self.parse, 3648 ["--basedir", "there", "start"]) 3649 self.failUnlessRaises(usage.UsageError, self.parse, 3650 ["start", "--node-directory", "there"]) 3651 3652 self.failUnlessRaises(usage.UsageError, self.parse, 3653 ["--node-directory=there", 3654 "start", "--basedir=here"]) 3655 self.failUnlessRaises(usage.UsageError, self.parse, 3656 ["start", "--basedir=here", "anywhere"]) 3657 self.failUnlessRaises(usage.UsageError, self.parse, 3658 ["--node-directory=there", 3659 "start", "anywhere"]) 3660 self.failUnlessRaises(usage.UsageError, self.parse, 3661 ["--node-directory=there", 3662 "start", "--basedir=here", "anywhere"]) 3663 -
src/allmydata/test/test_deepcheck.py
diff --git a/src/allmydata/test/test_deepcheck.py b/src/allmydata/test/test_deepcheck.py index 669a6d5..f29a688 100644
a b class DeepCheckWebGood(DeepCheckBase, unittest.TestCase): 761 761 762 762 def do_cli_manifest_stream1(self): 763 763 basedir = self.get_clientdir(0) 764 d = self._run_cli([" manifest",765 " --node-directory", basedir,764 d = self._run_cli(["--node-directory", basedir, 765 "manifest", 766 766 self.root_uri]) 767 767 def _check((out,err)): 768 768 self.failUnlessEqual(err, "") … … class DeepCheckWebGood(DeepCheckBase, unittest.TestCase): 789 789 790 790 def do_cli_manifest_stream2(self): 791 791 basedir = self.get_clientdir(0) 792 d = self._run_cli([" manifest",793 " --node-directory", basedir,792 d = self._run_cli(["--node-directory", basedir, 793 "manifest", 794 794 "--raw", 795 795 self.root_uri]) 796 796 def _check((out,err)): … … class DeepCheckWebGood(DeepCheckBase, unittest.TestCase): 802 802 803 803 def do_cli_manifest_stream3(self): 804 804 basedir = self.get_clientdir(0) 805 d = self._run_cli([" manifest",806 " --node-directory", basedir,805 d = self._run_cli(["--node-directory", basedir, 806 "manifest", 807 807 "--storage-index", 808 808 self.root_uri]) 809 809 def _check((out,err)): … … class DeepCheckWebGood(DeepCheckBase, unittest.TestCase): 814 814 815 815 def do_cli_manifest_stream4(self): 816 816 basedir = self.get_clientdir(0) 817 d = self._run_cli([" manifest",818 " --node-directory", basedir,817 d = self._run_cli(["--node-directory", basedir, 818 "manifest", 819 819 "--verify-cap", 820 820 self.root_uri]) 821 821 def _check((out,err)): … … class DeepCheckWebGood(DeepCheckBase, unittest.TestCase): 830 830 831 831 def do_cli_manifest_stream5(self): 832 832 basedir = self.get_clientdir(0) 833 d = self._run_cli([" manifest",834 " --node-directory", basedir,833 d = self._run_cli(["--node-directory", basedir, 834 "manifest", 835 835 "--repair-cap", 836 836 self.root_uri]) 837 837 def _check((out,err)): … … class DeepCheckWebGood(DeepCheckBase, unittest.TestCase): 846 846 847 847 def do_cli_stats1(self): 848 848 basedir = self.get_clientdir(0) 849 d = self._run_cli([" stats",850 " --node-directory", basedir,849 d = self._run_cli(["--node-directory", basedir, 850 "stats", 851 851 self.root_uri]) 852 852 def _check3((out,err)): 853 853 lines = [l.strip() for l in out.split("\n") if l] … … class DeepCheckWebGood(DeepCheckBase, unittest.TestCase): 866 866 867 867 def do_cli_stats2(self): 868 868 basedir = self.get_clientdir(0) 869 d = self._run_cli([" stats",870 " --node-directory", basedir,869 d = self._run_cli(["--node-directory", basedir, 870 "stats", 871 871 "--raw", 872 872 self.root_uri]) 873 873 def _check4((out,err)): -
src/allmydata/test/test_runner.py
diff --git a/src/allmydata/test/test_runner.py b/src/allmydata/test/test_runner.py index 4e9f683..96894e8 100644
a b class CreateNode(unittest.TestCase): 282 282 283 283 # test the --node-directory form 284 284 n3 = os.path.join(basedir, command + "-n3") 285 argv = ["--quiet", command, "--node-directory", n3]285 argv = ["--quiet", "--node-directory", n3, command] 286 286 rc, out, err = self.run_tahoe(argv) 287 287 self.failUnlessEqual(err, "") 288 288 self.failUnlessEqual(out, "") -
src/allmydata/test/test_system.py
diff --git a/src/allmydata/test/test_system.py b/src/allmydata/test/test_system.py index f3b72f5..5c19e16 100644
a b class SystemTest(SystemTestMixin, RunBinTahoeMixin, unittest.TestCase): 1431 1431 1432 1432 def run(ignored, verb, *args, **kwargs): 1433 1433 stdin = kwargs.get("stdin", "") 1434 newargs = [verb] + nodeargs+ list(args)1434 newargs = nodeargs + [verb] + list(args) 1435 1435 return self._run_cli(newargs, stdin=stdin) 1436 1436 1437 1437 def _check_ls((out,err), expected_children, unexpected_children=[]): … … class SystemTest(SystemTestMixin, RunBinTahoeMixin, unittest.TestCase): 1736 1736 # tahoe_ls doesn't currently handle the error correctly: it tries to 1737 1737 # JSON-parse a traceback. 1738 1738 ## def _ls_missing(res): 1739 ## argv = ["ls"] + nodeargs + ["bogus"]1739 ## argv = nodeargs + ["ls", "bogus"] 1740 1740 ## return self._run_cli(argv) 1741 1741 ## d.addCallback(_ls_missing) 1742 1742 ## def _check_ls_missing((out,err)): … … class SystemTest(SystemTestMixin, RunBinTahoeMixin, unittest.TestCase): 1760 1760 def _run_in_subprocess(ignored, verb, *args, **kwargs): 1761 1761 stdin = kwargs.get("stdin") 1762 1762 env = kwargs.get("env") 1763 newargs = [ verb, "--node-directory", self.getdir("client0")] + list(args)1763 newargs = ["--node-directory", self.getdir("client0"), verb] + list(args) 1764 1764 return self.run_bintahoe(newargs, stdin=stdin, env=env) 1765 1765 1766 1766 def _check_succeeded(res, check_stderr=True):