amprolla

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

commit 5df8c5c98b05552b52dafe784239e4067b223351
parent 198ab28f3bff343175099626b40066f53a0c6d80
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Sat, 20 May 2017 23:49:35 +0200

PEP8 fixes

Diffstat:
Mamprolla-init | 12++++++------
Mlib/config.py | 8++++----
Mlib/delta.py | 48+++++++++++++++++++++++++-----------------------
Mlib/fs.py | 9+++++----
Mlib/log.py | 4++++
Mlib/net.py | 5+++--
6 files changed, 47 insertions(+), 39 deletions(-)

diff --git a/amprolla-init b/amprolla-init @@ -3,10 +3,7 @@ # see LICENSE file for copyright and license details import os -#import re -import requests import sys -import threading import lib.config as config import lib.delta as delta @@ -20,8 +17,10 @@ def popDirs(): notice("creating initial directory structure") for i in range(0, len(paths)): - baseurl = "http://" + "/".join([config.repos[i]["host"], config.repos[i]["dists"]]) - basepath = "/".join([config.amprolla["spooldir"], config.repos[i]["dists"]]) + baseurl = "http://" + \ + "/".join([config.repos[i]["host"], config.repos[i]["dists"]]) + basepath = "/".join([config.amprolla["spooldir"], + config.repos[i]["dists"]]) for j in paths[config.repos[i]["name"]]: suiteurl = "/".join([baseurl, j]) @@ -38,7 +37,7 @@ def popDirs(): try: with open(suitepath + "/Release", "rb") as frel: rels = frel.read() - relmap = delta.parseRel(rels) + relmap = delta.parse_release(rels) except IOError: warn("no Release file for %s" % suitepath) @@ -55,6 +54,7 @@ def popDirs(): except TypeError: warn("Typeerror") + def merge(): for i in config.amprolla["mergedsubdirs"]: mdir = "/".join([config.amprolla["mergedir"], i]) diff --git a/lib/config.py b/lib/config.py @@ -6,13 +6,13 @@ amprolla = { "spooldir": "./spool", "sign_key": "fa1b0274", "mergedir": "./merged", - "mergedsubdirs": [ "dists", "pool"], - "banpkgs": [ 'systemd', 'systemd-sysv' ] + "mergedsubdirs": ["dists", "pool"], + "banpkgs": ['systemd', 'systemd-sysv'] #"checksums": [ 'md5sum', 'sha1', 'sha256', 'sha512' ] } repos = { - ## key name is priority, first is 0 + # key name is priority, first is 0 0: { "name": "DEVUAN", "host": "packages.devuan.org", @@ -73,7 +73,7 @@ aliases = { } } -categories = [ 'main', 'contrib', 'non-free' ] +categories = ['main', 'contrib', 'non-free'] releases = { diff --git a/lib/delta.py b/lib/delta.py @@ -11,10 +11,12 @@ import time import config from log import notice -def getTime(date): + +def get_time(date): return time.mktime(time.strptime(date, "%a, %d %b %Y %H:%M:%S %Z")) -def getDate(relfile): + +def get_date(relfile): match = re.search('Date: .+', relfile) if match: line = relfile[match.start():match.end()] @@ -22,36 +24,36 @@ def getDate(relfile): return relfile -def parseRel(reltext): +def parse_release(reltext): hash = {} match = re.search('SHA256:+', reltext) if match: line = reltext[match.start():-1] for i in line.split('\n'): - if i == 'SHA256:' or i == '\n': # XXX: hack + if i == 'SHA256:' or i == '\n': # XXX: hack continue hash[(i.split()[2])] = i.split()[0] return hash -def pkgParse(entry): +def parse_package(entry): # for parsing a single package values = re.split('\\n[A-Z].+?:', entry)[0:] values[0] = values[0].split(':')[1] - keys = re.findall('\\n[A-Z].+?:', '\n'+entry) + keys = re.findall('\\n[A-Z].+?:', '\n' + entry) both = zip(keys, values) return {key.lstrip(): value for key, value in both} -def parsePkgs(pkgtext): +def parse_packages(pkgtext): # this parses our package file into a hashmap # key: package name, value: entire package paragraph as a hashmap map = {} # TODO: consider also this approach - #def parsePkgs(pkgfilepath): - #with gzip.open(pkgfilepath, "rb") as f: - # pkgs = f.read().split("\n\n") + # def parse_packages(pkgfilepath): + # with gzip.open(pkgfilepath, "rb") as f: + # pkgs = f.read().split("\n\n") pkgs = pkgtext.split("\n\n") for pkg in pkgs: @@ -59,11 +61,11 @@ def parsePkgs(pkgtext): if m: line = pkg[m.start():m.end()] key = line.split(': ')[1] - map[key] = pkgParse(pkg) + map[key] = parse_package(pkg) return map -def printPkg(map, pkgname): +def print_package(map, pkgname): try: pkg = ast.literal_eval(map[pkgname]) sin = [] @@ -75,32 +77,32 @@ def printPkg(map, pkgname): log.die("nonexistent package") -def dictCompare(d1, d2): +def compare_dict(d1, d2): d1_keys = set(d1.keys()) d2_keys = set(d2.keys()) intersect_keys = d1_keys.intersection(d2_keys) - modified = {o : (d1[o], d2[o]) for o in intersect_keys if d1[o] != d2[o]} + modified = {o: (d1[o], d2[o]) for o in intersect_keys if d1[o] != d2[o]} return modified -def compareRel(oldrel, newrel): +def compare_release(oldrel, newrel): r = requests.get(newrel) new = r.text with open(oldrel, "rb") as f: old = f.read() - oldtime = getTime(getDate(old)) - newtime = getTime(getDate(new)) + oldtime = get_time(get_date(old)) + newtime = get_time(get_date(new)) if newtime > oldtime: notice("Update available") - newhashes = parseRel(new) - oldhashes = parseRel(old) - changes = dictCompare(newhashes, oldhashes) + newhashes = parse_release(new) + oldhashes = parse_release(old) + changes = compare_dict(newhashes, oldhashes) # k = pkg name, v = sha256 return changes -#relmap = compareRel("../spool/dists/jessie/updates/Release", "http://security.debian.org/dists/jessie/updates/Release") -#print relmap -#for k,v in relmap.iteritems(): +# relmap = compare_release("../spool/dists/jessie/updates/Release", "http://security.debian.org/dists/jessie/updates/Release") +# print relmap +# for k,v in relmap.iteritems(): # print(k) diff --git a/lib/fs.py b/lib/fs.py @@ -4,6 +4,7 @@ import config + def crawl(): paths = {} for i in range(0, len(config.repos)): @@ -12,22 +13,22 @@ def crawl(): sts = [] for j in config.suites: for k in config.suites[j]: - if config.repos[i]["aliases"] == True: + if config.repos[i]["aliases"] is True: if repo in config.aliases: try: suite = config.aliases[repo][k] except: - if config.repos[i]["skipmissing"] == True: + if config.repos[i]["skipmissing"] is True: continue else: suite = k else: suite = k - skips = [ "jessie-security", "ascii-security" ] ## XXX: HACK: + skips = ["jessie-security", "ascii-security"] # XXX: HACK: if repo == "DEBIAN" and suite in skips: continue sts.append(suite) paths[repo] = sts return paths -#print(crawl()) +# print(crawl()) diff --git a/lib/log.py b/lib/log.py @@ -4,18 +4,22 @@ import sys + def die(msg): print("\033[1;31m[E] %s\033[0m" % msg) sys.exit(1) + def notice(msg): print("\033[1;32m(*) %s\033[0m" % msg) return + def warn(msg): print("\033[1;33m[W] %s\033[0m" % msg) return + def cleanexit(): notice("exiting cleanly...") sys.exit(0) diff --git a/lib/net.py b/lib/net.py @@ -18,9 +18,10 @@ def download(url, path): die("fail!") with open(path, "wb") as f: - for chunk in r.iter_content(chunk_size=1024): # XXX: should be more on gbit servers + # XXX: should be more on gbit servers + for chunk in r.iter_content(chunk_size=1024): if chunk: f.write(chunk) - #f.flush() + # f.flush() print("\033[1;32m . done\033[0m") return