Browse Source

pylint/pep8 fixes, remove some cruft from lib

keep-around/e977c9e07f177e8bc2b51265de1bc93475397f61
parazyd 6 years ago
parent
commit
f9d091ad6f
Signed by untrusted user: parazyd GPG Key ID: F0CB28FCF78637DE
  1. 31
      lib/config.py
  2. 34
      lib/fs.py
  3. 7
      lib/log.py
  4. 17
      lib/net.py
  5. 6
      lib/package.py
  6. 78
      lib/parse.py

31
lib/config.py

@ -1,12 +1,17 @@
#!/usr/bin/env python
# copyright (c) 2017 - Ivan J. <parazyd@dyne.org>
# see LICENSE file for copyright and license details
"""
amprolla configuration file
"""
# from hashlib import md5, sha1, sha256
spooldir = './spool'
sign_key = 'fa1b0274'
mergedir = './merged'
mergesubdir = 'dists'
banpkgs = {'systemd', 'systemd-sysv'}
# checksums = [{'name': 'MD5Sum', 'f': md5}, sha1, sha256]
# checksums = [ 'md5sum', 'sha1', 'sha256', 'sha512' ]
repo_order = ['devuan', 'debian-sec', 'debian']
@ -73,7 +78,27 @@ aliases = {
categories = ['main', 'contrib', 'non-free']
arches = ['binary-armhf']
arches = [
# 'binary-all',
# 'binary-alpha',
# 'binary-amd64',
# 'binary-arm64',
# 'binary-armel',
'binary-armhf',
# 'binary-hppa',
# 'binary-hurd-i386',
# 'binary-i386',
# 'binary-ia64',
# 'binary-kfreebsd-amd64',
# 'binary-kfreebsd-i386',
# 'binary-mips',
# 'binary-mips64el',
# 'binary-mipsel',
# 'binary-powerpc',
# 'binary-ppc64el',
# 'binary-s390x',
# 'binary-sparc'
]
mainrepofiles = [
'InRelease',

34
lib/fs.py

@ -1,34 +0,0 @@
#!/usr/bin/env python
# copyright (c) 2017 - Ivan J. <parazyd@dyne.org>
# see LICENSE file for copyright and license details
import config
def crawl():
paths = {}
for i in range(0, len(config.repos)):
repo = config.repos[i]["name"]
basepath = config.repos[i]["dists"]
sts = []
for j in config.suites:
for k in config.suites[j]:
if config.repos[i]["aliases"] is True:
if repo in config.aliases:
try:
suite = config.aliases[repo][k]
except:
if config.repos[i]["skipmissing"] is True:
continue
else:
suite = k
else:
suite = k
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())

7
lib/log.py

@ -1,9 +1,10 @@
#!/usr/bin/env python
# copyright (c) 2017 - Ivan J. <parazyd@dyne.org>
# see LICENSE file for copyright and license details
# TODO: Replace with logging
"""
Logging functions
"""
# TODO: Replace with logging
import sys

17
lib/net.py

@ -1,25 +1,30 @@
#!/usr/bin/env python3
# copyright (c) 2017 - Ivan J. <parazyd@dyne.org>
# see LICENSE file for copyright and license details
import requests
"""
Network functions/helpers
"""
import os
import requests
from .log import die, notice, warn, cleanexit
from .log import die, warn
def download(url, path):
"""
Downloads a file by providing it an url and a write path
"""
print("downloading: %s\nto: %s" % (url, path))
r = requests.get(url, stream=True)
if r.status_code == 404:
warn("download of %s failed: not found!" % url)
return
elif r.status_code != 200:
die("download of %s failed", url)
die("download of %s failed" % url)
os.makedirs(os.path.dirname(path), exist_ok=True)
with open(path, "wb") as f:
# XXX: should be more on gbit servers
# chunk_size {sh,c}ould be more on gbit servers
for chunk in r.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)

6
lib/package.py

@ -1,3 +1,9 @@
# see LICENSE file for copyright and license details
"""
Package merging functions and helpers
"""
import os
from gzip import open as gzip_open

78
lib/parse.py

@ -1,22 +1,24 @@
#!/usr/bin/env python
# copyright (c) 2017 - Ivan J. <parazyd@dyne.org>
# see LICENSE file for copyright and license details
import ast
import gzip
"""
Parsing functions/helpers
"""
import re
#import requests
import time
from . import config
from .log import notice
def get_time(date):
"""
Gets epoch time
"""
return time.mktime(time.strptime(date, "%a, %d %b %Y %H:%M:%S %Z"))
def get_date(relfile):
"""
Gets the date from the contents of a Release file
"""
date = None
contents = relfile.split('\n')
for line in contents:
@ -48,6 +50,11 @@ def parse_release(reltext):
def parse_release_re(reltext):
"""
Parses a Release file using regular expressions and returns a dict
of the files we keed
key = filename, value = sha256 checksum
"""
_hash = {}
match = re.search('SHA256:+', reltext)
if match:
@ -95,9 +102,11 @@ def parse_package_re(entry):
def parse_packages(pkgtext):
# this parses our package file into a hashmap
# key: package name, value: entire package paragraph as a hashmap
map = {}
"""
Parses our package file contents into a hashmap
key: package name, value: entire package paragraph as a hashmap
"""
_map = {}
pkgs = pkgtext.split("\n\n")
for pkg in pkgs:
@ -105,9 +114,10 @@ def parse_packages(pkgtext):
if m:
line = pkg[m.start():m.end()]
key = line.split(': ')[1]
map[key] = parse_package(pkg)
_map[key] = parse_package(pkg)
return _map
return map
def parse_dependencies(dependencies):
"""
@ -127,8 +137,8 @@ def parse_dependencies(dependencies):
v = pkg_plus_version.split(' ', 1)
name = v[0]
# If we get passed an empty string, the name is '', and we just outright
# stop
# If we get passed an empty string, the name is '', and we just
# outright stop
if not name:
return {}
@ -141,44 +151,12 @@ def parse_dependencies(dependencies):
return r
def print_package(map, pkgname):
try:
pkg = ast.literal_eval(map[pkgname])
sin = []
for i in config.pkgfmt:
if config.pkgfmt[i] in pkg.keys():
sin.append(config.pkgfmt[i] + pkg[config.pkgfmt[i]])
return sin
except:
log.die("nonexistent package")
def compare_dict(d1, d2):
"""
Compares two dicts
"""
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]}
return modified
def compare_release(oldrel, newrel):
r = requests.get(newrel)
new = r.text
with open(oldrel, "rb") as f:
old = f.read()
oldtime = get_time(get_date(old))
newtime = get_time(get_date(new))
if newtime > oldtime:
notice("Update available")
newhashes = parse_release(new)
oldhashes = parse_release(old)
changes = compare_dict(newhashes, oldhashes)
# k = pkg name, v = sha256
return changes
# 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)

Loading…
Cancel
Save