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.
This commit is contained in:
robk-tahoe 2008-09-24 08:20:02 -07:00
parent 8f28d64d77
commit 2c9a854f10
3 changed files with 24 additions and 21 deletions

View File

@ -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

View File

@ -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,

View File

@ -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