示例#1
0
def mangle_filename(old_filename, new_filename, mapping):
    with open(old_filename, "rb") as f:
        buf = f.read()

    new_buf = redll(buf, mapping)

    with open(new_filename, "wb") as f:
        f.write(new_buf)
示例#2
0
        print("copying from: ", dll_path, " to ", dest_path)
        if not os.path.exists(dest_path):
            shutil.copy(dll_path, dest_path)

    # copy in the module (base library)
    shutil.copy(myarg, os.path.join(dest_folder, base_lib))

    for lib in [
            os.path.join(dest_folder, f) for f in os.listdir(dest_folder)
            if os.path.isfile(os.path.join(dest_folder, f))
    ]:
        if re.search(".+\.py$", lib):
            continue
        print("patching symbols in file: ", lib)

        buf = None
        with open(lib, "rb") as f:
            buf = f.read()

        try:
            new_buf = redll(buf, manglermap)
        except ValueError as ve:
            print(ve)
            continue

        with open(lib, "wb") as f:
            f.write(new_buf)

    print(deps)
示例#3
0
    # 4. Repair a wheel
    DIST_DIR = 'dist'
    for whl in glob.glob(os.path.join(DIST_DIR, '*.whl')):
        whl_repair_dir = os.path.join(DIST_DIR, 'whl_repair')
        with zipfile.ZipFile(whl, 'r') as zip_ref:
            zip_ref.extractall(whl_repair_dir)

        for pyd_file in glob.glob(os.path.join(whl_repair_dir, '**', '*.pyd'),
                                  recursive=True):
            fn, ext = os.path.splitext(pyd_file)

            with open(pyd_file, "rb") as f:
                buf = f.read()

            new_buf = redll(buf, dll_map)

            with open(pyd_file, "wb") as f:
                f.write(new_buf)

        with zipfile.ZipFile(whl, 'w') as new_whl:
            for folder, subfolders, filenames in os.walk(whl_repair_dir):
                for filename in filenames:
                    #create complete filepath of file in directory
                    file_path = os.path.join(folder, filename)
                    # Add file to zip
                    new_whl.write(
                        file_path,
                        os.path.join(folder.replace(whl_repair_dir, ''),
                                     filename))
            whl_path = Path(whl)