summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Grapentin <andreas@grapentin.org>2019-03-03 15:35:45 +0100
committerAndreas Grapentin <andreas@grapentin.org>2019-03-03 15:35:45 +0100
commitdbaf0a2c36d37fcbad55c4a87bbc918f59821e92 (patch)
tree922e909e96b0d9e1a5746aeaf0e557e271929628
parent9f4c84bc1969587f632e3011329656d86b79cde5 (diff)
parsing buildinfo of upstream packages
-rw-r--r--parabola_repolint/__main__.py8
-rw-r--r--parabola_repolint/linter.py43
-rw-r--r--parabola_repolint/repocache.py40
3 files changed, 52 insertions, 39 deletions
diff --git a/parabola_repolint/__main__.py b/parabola_repolint/__main__.py
index e95ec33..317495d 100644
--- a/parabola_repolint/__main__.py
+++ b/parabola_repolint/__main__.py
@@ -15,7 +15,7 @@ from parabola_repolint.notify import etherpad_replace, send_mail, write_log
def make_argparser(linter):
''' produce the argparse object '''
- checks = "\n " + "\n ".join(sorted(linter.checks))
+ checks = "\n " + "\n ".join(sorted(map(str, linter.checks)))
parser = argparse.ArgumentParser(
description='parabola package linter',
formatter_class=argparse.RawDescriptionHelpFormatter,
@@ -40,7 +40,7 @@ def make_argparser(linter):
'-c',
'--checks',
type=lambda a: set() if not a else set(s.strip() for s in a.split(',')),
- default=','.join(linter.checks),
+ default=','.join(map(str, linter.checks)),
help='comma-separated list of checks to perform'
)
@@ -62,11 +62,11 @@ def checked_main(args):
args = make_argparser(linter).parse_args(args)
- diff = args.checks.union(args.skip_checks).difference(linter.checks)
+ diff = args.checks.union(args.skip_checks).difference(map(str, linter.checks))
if diff:
logging.warning("unrecognized linter checks: %s", ', '.join(diff))
- checks = args.checks.intersection(linter.checks).difference(args.skip_checks)
+ checks = args.checks.intersection(map(str, linter.checks)).difference(args.skip_checks)
linter.load_checks(checks)
cache.load_repos(args.noupdate, args.ignore_cache)
linter.run_checks()
diff --git a/parabola_repolint/linter.py b/parabola_repolint/linter.py
index ecd4d9c..b0a4def 100644
--- a/parabola_repolint/linter.py
+++ b/parabola_repolint/linter.py
@@ -10,22 +10,38 @@ import socket
import enum
-# pylint: disable=too-few-public-methods,no-self-use
-class LinterCheckBase():
+class LinterCheckMeta(type):
+ ''' a meta class for linter checks '''
+
+ def __repr__(cls):
+ ''' produce a string representation of the check '''
+ return cls.name
+
+
+class LinterCheckBase(metaclass=LinterCheckMeta):
''' a base class for linter checks '''
def __init__(self, linter, cache):
''' a default constructor '''
self._linter = linter
self._cache = cache
+ self._issues = []
- def format(self, issues):
+ @property
+ def issues(self):
+ ''' produce the list of issues generated by this check '''
+ return self._issues
+
+ def format(self):
''' a default formatter for found issues '''
res = []
- for issue in issues:
+ for issue in self._issues:
res.append(' ' + issue[0] % issue[1:])
return "\n".join(sorted(res))
+ def __repr__(self):
+ ''' produce a string representation of the check '''
+ return str(type(self))
class LinterIssue(Exception):
@@ -61,7 +77,7 @@ def _load_linter_checks_from(package_name):
for cls in module.__dict__.values():
if _is_linter_check(cls):
- logging.debug('loaded linter check "%s"', cls.name)
+ logging.debug('loaded linter check "%s"', cls)
result.append(cls)
return result
@@ -74,7 +90,6 @@ class Linter():
''' constructor '''
self._checks = _load_linter_checks_from('parabola_repolint.linter_checks')
self._enabled_checks = []
- self._issues = {}
self._cache = repo_cache
@@ -84,7 +99,7 @@ class Linter():
@property
def checks(self):
''' return the names of all supported linter checks '''
- return map(lambda c: c.name, self._checks)
+ return self._checks
def register_repo_cache(self, cache):
''' store a reference to the repo cache '''
@@ -110,7 +125,6 @@ class Linter():
for check_type in LinterCheckType:
check_func = check_funcs[check_type]
for check in [c for c in self._enabled_checks if c.check_type == check_type]:
- self._issues[check] = []
logging.info('running check %s', check)
check_func(check)
@@ -141,12 +155,13 @@ class Linter():
for key in self._cache.keyring:
self._try_check(check, key)
+ # pylint: disable=no-self-use
def _try_check(self, check, *args, **kwargs):
''' run a check and catch any LinterIssue '''
try:
check.check(*args, **kwargs)
except LinterIssue as i:
- self._issues[check].append(i.args)
+ check.issues.append(i.args)
def format(self):
''' return a formatted string of the linter issues '''
@@ -159,10 +174,10 @@ Generated by parabola-repolint on %s at %s
''' % (socket.gethostname(), now)
for check in self._enabled_checks:
- if self._issues[check]:
+ if check.issues:
header = '%s:\n%s' % (check.header, '-' * (len(check.header) + 1))
out += '\n\n\n%s\n%s\nissues:\n' % (header, check.__doc__)
- out += check.format(self._issues[check])
+ out += check.format()
return out
def short_format(self):
@@ -171,8 +186,8 @@ Generated by parabola-repolint on %s at %s
out = 'parabola-repolint check at %s' % now
for check in self._enabled_checks:
- if self._issues[check]:
- out += '\n %s: %i' % (check.header, len(self._issues[check]))
+ if check.issues:
+ out += '\n %s: %i' % (check, len(check.issues))
out += '\ntotal issues: %i' % self.total_issues
return out
@@ -182,7 +197,7 @@ Generated by parabola-repolint on %s at %s
''' produce the total number of found issues '''
res = 0
for check in self._enabled_checks:
- res += len(self._issues[check])
+ res += len(check.issues)
return res
@property
diff --git a/parabola_repolint/repocache.py b/parabola_repolint/repocache.py
index ec353b0..dae9bbb 100644
--- a/parabola_repolint/repocache.py
+++ b/parabola_repolint/repocache.py
@@ -99,26 +99,24 @@ class PkgFile():
logging.warning('unhandled PKGINFO key: %s', key)
self._buildinfo = {}
- # only parse .BUILDINFO for parabola packages
- if repo.name in CONFIG.parabola.repos:
- buildinfo = self._cached_buildinfo(path + '.buildinfo', mtime)
- for line in buildinfo.splitlines():
- key, value = line.split('=', 1)
- key = key.strip()
- value = value.strip()
-
- if key in BUILDINFO_VALUE:
- self._buildinfo[key] = value
- elif key in BUILDINFO_SET:
- if key not in self._buildinfo:
- self._buildinfo[key] = set()
- self._buildinfo[key].add(value)
- elif key in BUILDINFO_LIST:
- if key not in self._buildinfo:
- self._buildinfo[key] = list()
- self._buildinfo[key].append(value)
- else:
- logging.warning('unhandled BUILDINFO key: %s', key)
+ buildinfo = self._cached_buildinfo(path + '.buildinfo', mtime)
+ for line in buildinfo.splitlines():
+ key, value = line.split('=', 1)
+ key = key.strip()
+ value = value.strip()
+
+ if key in BUILDINFO_VALUE:
+ self._buildinfo[key] = value
+ elif key in BUILDINFO_SET:
+ if key not in self._buildinfo:
+ self._buildinfo[key] = set()
+ self._buildinfo[key].add(value)
+ elif key in BUILDINFO_LIST:
+ if key not in self._buildinfo:
+ self._buildinfo[key] = list()
+ self._buildinfo[key].append(value)
+ else:
+ logging.warning('unhandled BUILDINFO key: %s', key)
self._siginfo = self._cached_siginfo(path + '.siginfo', mtime)
@@ -838,7 +836,7 @@ class RepoCache():
src = keyring_pkgfile.path
dst = self._keyring_dir
- if not os.path.isdir(dst) or os.path.getmtime(dst) > os.path.getmtime(src):
+ if not os.path.isdir(dst) or os.path.getmtime(dst) <= os.path.getmtime(src):
os.makedirs(dst, exist_ok=True)
shutil.rmtree(dst)
os.makedirs(dst, exist_ok=True)