From: david-sarah Date: Mon, 5 Sep 2011 02:09:22 +0000 (-0700) Subject: CLI: make the --mutable-type option value for 'tahoe put' and 'tahoe mkdir' case... X-Git-Tag: allmydata-tahoe-1.9.0a2~60 X-Git-Url: https://git.rkrishnan.org/pf/content/en/seg/rgr-080307.php?a=commitdiff_plain;h=23f46b758ecb3942d13262e7c1738d223699b5dd;p=tahoe-lafs%2Ftahoe-lafs.git CLI: make the --mutable-type option value for 'tahoe put' and 'tahoe mkdir' case-insensitive, and change --help for these commands accordingly. fixes #1527 --- diff --git a/src/allmydata/scripts/cli.py b/src/allmydata/scripts/cli.py index b041b581..970c8c40 100644 --- a/src/allmydata/scripts/cli.py +++ b/src/allmydata/scripts/cli.py @@ -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,) diff --git a/src/allmydata/scripts/tahoe_put.py b/src/allmydata/scripts/tahoe_put.py index 3dc13773..a92cfc53 100644 --- a/src/allmydata/scripts/tahoe_put.py +++ b/src/allmydata/scripts/tahoe_put.py @@ -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: diff --git a/src/allmydata/test/test_cli.py b/src/allmydata/test/test_cli.py index ab2e2222..9a60c5fd 100644 --- a/src/allmydata/test/test_cli.py +++ b/src/allmydata/test/test_cli.py @@ -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: