]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - src/allmydata/scripts/common.py
change default node-directory on windows to do registry lookup, not ~/.tahoe
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / scripts / common.py
1
2 import os, sys
3 from twisted.python import usage
4
5
6 class BaseOptions:
7     optFlags = [
8         ["quiet", "q", "Operate silently."],
9         ["version", "V", "Display version numbers and exit."],
10         ]
11
12     def opt_version(self):
13         import allmydata
14         print allmydata.get_package_versions_string()
15         sys.exit(0)
16
17
18 class BasedirMixin:
19     optFlags = [
20         ["multiple", "m", "allow multiple basedirs to be specified at once"],
21         ]
22
23     def postOptions(self):
24         if not self.basedirs:
25             raise usage.UsageError("<basedir> parameter is required")
26         if self['basedir']:
27             del self['basedir']
28         self['basedirs'] = [os.path.abspath(os.path.expanduser(b))
29                             for b in self.basedirs]
30
31     def parseArgs(self, *args):
32         self.basedirs = []
33         if self['basedir']:
34             self.basedirs.append(self['basedir'])
35         if self['multiple']:
36             self.basedirs.extend(args)
37         else:
38             if len(args) == 0 and not self.basedirs:
39                 if sys.platform == 'win32':
40                     from allmydata.windows import registry
41                     self.basedirs.append(registry.get_base_dir_path())
42                 else:
43                     self.basedirs.append(os.path.expanduser("~/.tahoe"))
44             if len(args) > 0:
45                 self.basedirs.append(args[0])
46             if len(args) > 1:
47                 raise usage.UsageError("I wasn't expecting so many arguments")
48
49 class NoDefaultBasedirMixin(BasedirMixin):
50     def parseArgs(self, *args):
51         # create-client won't default to --basedir=~/.tahoe
52         self.basedirs = []
53         if self['basedir']:
54             self.basedirs.append(self['basedir'])
55         if self['multiple']:
56             self.basedirs.extend(args)
57         else:
58             if len(args) > 0:
59                 self.basedirs.append(args[0])
60             if len(args) > 1:
61                 raise usage.UsageError("I wasn't expecting so many arguments")
62         if not self.basedirs:
63             raise usage.UsageError("--basedir must be provided")
64
65