Exemple #1
0
def update_index(dir_path, force=False, verbose=False):
    index_path = join(dir_path, 'index.json')
    if force or not isfile(index_path):
        index = {}
    else:
        index = json.load(open(index_path, 'r'))

    new_index = {}
    for fn in os.listdir(dir_path):
        if not is_valid_eggname(fn):
            continue
        path = join(dir_path, fn)
        info = index.get(fn)
        if info and getmtime(path) == info['mtime']:
            new_index[fn] = info
            continue
        info = info_file(path)
        info.update(info_from_egg(path))
        new_index[fn] = info

    patches_index_path = join(dir_path, 'patches', 'index.json')
    if isfile(patches_index_path):
        patch_index = json.load(open(patches_index_path))
        for info in patch_index.itervalues():
            info['type'] = 'patch'
        new_index.update(patch_index)

    with open(index_path, 'w') as f:
        json.dump(new_index, f, indent=2, sort_keys=True)
Exemple #2
0
def update_index(eggs_dir, patches_dir, force=False):
    index_path = join(patches_dir, 'index.json')
    if force or not isfile(index_path):
        index = {}
    else:
        index = json.load(open(index_path))

    new_index = {}
    for patch_fn in os.listdir(patches_dir):
        if not fn_pat.match(patch_fn):
            continue
        src_fn, dst_fn = split(patch_fn)
        dst_path = join(eggs_dir, dst_fn)
        dst_size = getsize(dst_path)
        if dst_size < 131072:
            continue
        patch_path = join(patches_dir, patch_fn)
        if dst_size < getsize(patch_path) * 2:
            continue
        info = index.get(patch_fn)
        if info and getmtime(patch_path) == info['mtime']:
            new_index[patch_fn] = info
            continue
        info = info_file(patch_path)
        info.update(zdiff.info(patch_path))
        info['name'] = patch_fn.split('-')[0].lower()
        new_index[patch_fn] = info

    with open(index_path, 'w') as f:
        json.dump(new_index, f, indent=2, sort_keys=True)