-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",
"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
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
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()
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"
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()
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):
"""
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)
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()