]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
cli: cleanup webopen command
authorrobk-tahoe <robk-tahoe@allmydata.com>
Wed, 18 Jun 2008 20:19:40 +0000 (13:19 -0700)
committerrobk-tahoe <robk-tahoe@allmydata.com>
Wed, 18 Jun 2008 20:19:40 +0000 (13:19 -0700)
moved the body of webopen out of cli.py into tahoe_webopen.py

made its invocation consistent with the other cli commands, most
notably replacing its 'vdrive path' with the same alias parsing,
allowing usage such as 'tahoe webopen private:Pictures/xti'

src/allmydata/scripts/cli.py
src/allmydata/scripts/tahoe_webopen.py [new file with mode: 0644]

index 2de968bd913ea2a7bf74c7bce818ea9f2c8d2234..7e0e5865c92e0db74234a15ac73f6ffbfdeaca27 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, where=""):
-        self.where = where
+    def parseArgs(self, vdrive_pathname=""):
+        self['vdrive_pathname'] = vdrive_pathname
 
     longdesc = """Opens a webbrowser to the contents of some portion of the virtual drive."""
 
@@ -275,22 +275,14 @@ def ln(options):
 
 def webopen(options, opener=None):
     import urllib, webbrowser
-    from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, escape_path
-    nodeurl = options['node-url']
+    nodeurl = config['node-url']
     if nodeurl[-1] != "/":
         nodeurl += "/"
-    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)
+    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
 
 dispatch = {
diff --git a/src/allmydata/scripts/tahoe_webopen.py b/src/allmydata/scripts/tahoe_webopen.py
new file mode 100644 (file)
index 0000000..92a3023
--- /dev/null
@@ -0,0 +1,17 @@
+
+from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, escape_path
+
+def webopen(nodeurl, aliases, where, stdout, stderr):
+    import urllib, webbrowser
+    if not nodeurl.endswith("/"):
+        nodeurl += "/"
+    if where.endswith("/"):
+        where = where[:-1]
+    rootcap, path = get_alias(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)
+    return 0
+