def cat(program, *urls): """Usage: [url ...] Concatenate the contents of all url[s] and print to stdout. If any of the url[s] are tags, the blobs reachable from the tags will be printed after any non-tag url[s]. """ from itertools import chain from subprocess import call from disco.comm import download from disco.util import deref, urlresolve, proxy_url from disco.compat import bytes_to_str ignore_missing = program.options.ignore_missing tags, urls = program.separate_tags(*urls) def curl(replicas): for replica in replicas: try: return download( proxy_url(urlresolve(replica, master=program.ddfs.master), to_master=False)) except Exception as e: sys.stderr.write("{0}\n".format(e)) if not ignore_missing: raise Exception( "Failed downloading all replicas: {0}".format(replicas)) return '' for replicas in deref(chain(urls, program.blobs(*tags))): sys.stdout.write(bytes_to_str(curl(replicas)))
def cat(program, *urls): """Usage: [url ...] Concatenate the contents of all url[s] and print to stdout. If any of the url[s] are tags, the blobs reachable from the tags will be printed after any non-tag url[s]. """ from itertools import chain from subprocess import call from disco.comm import download from disco.util import deref, urlresolve, proxy_url from disco.compat import bytes_to_str ignore_missing = program.options.ignore_missing tags, urls = program.separate_tags(*urls) def curl(replicas): for replica in replicas: try: return download(proxy_url(urlresolve(replica, master=program.ddfs.master), to_master=False)) except Exception as e: sys.stderr.write("{0}\n".format(e)) if not ignore_missing: raise Exception("Failed downloading all replicas: {0}".format(replicas)) return '' for replicas in deref(chain(urls, program.blobs(*tags))): sys.stdout.write(bytes_to_str(curl(replicas)))
def deref(program, *urls): """Usage: [url ...] Dereference the urls and print them to stdout. Input urls are specified as arguments or read from stdin. """ from disco.util import deref for input in deref(program.input(*urls), resolve=program.options.resolve): print("\t".join(input))
ignore_missing = program.options.ignore_missing tags, urls = program.separate_tags(*urls) def curl(replicas): for replica in replicas: try: return download(proxy_url(urlresolve(replica, master=program.ddfs.master), to_master=False)) except Exception, e: sys.stderr.write("%s\n" % e) if not ignore_missing: raise Exception("Failed downloading all replicas: %s" % replicas) return '' for replicas in deref(chain(urls, program.blobs(*tags))): sys.stdout.write(curl(replicas)) @DDFS.command def chtok(program, tag, token): """Usage: tag token Change the read/write tokens for a tag. """ if program.options.read: program.ddfs.setattr(tag, 'ddfs:read-token', token) if program.options.write: program.ddfs.setattr(tag, 'ddfs:write-token', token) chtok.add_option('-r', '--read', action='store_true',
from disco.util import deref ignore_missing = program.options.ignore_missing tags, urls = program.separate_tags(*urls) def curl(replicas): for replica in replicas: try: return download(replica) except Exception, e: sys.stderr.write("%s\n" % e) if not ignore_missing: raise Exception("Failed downloading all replicas: %s" % replicas) return '' for replicas in deref(chain(urls, program.blobs(*tags))): sys.stdout.write(curl(replicas)) @DDFS.command def chtok(program, tag, token): """Usage: tag token Change the read/write tokens for a tag. """ if program.options.read: program.ddfs.setattr(tag, 'ddfs:read-token', token) if program.options.write: program.ddfs.setattr(tag, 'ddfs:write-token', token)