From: Brian Warner Date: Tue, 12 Aug 2008 01:20:23 +0000 (-0700) Subject: CLI: make 'tahoe webopen' command accept aliases like 'tahoe ls' X-Git-Url: https://git.rkrishnan.org/frontends/specifications/install.html?a=commitdiff_plain;h=376df2eb5ae34601c823ba78c87ed96d6ee63fe3;p=tahoe-lafs%2Ftahoe-lafs.git CLI: make 'tahoe webopen' command accept aliases like 'tahoe ls' --- diff --git a/docs/CLI.txt b/docs/CLI.txt index 0f61dcb8..2431e000 100644 --- a/docs/CLI.txt +++ b/docs/CLI.txt @@ -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 diff --git a/src/allmydata/scripts/cli.py b/src/allmydata/scripts/cli.py index 5c207ee2..183421a5 100644 --- a/src/allmydata/scripts/cli.py +++ b/src/allmydata/scripts/cli.py @@ -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): diff --git a/src/allmydata/test/test_cli.py b/src/allmydata/test/test_cli.py index 5fdf6f40..da358af7 100644 --- a/src/allmydata/test/test_cli.py +++ b/src/allmydata/test/test_cli.py @@ -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):