示例#1
0
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)))
示例#2
0
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)))
示例#3
0
文件: discocli.py 项目: saa/disco
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))
示例#4
0
文件: ddfscli.py 项目: djagdish/disco
    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',
示例#5
0
    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)