From: robk-tahoe Date: Wed, 24 Sep 2008 15:20:02 +0000 (-0700) Subject: CLI: reconcile webopen changes X-Git-Url: https://git.rkrishnan.org/listings/pb2server.py?a=commitdiff_plain;h=2c9a854f10243fe55509f1cd45b1fa1a6e4b04bf;p=tahoe-lafs%2Ftahoe-lafs.git CLI: reconcile webopen changes I think this is largely attributable to a cleanup patch I'd made which never got committed upstream somehow, but at any rate various conflicting changes to webopen had been made. This cleans up the conflicts therein, and hopefully brings 'tahoe webopen' in line with other cli commands. --- diff --git a/docs/CLI.txt b/docs/CLI.txt index 04a1a8b8..b581f6d6 100644 --- a/docs/CLI.txt +++ b/docs/CLI.txt @@ -178,7 +178,7 @@ tahoe list-aliases tahoe mkdir tahoe mkdir [alias:]path tahoe ls [alias:][path] -tahoe webopen [alias:]path +tahoe webopen [alias:][path] tahoe put [--mutable] [localfrom:-] tahoe put [--mutable] [localfrom:-] [alias:]to tahoe put [--mutable] [localfrom:-] [alias:]subdir/to @@ -234,12 +234,15 @@ tahoe ls subdir This lists a subdirectory of your filesystem. +tahoe webopen tahoe webopen tahoe: tahoe webopen tahoe:subdir/ +tahoe webopen 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. + add, dowlonad, rename, and delete files in the directory. If not given an + alias or path, opens "tahoe:", the root dir of the default alias. tahoe put file.txt tahoe put ./file.txt diff --git a/src/allmydata/scripts/cli.py b/src/allmydata/scripts/cli.py index 7e0e5865..98e48995 100644 --- a/src/allmydata/scripts/cli.py +++ b/src/allmydata/scripts/cli.py @@ -189,8 +189,11 @@ 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=None): + self.where = where + + def getSynopsis(self): + return "%s webopen [ALIAS:PATH]" % (os.path.basename(sys.argv[0]),) longdesc = """Opens a webbrowser to the contents of some portion of the virtual drive.""" @@ -274,16 +277,9 @@ def ln(options): return rc def webopen(options, opener=None): - import urllib, webbrowser - nodeurl = config['node-url'] - if nodeurl[-1] != "/": - nodeurl += "/" - root_cap = config.aliases["tahoe"] - url = nodeurl + "uri/%s/" % urllib.quote(root_cap) - if config['vdrive_pathname']: - url += urllib.quote(config['vdrive_pathname']) - webbrowser.open(url) - return 0 + from allmydata.scripts import tahoe_webopen + rc = tahoe_webopen.webopen(options, opener=opener) + return rc dispatch = { "mkdir": mkdir, diff --git a/src/allmydata/scripts/tahoe_webopen.py b/src/allmydata/scripts/tahoe_webopen.py index 92a3023c..4065660b 100644 --- a/src/allmydata/scripts/tahoe_webopen.py +++ b/src/allmydata/scripts/tahoe_webopen.py @@ -1,17 +1,21 @@ from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, escape_path +import urllib -def webopen(nodeurl, aliases, where, stdout, stderr): - import urllib, webbrowser +def webopen(options, opener=None): + nodeurl = options['node-url'] if not nodeurl.endswith("/"): nodeurl += "/" - if where.endswith("/"): - where = where[:-1] - rootcap, path = get_alias(aliases, where, DEFAULT_ALIAS) + where = options.where + if where is None: + where = 'tahoe:' + rootcap, path = get_alias(options.aliases, where, DEFAULT_ALIAS) url = nodeurl + "uri/%s" % urllib.quote(rootcap) if path: - # move where.endswith check here? url += "/" + escape_path(path) - webbrowser.open(url) + if not opener: + import webbrowser + opener = webbrowser.open + opener(url) return 0