Beispiel #1
0
def download(url, dst_path):
    try:
        u = connectionhandled_urlopen(url)
    except IOError:
        raise RuntimeError("Could not open '%s'" % url)
    except ValueError as e:
        raise RuntimeError(e)

    size = get_http_value(u, 'Content-Length')
    if size:
        size = int(size)
        fn = basename(dst_path)
        getLogger('fetch.start').info((fn[:14], size))

    n = 0
    fo = open(dst_path, 'wb')
    while True:
        chunk = u.read(16384)
        if not chunk:
            break
        fo.write(chunk)
        n += len(chunk)
        if size:
            getLogger('fetch.update').info(n)
    fo.close()

    u.close()
    if size:
        getLogger('fetch.stop').info(None)
Beispiel #2
0
def download(url, dst_path):
    try:
        u = connectionhandled_urlopen(url)
    except IOError:
        raise RuntimeError("Could not open '%s'" % url)
    except ValueError as e:
        raise RuntimeError(e)

    size = get_http_value(u, 'Content-Length')
    if size:
        size = int(size)
        fn = basename(dst_path)
        getLogger('fetch.start').info((fn[:14], size))

    n = 0
    fo = open(dst_path, 'wb')
    while True:
        chunk = u.read(16384)
        if not chunk:
            break
        fo.write(chunk)
        n += len(chunk)
        if size:
            getLogger('fetch.update').info(n)
    fo.close()

    u.close()
    if size:
        getLogger('fetch.stop').info(None)
Beispiel #3
0
def add_http_value_to_dict(u, http_key, d, dict_key):
    value = get_http_value(u, http_key)
    if value:
        d[dict_key] = value
Beispiel #4
0
def add_http_value_to_dict(u, http_key, d, dict_key):
    value = get_http_value(u, http_key)
    if value:
        d[dict_key] = value