1 | --- old-tahoe/src/allmydata/scripts/common.py 2010-01-12 04:29:38.233000000 +0000 |
---|
2 | +++ new-tahoe/src/allmydata/scripts/common.py 2010-01-12 04:29:38.299000000 +0000 |
---|
3 | @@ -1,6 +1,21 @@ |
---|
4 | |
---|
5 | import os, sys, urllib |
---|
6 | from twisted.python import usage |
---|
7 | +from allmydata.util.assertutil import precondition |
---|
8 | + |
---|
9 | + |
---|
10 | +_default_basedir = 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, (str, unicode)), path) |
---|
16 | + _default_basedir = os.path.abspath(path) |
---|
17 | + |
---|
18 | +if _default_basedir is None: |
---|
19 | + path = os.path.expanduser("~/.tahoe") |
---|
20 | + precondition(isinstance(path, (str, unicode)), path) |
---|
21 | + _default_basedir = os.path.abspath(path) |
---|
22 | |
---|
23 | |
---|
24 | class BaseOptions: |
---|
25 | @@ -15,6 +30,11 @@ |
---|
26 | ["version-and-path", None, "Display version numbers and paths to their locations and exit."], |
---|
27 | ] |
---|
28 | |
---|
29 | + optParameters = [ |
---|
30 | + ["basedir", "C", None, "Specify the base directory of the node to be used." + ( |
---|
31 | + "" if _default_basedir is None else " [default for most commands: " + _default_basedir + "]")], |
---|
32 | + ] |
---|
33 | + |
---|
34 | def opt_version(self): |
---|
35 | import allmydata |
---|
36 | print allmydata.get_package_versions_string() |
---|
37 | @@ -27,19 +47,20 @@ |
---|
38 | |
---|
39 | |
---|
40 | class BasedirMixin: |
---|
41 | + use_default_basedir = True |
---|
42 | + |
---|
43 | optFlags = [ |
---|
44 | - ["multiple", "m", "allow multiple basedirs to be specified at once"], |
---|
45 | + ["multiple", "m", "Specify multiple base directories at once."], |
---|
46 | ] |
---|
47 | |
---|
48 | def postOptions(self): |
---|
49 | if not self.basedirs: |
---|
50 | - raise usage.UsageError("<basedir> parameter is required") |
---|
51 | + raise usage.UsageError("A base directory must be provided using --basedir or --multiple.") |
---|
52 | if self['basedir']: |
---|
53 | del self['basedir'] |
---|
54 | self['basedirs'] = [os.path.abspath(os.path.expanduser(b)) for b in self.basedirs] |
---|
55 | |
---|
56 | def parseArgs(self, *args): |
---|
57 | - from allmydata.util.assertutil import precondition |
---|
58 | self.basedirs = [] |
---|
59 | if self['basedir']: |
---|
60 | precondition(isinstance(self['basedir'], (str, unicode)), self['basedir']) |
---|
61 | @@ -48,41 +69,18 @@ |
---|
62 | precondition(not [x for x in args if not isinstance(x, (str, unicode))], args) |
---|
63 | self.basedirs.extend(args) |
---|
64 | else: |
---|
65 | - if len(args) == 0 and not self.basedirs: |
---|
66 | - if sys.platform == 'win32': |
---|
67 | - from allmydata.windows import registry |
---|
68 | - rbdp = registry.get_base_dir_path() |
---|
69 | - if rbdp: |
---|
70 | - precondition(isinstance(registry.get_base_dir_path(), (str, unicode)), registry.get_base_dir_path()) |
---|
71 | - self.basedirs.append(rbdp) |
---|
72 | - else: |
---|
73 | - precondition(isinstance(os.path.expanduser("~/.tahoe"), (str, unicode)), os.path.expanduser("~/.tahoe")) |
---|
74 | - self.basedirs.append(os.path.expanduser("~/.tahoe")) |
---|
75 | + if self.use_default_basedir and len(args) == 0 and not self.basedirs: |
---|
76 | + self.basedirs.append(_default_basedir) |
---|
77 | if len(args) > 0: |
---|
78 | precondition(isinstance(args[0], (str, unicode)), args[0]) |
---|
79 | self.basedirs.append(args[0]) |
---|
80 | if len(args) > 1: |
---|
81 | raise usage.UsageError("I wasn't expecting so many arguments") |
---|
82 | |
---|
83 | + |
---|
84 | class NoDefaultBasedirMixin(BasedirMixin): |
---|
85 | - def parseArgs(self, *args): |
---|
86 | - from allmydata.util.assertutil import precondition |
---|
87 | - # create-client won't default to --basedir=~/.tahoe |
---|
88 | - self.basedirs = [] |
---|
89 | - if self['basedir']: |
---|
90 | - precondition(isinstance(self['basedir'], (str, unicode)), self['basedir']) |
---|
91 | - self.basedirs.append(self['basedir']) |
---|
92 | - if self['multiple']: |
---|
93 | - precondition(not [x for x in args if not isinstance(x, (str, unicode))], args) |
---|
94 | - self.basedirs.extend(args) |
---|
95 | - else: |
---|
96 | - if len(args) > 0: |
---|
97 | - precondition(isinstance(args[0], (str, unicode)), args[0]) |
---|
98 | - self.basedirs.append(args[0]) |
---|
99 | - if len(args) > 1: |
---|
100 | - raise usage.UsageError("I wasn't expecting so many arguments") |
---|
101 | - if not self.basedirs: |
---|
102 | - raise usage.UsageError("--basedir must be provided") |
---|
103 | + use_default_basedir = False |
---|
104 | + |
---|
105 | |
---|
106 | DEFAULT_ALIAS = "tahoe" |
---|
107 | |
---|
108 | @@ -96,7 +94,7 @@ |
---|
109 | f = open(rootfile, "r") |
---|
110 | rootcap = f.read().strip() |
---|
111 | if rootcap: |
---|
112 | - aliases["tahoe"] = uri.from_string_dirnode(rootcap).to_string() |
---|
113 | + aliases[DEFAULT_ALIAS] = uri.from_string_dirnode(rootcap).to_string() |
---|
114 | except EnvironmentError: |
---|
115 | pass |
---|
116 | try: |
---|