]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
CLI: make the --mutable-type option value for 'tahoe put' and 'tahoe mkdir' case...
authordavid-sarah <david-sarah@jacaranda.org>
Mon, 5 Sep 2011 02:09:22 +0000 (19:09 -0700)
committerdavid-sarah <david-sarah@jacaranda.org>
Mon, 5 Sep 2011 02:09:22 +0000 (19:09 -0700)
src/allmydata/scripts/cli.py
src/allmydata/scripts/tahoe_put.py
src/allmydata/test/test_cli.py

index b041b581f4cd0f3d1109b6344fc8480822dcd92e..970c8c409e80491261f94389f487daf05b98feff 100644 (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,)
 
index 3dc13773fa75a8a62c97e9c4bce68451330940a5..a92cfc53e9cef047edf23f7093ee14b93b015bf1 100644 (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:
index ab2e2222da27ed2b20c072ad1ca364576832e816..9a60c5fdd5d9dcccae56596a05dcccefae09a160 100644 (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: