Пример #1
0
def fetch_extract_archive_to_ca(url, basename, in_hash, keep_basename,
                                out_hash):
    global _disable_op_fail_message
    extract_basename = extract.get_extracted_path(basename)

    if len(out_hash) == 0:
        extract_hash = get_unknown_hash()
    else:
        extract_hash = out_hash
        ca_out_path = genesis.make_ca_path(out_hash, extract_basename)
        if os.path.exists(ca_out_path):
            log.verbose(
                "archive '{}' already fetched and extracted to '{}'".format(
                    url, ca_out_path))
            return ca_out_path

    ca_in_path = fetch_archive_to_ca(url, basename, in_hash, 'inHash')
    extract_path = genesis.make_ca_stage_path(extract_hash, extract_basename)
    if os.path.exists(extract_path):
        sys.exit(
            "Error: cannot extract '{}' because extract path '{}' already exists"
            .format(ca_in_path, extract_path))

    actual_extract_basename = extract.extract(ca_in_path,
                                              extract_path,
                                              keep_basename=keep_basename)
    if not actual_extract_basename.endswith(extract_basename):
        sys.exit(
            "Error(code bug) extract basename mismatch, expected '{}' got '{}'"
            .format(extract_basename, actual_extract_basename))
    file_type, actual_out_hash = genesis.hash_path(extract_path)
    if len(out_hash) == 0:
        correct_path = genesis.make_ca_path(actual_out_hash, extract_basename)
        if os.path.exists(correct_path):
            log.rmtree(extract_path)
        else:
            log.rename(extract_path, correct_path)
        log.log("Please update outHash for '{}' to this:".format(url))
        log.log(actual_out_hash)
        _disable_op_fail_message = True
        sys.exit(1)
    if out_hash != actual_out_hash:
        log.log("outHash Mismatch for '{}', expected then actual:".format(url))
        log.log(out_hash)
        log.log(actual_out_hash)
        _disable_op_fail_message = True
        sys.exit(1)
    log.rename(extract_path, ca_out_path)
    return ca_out_path
Пример #2
0
 def __init__(self):
     self.proxies = urllib.request.getproxies()
     if os.name == "nt":
         # check if an auto configure script is being used
         with winreg.OpenKey(winreg.HKEY_CURRENT_USER, INTERNET_SETTINGS, 0, winreg.KEY_READ) as key:
             autoconfurl = winregGetString(key, "AutoConfigURL")
             if autoconfurl:
                 slug_url = slugify(autoconfurl)
                 downloaded_path = os.path.join(genesis.get_proxy_path(), slug_url)
                 if os.path.exists(downloaded_path):
                     log.verbose("autoconf script '{}' has already been downloaded".format(downloaded_path))
                 else:
                     tmp_path = downloaded_path + ".downloading"
                     if os.path.exists(tmp_path):
                         sys.exit("not impl: download path '{}' already exists".format(tmp_path))
                     download_no_proxy_init(autoconfurl, tmp_path)
                     log.rename(tmp_path, downloaded_path)
                 log.log("WARNING: need to parse/use '{}' (probably need spidermonkey and/or pypac)".format(downloaded_path))
Пример #3
0
def write_gen_obj(gen_obj):
    # TODO: lock the stage path
    stage_file = gen_obj.get_obj_stage_path()
    if os.path.exists(stage_file):
        sys.exit(
            "stage path for genesis object file '{}' already exists, not impl".
            format(stage_file))
    with open(stage_file, "wb") as file:
        file.write(gen_obj.get_hashdata().encode('ascii'))
    # verify the hash
    actual_hash = hash_file(stage_file)
    if actual_hash != gen_obj.get_hash():
        os.remove(stage_file)
        sys.exit("Error: code bug, hashes didn't match {} and {}".format(
            actual_hash, gen_obj.get_hash()))
    obj_path = gen_obj.get_obj_path()
    log.rename(stage_file, obj_path)
    return obj_path
Пример #4
0
def fetch_archive_to_ca(url, basename, in_hash, hash_name):
    global _disable_op_fail_message
    if len(in_hash) == 0:
        download_hash = get_unknown_hash()
    else:
        download_hash = in_hash
        ca_in_path = genesis.make_ca_path(in_hash, basename)
        if os.path.exists(ca_in_path):
            log.verbose("archive '{}' already fetched to '{}'".format(
                url, ca_in_path))
            return ca_in_path

    # TODO: need a lock file
    download_path = genesis.make_ca_stage_path(download_hash, basename)
    if os.path.exists(download_path):
        sys.exit(
            "Error: cannot download '{}' because download path '{}' already exists"
            .format(url, download_path))
    download.download(url, download_path)
    file_type, actual_in_hash = genesis.hash_path(download_path)
    if len(in_hash) == 0:
        correct_path = genesis.make_ca_path(actual_in_hash, basename)
        if os.path.exists(correct_path):
            log.rmtree_or_file(download_path)
        else:
            log.rename(download_path, correct_path)
        log.log("Please update {} for '{}' to this:".format(hash_name, url))
        log.log(actual_in_hash)
        _disable_op_fail_message = True
        sys.exit(1)
    if in_hash != actual_in_hash:
        log.log("{} Mismatch for '{}', expected then actual:".format(
            hash_name, url))
        log.log(in_hash)
        log.log(actual_in_hash)
        _disable_op_fail_message = True
        sys.exit(1)
    log.rename(download_path, ca_in_path)
    return ca_in_path
Пример #5
0
def moveToDir(op):
    src = op['src']
    dst = op['dst']
    log.rename(src, os.path.join(dst, os.path.basename(src)))
Пример #6
0
def move(op):
    src = op['src']
    dst = op['dst']
    log.rename(src, dst)