[Tahoe-dev] better tahoe get cmdline client

Zooko O'Whielacronx zooko at zooko.com
Tue Jul 10 01:51:13 UTC 2007


Folks:

Now you can get files out of a tahoe grid from the command-line more  
flexibly.  The full history of this file is visible in the revision  
control browser [1]), and the current version is:

Regards,

Zooko

------- begin included file tahoe-get.py
#!/usr/bin/env python

import optparse, os, sys, urllib

def GET(url, outf=None):
     f = urllib.urlopen(url)
     d = f.read()
     if outf is not None:
         outf.write(d)

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("-r", "--recursive", dest="recursive",  
action="store_true", default=False)

(options, args) = parser.parse_args()

vfname = args[0]
if len(args) == 1 or args[1] == "-":
     targfname = None
else:
     targfname = args[1]

base = options.server
base += "/vdrive/"
base += options.vdrive
base += "/"

url = base + vfname

def is_local(server):
     return server.startswith("http://localhost") or server.startswith 
("http://127.0.0.1")

if targfname is None:
     GET(url, sys.stdout)
elif options.recursive:
     if not is_local(options.server):
         parser.error("We can't do the --recursive option with a  
remote server.")
     else:
         fullfname = os.path.abspath(targfname)
         assert not os.path.exists(fullfname)
         url += "?localdir=%s" % fullfname
     GET(url)
else:
     GET(url, open(targfname, "wb"))
------- end included file tahoe-get.py

[1] http://allmydata.org/trac/tahoe/timeline



More information about the tahoe-dev mailing list