2007-07-11 01:41:52 +00:00
|
|
|
|
2007-08-16 19:50:19 +00:00
|
|
|
import os, sys
|
2007-07-11 01:41:52 +00:00
|
|
|
from twisted.python import usage
|
|
|
|
|
|
|
|
|
2007-08-16 19:50:19 +00:00
|
|
|
class BaseOptions:
|
|
|
|
optFlags = [
|
|
|
|
["quiet", "q", "Operate silently."],
|
|
|
|
["version", "V", "Display version numbers and exit."],
|
|
|
|
]
|
|
|
|
|
|
|
|
def opt_version(self):
|
2007-12-13 02:37:37 +00:00
|
|
|
import allmydata
|
|
|
|
print allmydata.get_package_versions_string()
|
2007-08-16 19:50:19 +00:00
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
|
2007-07-11 01:41:52 +00:00
|
|
|
class BasedirMixin:
|
|
|
|
optFlags = [
|
|
|
|
["multiple", "m", "allow multiple basedirs to be specified at once"],
|
|
|
|
]
|
|
|
|
|
|
|
|
def postOptions(self):
|
|
|
|
if not self.basedirs:
|
|
|
|
raise usage.UsageError("<basedir> parameter is required")
|
|
|
|
if self['basedir']:
|
|
|
|
del self['basedir']
|
|
|
|
self['basedirs'] = [os.path.abspath(os.path.expanduser(b))
|
|
|
|
for b in self.basedirs]
|
|
|
|
|
|
|
|
def parseArgs(self, *args):
|
|
|
|
self.basedirs = []
|
|
|
|
if self['basedir']:
|
|
|
|
self.basedirs.append(self['basedir'])
|
|
|
|
if self['multiple']:
|
|
|
|
self.basedirs.extend(args)
|
|
|
|
else:
|
|
|
|
if len(args) == 0 and not self.basedirs:
|
2008-01-11 02:32:18 +00:00
|
|
|
if sys.platform == 'win32':
|
|
|
|
from allmydata.windows import registry
|
|
|
|
self.basedirs.append(registry.get_base_dir_path())
|
|
|
|
else:
|
|
|
|
self.basedirs.append(os.path.expanduser("~/.tahoe"))
|
2007-07-11 01:41:52 +00:00
|
|
|
if len(args) > 0:
|
|
|
|
self.basedirs.append(args[0])
|
|
|
|
if len(args) > 1:
|
|
|
|
raise usage.UsageError("I wasn't expecting so many arguments")
|
|
|
|
|
|
|
|
class NoDefaultBasedirMixin(BasedirMixin):
|
|
|
|
def parseArgs(self, *args):
|
2007-10-11 08:54:23 +00:00
|
|
|
# create-client won't default to --basedir=~/.tahoe
|
2007-07-11 01:41:52 +00:00
|
|
|
self.basedirs = []
|
|
|
|
if self['basedir']:
|
|
|
|
self.basedirs.append(self['basedir'])
|
|
|
|
if self['multiple']:
|
|
|
|
self.basedirs.extend(args)
|
|
|
|
else:
|
|
|
|
if len(args) > 0:
|
|
|
|
self.basedirs.append(args[0])
|
|
|
|
if len(args) > 1:
|
|
|
|
raise usage.UsageError("I wasn't expecting so many arguments")
|
|
|
|
if not self.basedirs:
|
|
|
|
raise usage.UsageError("--basedir must be provided")
|
|
|
|
|
2007-10-12 05:29:23 +00:00
|
|
|
|