From: Zooko O'Whielacronx Date: Fri, 17 Aug 2007 19:54:47 +0000 (-0700) Subject: command-line: fix all three commands and all two ways to invoke them to require node... X-Git-Url: https://git.rkrishnan.org/(%5B%5E?a=commitdiff_plain;h=bffd0c97f5703acc69b63e34ed812b14fd2ebbc2;p=tahoe-lafs%2Ftahoe-lafs.git command-line: fix all three commands and all two ways to invoke them to require node-url and give a useful usage string if node-url is absent or of the wrong form --- diff --git a/src/allmydata/scripts/cli.py b/src/allmydata/scripts/cli.py index 5eec4a29..61180061 100644 --- a/src/allmydata/scripts/cli.py +++ b/src/allmydata/scripts/cli.py @@ -1,8 +1,10 @@ -import os.path, sys +import os.path, re, sys from twisted.python import usage from allmydata.scripts.common import BaseOptions +NODEURL_RE=re.compile("http://([^:]*)(:([1-9][0-9]*))?") + class VDriveOptions(BaseOptions, usage.Options): optParameters = [ ["vdrive", "d", "global", @@ -12,6 +14,10 @@ class VDriveOptions(BaseOptions, usage.Options): "URL of the tahoe node to use, a URL like \"http://127.0.0.1:8888\""], ] + def postOptions(self): + if not isinstance(self['node-url'], basestring) or not NODEURL_RE.match(self['node-url']): + raise usage.UsageError("--node-url is required to be a string and look like \"http://HOSTNAMEORADDR:PORT\", not: %r" % (self['node-url'],)) + class ListOptions(VDriveOptions): def parseArgs(self, vdrive_filename=""): self['vdrive_filename'] = vdrive_filename diff --git a/src/allmydata/scripts/tahoe_get.py b/src/allmydata/scripts/tahoe_get.py index fd655533..efaa5d0c 100644 --- a/src/allmydata/scripts/tahoe_get.py +++ b/src/allmydata/scripts/tahoe_get.py @@ -2,11 +2,13 @@ import sys, urllib -def get(server, vdrive, vdrive_file, local_file): +def get(nodeurl, vdrive, vdrive_file, local_file): + if not isinstance(nodeurl, basestring): + raise ValueError("nodeurl is required to be a string and look like \"http://HOSTNAMEORADDR:PORT\", not: %r" % (nodeurl,)) - if server[-1] != "/": - server += "/" - url = server + "vdrive/" + vdrive + "/" + if nodeurl[-1] != "/": + nodeurl += "/" + url = nodeurl + "vdrive/" + vdrive + "/" if vdrive_file: url += vdrive_file @@ -26,19 +28,23 @@ def get(server, vdrive, vdrive_file, local_file): def main(): - import optparse + import optparse, re parser = optparse.OptionParser() parser.add_option("-d", "--vdrive", dest="vdrive", default="global") - parser.add_option("-s", "--server", dest="server", default="http://tahoebs1.allmydata.com:8011") + parser.add_option("-u", "--nodeurl", dest="nodeurl") (options, args) = parser.parse_args() + NODEURL_RE=re.compile("http://([^:]*)(:([1-9][0-9]*))?") + if not isinstance(options.nodeurl, basestring) or not NODEURL_RE.match(options.nodeurl): + raise ValueError("--node-url is required to be a string and look like \"http://HOSTNAMEORADDR:PORT\", not: %r" % (options.nodeurl,)) + vdrive_file = args[0] local_file = None if len(args) > 1: local_file = args[1] - get(options.server, options.vdrive, vdrive_file, local_file) + get(options.nodeurl, options.vdrive, vdrive_file, local_file) if __name__ == '__main__': main() diff --git a/src/allmydata/scripts/tahoe_ls.py b/src/allmydata/scripts/tahoe_ls.py index d94c3f17..473d9804 100644 --- a/src/allmydata/scripts/tahoe_ls.py +++ b/src/allmydata/scripts/tahoe_ls.py @@ -3,11 +3,10 @@ import urllib import simplejson -def list(server, vdrive, vdrive_file): - - if server[-1] != "/": - server += "/" - url = server + "vdrive/" + vdrive + "/" +def list(nodeurl, vdrive, vdrive_file): + if nodeurl[-1] != "/": + nodeurl += "/" + url = nodeurl + "vdrive/" + vdrive + "/" if vdrive_file: url += vdrive_file url += "?t=json" @@ -30,18 +29,22 @@ def list(server, vdrive, vdrive_file): def main(): - import optparse + import optparse, re parser = optparse.OptionParser() parser.add_option("-d", "--vdrive", dest="vdrive", default="global") - parser.add_option("-s", "--server", dest="server", default="http://tahoebs1.allmydata.com:8011") + parser.add_option("-u", "--node-url", dest="nodeurl") (options, args) = parser.parse_args() + NODEURL_RE=re.compile("http://([^:]*)(:([1-9][0-9]*))?") + if not isinstance(options.nodeurl, basestring) or not NODEURL_RE.match(options.nodeurl): + raise ValueError("--node-url is required to be a string and look like \"http://HOSTNAMEORADDR:PORT\", not: %r" % (options.nodeurl,)) + vdrive_file = "" if args: vdrive_file = args[0] - list(options.server, options.vdrive, vdrive_file) + list(options.nodeurl, options.vdrive, vdrive_file) if __name__ == '__main__': main() diff --git a/src/allmydata/scripts/tahoe_put.py b/src/allmydata/scripts/tahoe_put.py index 37d987a3..5475bde8 100644 --- a/src/allmydata/scripts/tahoe_put.py +++ b/src/allmydata/scripts/tahoe_put.py @@ -2,7 +2,7 @@ import re, socket, sys -SERVERURL_RE=re.compile("http://([^:]*)(:([1-9][0-9]*))?") +NODEURL_RE=re.compile("http://([^:]*)(:([1-9][0-9]*))?") def put(nodeurl, vdrive, vdrive_fname, local_fname, verbosity): """ @@ -13,7 +13,7 @@ def put(nodeurl, vdrive, vdrive_fname, local_fname, verbosity): if not isinstance(nodeurl, basestring): raise ValueError("nodeurl is required to be a string and look like \"http://HOSTNAMEORADDR:PORT\", not: %r" % (nodeurl,)) - mo = SERVERURL_RE.match(nodeurl) + mo = NODEURL_RE.match(nodeurl) if not mo: raise ValueError("nodeurl is required to look like \"http://HOSTNAMEORADDR:PORT\", not: %r" % (nodeurl,)) host = mo.group(1) @@ -78,19 +78,23 @@ def put(nodeurl, vdrive, vdrive_fname, local_fname, verbosity): return 1 def main(): - import optparse + import optparse, re parser = optparse.OptionParser() parser.add_option("-d", "--vdrive", dest="vdrive", default="global") - parser.add_option("-s", "--server", dest="server", default="http://tahoebs1.allmydata.com:8011") + parser.add_option("-u", "--node-url", dest="nodeurl") (options, args) = parser.parse_args() + NODEURL_RE=re.compile("http://([^:]*)(:([1-9][0-9]*))?") + if not isinstance(options.nodeurl, basestring) or not NODEURL_RE.match(options.nodeurl): + raise ValueError("--node-url is required to be a string and look like \"http://HOSTNAMEORADDR:PORT\", not: %r" % (options.nodeurl,)) + local_file = args[0] vdrive_file = None if len(args) > 1: vdrive_file = args[1] - return put(options.server, options.vdrive, vdrive_file, local_file) + return put(options.nodeurl, options.vdrive, vdrive_file, local_file) if __name__ == '__main__': main()