]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
CLI: make 'tahoe webopen' command accept aliases like 'tahoe ls'
authorBrian Warner <warner@allmydata.com>
Tue, 12 Aug 2008 01:20:23 +0000 (18:20 -0700)
committerBrian Warner <warner@allmydata.com>
Tue, 12 Aug 2008 01:20:23 +0000 (18:20 -0700)
docs/CLI.txt
src/allmydata/scripts/cli.py
src/allmydata/test/test_cli.py

index 0f61dcb8281586116055d18b684a635cd96349eb..2431e000a37653a67ed935492939d5928f07b1ca 100644 (file)
@@ -178,6 +178,7 @@ tahoe list-aliases
 tahoe mkdir
 tahoe mkdir [alias:]path
 tahoe ls [alias:][path]
+tahoe webopen [alias:]path
 tahoe put [--mutable] [localfrom:-]
 tahoe put [--mutable] [localfrom:-] [alias:]to
 tahoe put [--mutable] [localfrom:-] [alias:]subdir/to
@@ -233,6 +234,13 @@ tahoe ls subdir
 
  This lists a subdirectory of your filesystem.
 
+tahoe webopen tahoe:
+tahoe webopen tahoe:subdir/
+
+ This uses the python 'webbrowser' module to cause a local web browser to
+ open to the web page for the given directory. This page offers interfaces to
+ add, dowlonad, rename, and delete files in the directory.
+
 tahoe put file.txt
 tahoe put ./file.txt
 tahoe put /tmp/file.txt
index 5c207ee2433684cdf75b688bd44a4eb96c87eb54..183421a53c7096c0254368b24b616413ac135b4e 100644 (file)
@@ -189,8 +189,8 @@ class LnOptions(VDriveOptions):
         return "%s ln FROM TO" % (os.path.basename(sys.argv[0]),)
 
 class WebopenOptions(VDriveOptions):
-    def parseArgs(self, vdrive_pathname=""):
-        self['vdrive_pathname'] = vdrive_pathname
+    def parseArgs(self, where=""):
+        self.where = where
 
     longdesc = """Opens a webbrowser to the contents of some portion of the virtual drive."""
 
@@ -277,16 +277,24 @@ def ln(options):
     rc = tahoe_mv.mv(options, mode="link")
     return rc
 
-def webopen(options):
+def webopen(options, opener=None):
     import urllib, webbrowser
+    from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, escape_path
     nodeurl = options['node-url']
     if nodeurl[-1] != "/":
         nodeurl += "/"
-    root_cap = options.aliases["tahoe"]
-    url = nodeurl + "uri/%s/" % urllib.quote(root_cap)
-    if options['vdrive_pathname']:
-        url += urllib.quote(options['vdrive_pathname'])
-    webbrowser.open(url)
+    where = options.where
+    if where.endswith("/"):
+        where = where[:-1]
+    rootcap, path = get_alias(options.aliases, where, DEFAULT_ALIAS)
+    url = nodeurl + "uri/%s" % urllib.quote(rootcap)
+    if path:
+        url += "/" + escape_path(path)
+    if url[-1] != "/":
+        url += "/"
+    if opener is None:
+        opener = webbrowser.open
+    opener(url)
     return 0
 
 def repl(options):
index 5fdf6f403f1f8663e0001c60f952e2b1057c494d..da358af7c8451c5fdb134f2ffbb0e607859caf6b 100644 (file)
@@ -235,6 +235,16 @@ class CLITestMixin:
 
 class CreateAlias(SystemTestMixin, CLITestMixin, unittest.TestCase):
 
+    def _test_webopen(self, args, expected_url):
+        woo = cli.WebopenOptions()
+        all_args = ["--node-directory", self.getdir("client0")] + list(args)
+        woo.parseOptions(all_args)
+        urls = []
+        rc = cli.webopen(woo, urls.append)
+        self.failUnlessEqual(rc, 0)
+        self.failUnlessEqual(len(urls), 1)
+        self.failUnlessEqual(urls[0], expected_url)
+
     def test_create(self):
         self.basedir = os.path.dirname(self.mktemp())
         d = self.set_up_nodes()
@@ -246,6 +256,27 @@ class CreateAlias(SystemTestMixin, CLITestMixin, unittest.TestCase):
             self.failUnless("tahoe" in aliases)
             self.failUnless(aliases["tahoe"].startswith("URI:DIR2:"))
         d.addCallback(_done)
+        d.addCallback(lambda res: self.do_cli("create-alias", "two"))
+        def _stash_urls(res):
+            aliases = get_aliases(self.getdir("client0"))
+            node_url_file = os.path.join(self.getdir("client0"), "node.url")
+            nodeurl = open(node_url_file, "r").read().strip()
+            uribase = nodeurl + "uri/"
+            self.tahoe_url = uribase + urllib.quote(aliases["tahoe"]) + "/"
+            self.tahoe_subdir_url = self.tahoe_url + "subdir/"
+            self.two_url = uribase + urllib.quote(aliases["two"]) + "/"
+        d.addCallback(_stash_urls)
+
+        d.addCallback(lambda res: self._test_webopen([], self.tahoe_url))
+        d.addCallback(lambda res: self._test_webopen(["/"], self.tahoe_url))
+        d.addCallback(lambda res: self._test_webopen(["tahoe:"], self.tahoe_url))
+        d.addCallback(lambda res: self._test_webopen(["tahoe:/"], self.tahoe_url))
+        d.addCallback(lambda res: self._test_webopen(["tahoe:subdir"],
+                                                     self.tahoe_subdir_url))
+        d.addCallback(lambda res: self._test_webopen(["tahoe:subdir/"],
+                                                     self.tahoe_subdir_url))
+        d.addCallback(lambda res: self._test_webopen(["two:"], self.two_url))
+
         return d
 
 class Put(SystemTestMixin, CLITestMixin, unittest.TestCase):