CLI: make the --mutable-type option value for 'tahoe put' and 'tahoe mkdir' case-insensitive, and change --help for these commands accordingly. fixes #1527

This commit is contained in:
david-sarah 2011-09-04 19:09:22 -07:00
parent 64996a913d
commit 23f46b758e
3 changed files with 27 additions and 22 deletions

View File

@ -51,14 +51,17 @@ class VDriveOptions(BaseOptions):
class MakeDirectoryOptions(VDriveOptions):
optParameters = [
("mutable-type", None, False, "Create a mutable file in the given format. Valid formats are 'sdmf' for SDMF and 'mdmf' for MDMF"),
("mutable-type", None, None, "Create a mutable directory in the given format. "
"Valid formats are SDMF and MDMF, case-insensitive."),
]
def parseArgs(self, where=""):
self.where = argv_to_unicode(where)
if self['mutable-type'] and self['mutable-type'] not in ("sdmf", "mdmf"):
raise usage.UsageError("%s is an invalid format" % self['mutable-type'])
if self['mutable-type']:
if self['mutable-type'].lower() not in ("sdmf", "mdmf"):
raise usage.UsageError("%s is an invalid format" % self['mutable-type'])
self['mutable-type'] = self['mutable-type'].lower()
def getSynopsis(self):
return "Usage: %s mkdir [options] [REMOTE_DIR]" % (self.command_name,)
@ -172,7 +175,8 @@ class PutOptions(VDriveOptions):
("mutable", "m", "Create a mutable file instead of an immutable one."),
]
optParameters = [
("mutable-type", None, False, "Create a mutable file in the given format. Valid formats are 'sdmf' for SDMF and 'mdmf' for MDMF"),
("mutable-type", None, None, "Create a mutable file in the given format (implies --mutable). "
"Valid formats are SDMF and MDMF, case-insensitive."),
]
def parseArgs(self, arg1=None, arg2=None):
@ -190,13 +194,14 @@ class PutOptions(VDriveOptions):
if self.from_file == u"-":
self.from_file = None
if self['mutable-type'] and self['mutable-type'] not in ("sdmf", "mdmf"):
raise usage.UsageError("%s is an invalid format" % self['mutable-type'])
if self['mutable-type']:
if self['mutable-type'].lower() not in ("sdmf", "mdmf"):
raise usage.UsageError("%s is an invalid format" % self['mutable-type'])
self['mutable-type'] = self['mutable-type'].lower()
if self['mutable-type']:
self['mutable'] = True
def getSynopsis(self):
return "Usage: %s put [options] LOCAL_FILE REMOTE_FILE" % (self.command_name,)

View File

@ -18,10 +18,7 @@ def put(options):
from_file = options.from_file
to_file = options.to_file
mutable = options['mutable']
mutable_type = False
if mutable:
mutable_type = options['mutable-type']
mutable_type = options['mutable-type']
if options['quiet']:
verbosity = 0
else:

View File

@ -1167,17 +1167,20 @@ class Put(GridTestMixin, CLITestMixin, unittest.TestCase):
fn1 = os.path.join(self.basedir, "data")
fileutil.write(fn1, data)
d = self.do_cli("create-alias", "tahoe")
d.addCallback(lambda ignored:
self.do_cli("put", "--mutable", "--mutable-type=mdmf",
fn1, "tahoe:uploaded.txt"))
d.addCallback(lambda ignored:
self.do_cli("ls", "--json", "tahoe:uploaded.txt"))
def _put_and_ls(ign, mutable_type, filename):
d2 = self.do_cli("put", "--mutable", "--mutable-type="+mutable_type,
fn1, filename)
d2.addCallback(lambda ign: self.do_cli("ls", "--json", filename))
return d2
d.addCallback(_put_and_ls, "mdmf", "tahoe:uploaded.txt")
d.addCallback(self._check_mdmf_json)
d.addCallback(lambda ignored:
self.do_cli("put", "--mutable", "--mutable-type=sdmf",
fn1, "tahoe:uploaded2.txt"))
d.addCallback(lambda ignored:
self.do_cli("ls", "--json", "tahoe:uploaded2.txt"))
d.addCallback(_put_and_ls, "MDMF", "tahoe:uploaded2.txt")
d.addCallback(self._check_mdmf_json)
d.addCallback(_put_and_ls, "sdmf", "tahoe:uploaded3.txt")
d.addCallback(self._check_sdmf_json)
d.addCallback(_put_and_ls, "SDMF", "tahoe:uploaded4.txt")
d.addCallback(self._check_sdmf_json)
return d
@ -3319,7 +3322,7 @@ class Mkdir(GridTestMixin, CLITestMixin, unittest.TestCase):
self.do_cli("ls", "--json", self._filecap))
d.addCallback(_check, '"mutable-type": "sdmf"')
d.addCallback(lambda ignored:
self.do_cli("mkdir", "--mutable-type=mdmf", "tahoe:bar"))
self.do_cli("mkdir", "--mutable-type=MDMF", "tahoe:bar"))
d.addCallback(_check, "URI:DIR2-MDMF")
d.addCallback(_stash_dircap)
d.addCallback(lambda ignored: