amprolla

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

commit 33b2e59db09f7bfa6f44e61fde227c6029205891
parent 740333927d14cfef6d09e196b2b74c1d60faa146
Author: parazyd <parazyd@dyne.org>
Date:   Tue,  6 Jun 2017 22:49:57 +0200

(not finished) begin implementing general logic for updates

Diffstat:
Damprolla_download.py | 76----------------------------------------------------------------------------
Mamprolla_merge.py | 1+
Aamprolla_update.py | 64++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 65 insertions(+), 76 deletions(-)

diff --git a/amprolla_download.py b/amprolla_download.py @@ -1,76 +0,0 @@ -#!/usr/bin/env python3 -# see LICENSE file for copyright and license details - -""" -module to pool and download Release files when needed -""" - -import subprocess -from os.path import join -import requests - -from lib.net import download -from lib.parse import parse_release, get_time, get_date - - -roots = { - 'devuan': { - 'local': 'spool/devuan/dists/jessie', - 'remote': 'http://auto.mirror.devuan.org/devuan/dists/jessie', - }, - 'debian': { - 'local': 'spool/debian/dists/jessie', - 'remote': 'http://ftp.debian.org/debian/dists/jessie', - }, - 'debian-sec': { - 'local': 'spool/dists/jessie/updates', - 'remote': 'http://security.debian.org/dists/jessie/updates', - }, -} - -release_file = 'Release' - - -def merge_files(repo, relfile): - """ - Loads the local release and call the merge process - """ - print('Loading Release') - rel = join(roots[repo]['local'], relfile) - release_contents = open(rel).read() - - hashes = parse_release(release_contents) - - for k in hashes: - # if k.endswith('Packages.gz'): - if k.endswith('/binary-armhf/Packages.gz'): - # skip empty files - # TODO: probably best to copy it in place when this occurs - if hashes[k] == 'f61f27bd17de546264aa58f40f3aafaac7021e0ef69c17f6b1b4cd7664a037ec': - print('Skipping %s' % k) - continue - - subprocess.run(['./amprolla-merge', k]) - - -local_rel = join(roots['devuan']['local'], release_file) -remote_rel = join(roots['devuan']['remote'], release_file) - -# Possibly use this var to check for changed hashes -local_contents = open(local_rel).read() -local_date = get_date(local_contents) - -r = requests.get(remote_rel) -remote_contents = r.text -remote_date = get_date(remote_contents) - -print('Local date: %s' % local_date) -print('Remote date: %s' % remote_date) - -if get_time(remote_date) > get_time(local_date): - # dump new release in place and merge - # NOTE: when testing, watch out because you lose the old Release file in - # spool - print('Remote is newer') - download(remote_rel, local_rel) - merge_files('devuan', local_rel) diff --git a/amprolla_merge.py b/amprolla_merge.py @@ -93,6 +93,7 @@ def merge(packages_list): print('Writing packages') # replace the devuan subdir with our mergedir that we plan to fill + # FIXME: do not assume Devuan always exists new_out = packages_list[0].replace(join(spooldir, repos['devuan']['dists']), join(mergedir, mergesubdir)) diff --git a/amprolla_update.py b/amprolla_update.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 +# see LICENSE file for copyright and license details + +""" +Perform incremental updates +""" + +from os.path import join +import requests + +from amprolla_init import pop_dirs +from amprolla_merge import prepare_merge_dict +from lib.config import repos, spooldir +from lib.parse import parse_release, get_time, get_date, compare_dict + +from pprint import pprint + + +roots = prepare_merge_dict() + +needsmerge = [] + +for suite, paths in roots.items(): + print(suite) + print(paths) + devuan_loc = paths[0] + debian_sec_loc = paths[1] + debian_loc = paths[2] + + if devuan_loc: + devuan_rem = devuan_loc.replace(spooldir, repos['devuan']['host']) + print(devuan_rem) + remoterel = join(devuan_rem, 'Release') + localrel = join(devuan_loc, 'Release') + + if remote_is_newer(remoterel, localrel): + print('Do something') + # probably add suite to needsmerge + + if debian_sec_loc: + print('Do the same') + + if debian_loc: + print('Do the same') + + + break + +def remote_is_newer(remote, local): + rem = requests.get(remote) + rem_contents = rem.text + rem_date = get_date(rem_contents) + + loc_contents = open(localrel).read() + loc_date = get_date(loc_contents) + + print('Remote date: %s' % rem_date) + print('Local date: %s' % loc_date) + + if get_time(rem_date) > get_time(loc_date): + print('Remote Release is newer!') + return True + + return False