CLI: add put --mutable, enhance ls to show mutable vs immutable as rw/r-
authorBrian Warner <warner@allmydata.com>
Tue, 20 May 2008 19:36:55 +0000 (12:36 -0700)
committerBrian Warner <warner@allmydata.com>
Tue, 20 May 2008 19:36:55 +0000 (12:36 -0700)
src/allmydata/scripts/cli.py
src/allmydata/scripts/tahoe_ls.py
src/allmydata/scripts/tahoe_put.py
src/allmydata/test/test_system.py

index baee26b5a6cbd4d615e0a03a3e3743d07e8d884c..84042186b91ab046672a7529144a0f7eaf4b9364 100644 (file)
@@ -114,6 +114,10 @@ class GetOptions(VDriveOptions):
     will be written to stdout."""
 
 class PutOptions(VDriveOptions):
+    optFlags = [
+        ("mutable", "m", "Create a mutable file instead of an immutable one."),
+        ]
+
     def parseArgs(self, arg1=None, arg2=None):
         # cat FILE > tahoe put           # create unlinked file from stdin
         # cat FILE > tahoe put FOO       # create tahoe:FOO from stdin
@@ -229,6 +233,7 @@ def put(config, stdout, stderr, stdin=sys.stdin):
                        config.aliases,
                        config.from_file,
                        config.to_file,
+                       config['mutable'],
                        verbosity,
                        stdin, stdout, stderr)
     return rc
index edfcce2cb0a38e8c1ef8a5acb2a2bc754fb7e5ae..821c98c4595884080736f09906015a91716c1e58 100644 (file)
@@ -36,6 +36,8 @@ def list(nodeurl, aliases, where, config, stdout, stderr):
         childtype = child[0]
         ctime = child[1]["metadata"].get("ctime")
         mtime = child[1]["metadata"].get("mtime")
+        rw_uri = child[1].get("rw_uri")
+        ro_uri = child[1].get("ro_uri")
         if ctime:
             # match for formatting that GNU 'ls' does
             if (now - ctime) > 6*30*24*60*60:
@@ -47,21 +49,32 @@ def list(nodeurl, aliases, where, config, stdout, stderr):
         else:
             ctime_s = "-"
         if childtype == "dirnode":
-            t = "d---------"
+            t0 = "d"
             size = "-"
             classify = "/"
         elif childtype == "filenode":
-            t = "----------"
+            t0 = "-"
             size = child[1]['size']
             classify = ""
-            if "rw_uri" in child[1]:
-                classify = "*" # mutable
+        else:
+            t0 = "?"
+            size = "?"
+            classify = "?"
+        t1 = "-"
+        if ro_uri:
+            t1 = "r"
+        t2 = "-"
+        if rw_uri:
+            t2 = "w"
+        t3 = "-"
+        if childtype == "dirnode":
+            t3 = "x"
 
-        uri = child[1].get("rw_uri", child[1].get("ro_uri", "-"))
+        uri = rw_uri or ro_uri
 
         line = []
         if config["long"]:
-            line.append("%s %10s %12s" % (t, size, ctime_s))
+            line.append("%s %10s %12s" % (t0+t1+t2+t3, size, ctime_s))
         if config["uri"]:
             line.append(uri)
         line.append(name)
index 6288cac10f6cd5c032591137396e2bc36030cac7..6d87b5e5775dcef3fe563127b0b0ef5861094281 100644 (file)
@@ -4,8 +4,8 @@ import urllib
 from allmydata.scripts.common_http import do_http
 from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, escape_path
 
-def put(nodeurl, aliases, from_file, to_file, verbosity,
-        stdin, stdout, stderr):
+def put(nodeurl, aliases, from_file, to_file, mutable,
+        verbosity, stdin, stdout, stderr):
     """
     @param verbosity: 0, 1, or 2, meaning quiet, verbose, or very verbose
 
@@ -20,6 +20,8 @@ def put(nodeurl, aliases, from_file, to_file, verbosity,
             url += escape_path(path)
     else:
         url = nodeurl + "uri"
+    if mutable:
+        url += "?mutable=true"
     if from_file:
         infileobj = open(from_file, "rb")
     else:
index 50662db36d98a4564b23ce0f7818b6845282e0a2..f74c06af360a4c2fbaef1ebae4092c3a67dcfabd 100644 (file)
@@ -1604,6 +1604,7 @@ class SystemTest(testutil.SignalMixin, testutil.PollMixin, testutil.StallMixin,
         d.addCallback(run, "put", files[1], "subdir/tahoe-file1")
         #  tahoe put bar tahoe:FOO
         d.addCallback(run, "put", files[2], "tahoe:file2")
+        d.addCallback(run, "put", "--mutable", files[3], "tahoe:file3")
 
         def _put_from_stdin(res, data, *args):
             args = nodeargs + list(args)
@@ -1629,7 +1630,7 @@ class SystemTest(testutil.SignalMixin, testutil.PollMixin, testutil.StallMixin,
                       "tahoe:from-stdin")
 
         d.addCallback(run, "ls")
-        d.addCallback(_check_ls, ["tahoe-file0", "file2", "subdir",
+        d.addCallback(_check_ls, ["tahoe-file0", "file2", "file3", "subdir",
                                   "tahoe-file-stdin", "from-stdin"])
         d.addCallback(run, "ls", "subdir")
         d.addCallback(_check_ls, ["tahoe-file1"])
@@ -1670,7 +1671,10 @@ class SystemTest(testutil.SignalMixin, testutil.PollMixin, testutil.StallMixin,
             lines = out.split("\n")
             for l in lines:
                 if "tahoe-file-stdin" in l:
+                    self.failUnless(l.startswith("-r-- "), l)
                     self.failUnless(" %d " % len(STDIN_DATA) in l)
+                if "file3" in l:
+                    self.failUnless(l.startswith("-rw- "), l) # mutable
         d.addCallback(_check_ls_l)
 
         d.addCallback(run, "mv", "tahoe-file-stdin", "tahoe-moved")