amprolla

devuan's apt repo merger
git clone git://parazyd.org/amprolla.git
Log | Files | Refs | README | LICENSE

commit 922535c9e9d39afcf2cb0c384220a0625e04c170
parent ad4a91c066ce306caf619fc3783cc963ab9c4802
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Fri, 26 May 2017 00:54:13 +0200

Add rewriting of 'Filepath' using a custom rewrite function

Diffstat:
Mamprolla | 14++++++++++++--
Mlib/package.py | 20++++++++++++++++----
2 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/amprolla b/amprolla @@ -30,10 +30,20 @@ devuan = load_packages_file(join(roots['devuan'], packages_file)) debian = load_packages_file(join(roots['debian'], packages_file)) debian_sec = load_packages_file(join(roots['debian-sec'], packages_file)) -all_repos = [devuan, debian_sec, debian] +all_repos = [{'name': 'devuan', 'packages': devuan}, + {'name': 'debian-sec', 'packages': debian_sec}, + {'name': 'debian', 'packages': debian}] + +def devuan_rewrite(pkg, repo_name): + if repo_name == 'devuan': + pkg['Filename'] = pkg['Filename'].replace('pool/', 'pool/%s/' % + repo_name.upper()) + + return pkg + print('Merging packages') -new_pkgs = merge_packages_many(all_repos, banned_packages=banpkgs) +new_pkgs = merge_packages_many(all_repos, banned_packages=banpkgs, rewriter=devuan_rewrite) print('Writing packages') write_packages(new_pkgs, 'Packages.merged') diff --git a/lib/package.py b/lib/package.py @@ -51,7 +51,8 @@ def package_banned(pkg, banned_pkgs): return bool(deps.intersection(banned_pkgs)) -def merge_packages(pkg1, pkg2, banned_packages=set()): +def merge_packages(pkg1, pkg2, name1, name2, banned_packages=set(), + rewriter=None): """ Merges two previously loaded/parsed (using load_packages_file) packages dictionaries, preferring `pkg1` over `pkg2`, and optionally discarding any @@ -65,19 +66,26 @@ def merge_packages(pkg1, pkg2, banned_packages=set()): pkg2_pkg = pkg2.get(pkg) if pkg1_pkg and pkg2_pkg: + if rewriter: + pkg1_pkg = rewriter(pkg1_pkg, name1) new_pkgs[pkg] = pkg1_pkg elif pkg1_pkg: if not package_banned(pkg1_pkg, banned_packages): + if rewriter: + pkg1_pkg = rewriter(pkg1_pkg, name1) + new_pkgs[pkg] = pkg1_pkg elif pkg2_pkg: if not package_banned(pkg2_pkg, banned_packages): + if rewriter: + pkg2_pkg = rewriter(pkg2_pkg, name2) new_pkgs[pkg] = pkg2_pkg else: assert False, 'Impossibru' return new_pkgs -def merge_packages_many(packages, banned_packages=set()): # TODO: Make generic +def merge_packages_many(packages, banned_packages=set(), rewriter=None): """ Merges two (or more) previously loaded/parsed (using load_packages_file) packages dictionaries, priority is defined by the order of the `packages` @@ -90,9 +98,13 @@ def merge_packages_many(packages, banned_packages=set()): # TODO: Make generic pkg1 = packages[0] pkg2 = packages[1] - new_pkgs = merge_packages(pkg1, pkg2, banned_packages=banned_packages) + new_pkgs = merge_packages(pkg1['packages'], pkg2['packages'], + pkg1['name'], pkg2['name'], + banned_packages=banned_packages, + rewriter=rewriter) for pkg in packages[2:]: - new_pkgs = merge_packages(new_pkgs, pkg, banned_packages=banned_packages) + new_pkgs = merge_packages(new_pkgs, pkg['packages'], '', pkg['name'], + banned_packages=banned_packages) return new_pkgs