From 9642f479c26c126d90dc496b213937a756ac7b62 Mon Sep 17 00:00:00 2001 From: lilydjwg Date: Wed, 10 Apr 2013 16:26:17 +0800 Subject: [PATCH 1/4] update README --- README.mkd | 1 + 1 file changed, 1 insertion(+) diff --git a/README.mkd b/README.mkd index 46dfe9f..c247f74 100644 --- a/README.mkd +++ b/README.mkd @@ -13,5 +13,6 @@ DEPENDENCIES TODO ==== +* [high] adding and then removing it before adding complete will result in not-in-database removing * [low] support symlinking packages here * [low] verify packages From 921ff34f9dfeee7ee511988fc4bfa3faa1467805 Mon Sep 17 00:00:00 2001 From: lilydjwg Date: Wed, 10 Apr 2013 16:26:19 +0800 Subject: [PATCH 2/4] more verbose logging --- repomon.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repomon.py b/repomon.py index bca258f..0c9a581 100755 --- a/repomon.py +++ b/repomon.py @@ -315,7 +315,7 @@ class EventHandler(pyinotify.ProcessEvent): try: info = pkgreader.readpkg(act.path) except: - logger.error('failed to read info for package %s', act.path) + logger.error('failed to read info for package %s', act.path, exc_info=True) info = None info = pickle.dumps(info) From 71338599b51c73b37ff876d06178e257108f3648 Mon Sep 17 00:00:00 2001 From: lilydjwg Date: Fri, 12 Apr 2013 00:09:54 +0800 Subject: [PATCH 3/4] pkgreader.py: add multikey makedepend --- pkgreader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgreader.py b/pkgreader.py index e9b582e..52e4e7d 100644 --- a/pkgreader.py +++ b/pkgreader.py @@ -4,7 +4,7 @@ import logging logger = logging.getLogger(__name__) multikeys = {'depend', 'makepkgopt', 'optdepend', 'replaces', 'conflict', - 'provides', 'license', 'backup', 'group'} + 'provides', 'license', 'backup', 'group', 'makedepend'} def _add_to_dict(d, key, value): if key in multikeys: From 29906bfc3b14ba27e244c0350c111741efde58a7 Mon Sep 17 00:00:00 2001 From: lilydjwg Date: Sun, 14 Apr 2013 14:53:06 +0800 Subject: [PATCH 4/4] add signature management --- repomon.py | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/repomon.py b/repomon.py index 0c9a581..7007881 100755 --- a/repomon.py +++ b/repomon.py @@ -26,13 +26,13 @@ import dbutil logger = logging.getLogger(__name__) # handles only x86_64, i686 and any arch packages -_pkgfile_pat = re.compile(r'(?:^|/)[a-z0-9_-]+-[a-z0-9_.]+-\d+-(?:x86_64|i686|any)\.pkg\.tar\.xz$') +_pkgfile_pat = re.compile(r'(?:^|/)[a-z0-9_-]+-[a-z0-9_.]+-\d+-(?:x86_64|i686|any)\.pkg\.tar\.xz(?:\.sig)?$') class ActionInfo(archpkg.PkgNameInfo): - def __new__(cls, path, action, four=None, five=None): + def __new__(cls, path, action, four=None, five=None, pkgpath=None): if four is not None: return super().__new__(cls, path, action, four, five) - file = os.path.split(path)[1] + file = os.path.split(pkgpath or path)[1] self = cls.parseFilename(file) self.action = action self.path = path @@ -207,6 +207,8 @@ class EventHandler(pyinotify.ProcessEvent): mtime int, state int, info blob)''') + self._db.execute('''create table if not exists sigfiles + (filename text unique)''') dirs = [os.path.join(base, x) for x in ('any', 'i686', 'x86_64')] self.files = files = set() @@ -219,6 +221,7 @@ class EventHandler(pyinotify.ProcessEvent): def _initial_update(self, files): oldfiles = {f[0] for f in self._db.execute('select filename from pkginfo')} + oldfiles.update(f[0] for f in self._db.execute('select filename from sigfiles')) for f in sorted(filterfalse(filterPkg, files - oldfiles), key=pkgsortkey): self.dispatch(f, 'add') @@ -263,14 +266,20 @@ class EventHandler(pyinotify.ProcessEvent): self.dispatch(event.pathname, 'add') def dispatch(self, path, action): - act = ActionInfo(path, action) - d, file = os.path.split(path) + if path.endswith('.sig'): + act = ActionInfo(path, action, pkgpath=path[:-4]) + callback = self._record_signatures + else: + act = ActionInfo(path, action) + callback = self._real_dispatch + d, file = os.path.split(path) base, arch = os.path.split(d) # rename if a packager has added to a wrong directory # but not for a link that has arch=any, as that's what we created - if action == 'add' and act.arch != arch and not (os.path.islink(path) and act.arch == 'any'): + if action == 'add' and act.arch != arch and not \ + (os.path.islink(path) and act.arch == 'any'): newd = os.path.join(base, act.arch) newpath = os.path.join(newd, file) os.rename(path, newpath) @@ -289,7 +298,7 @@ class EventHandler(pyinotify.ProcessEvent): os.symlink(os.path.join('..', arch, file), newpath) except FileExistsError: pass - self._real_dispatch(newd, ActionInfo(newpath, action)) + callback(newd, ActionInfo(newpath, action)) else: try: os.unlink(newpath) @@ -298,7 +307,7 @@ class EventHandler(pyinotify.ProcessEvent): # someone deleted the file for us pass - self._real_dispatch(d, act) + callback(d, act) def _real_dispatch(self, d, act): if act.action == 'add': @@ -338,8 +347,17 @@ class EventHandler(pyinotify.ProcessEvent): act.callback = callback self.repomans[d].add_action(act) - # def process_default(self, event): - # print(event) + def _record_signatures(self, d, action): + path = action.path + action = action.action + logger.info('%s signature %s.', action, path) + if action == 'add': + self._db.execute('''insert or replace into sigfiles + (filename) values (?)''', + (path,)) + else: + self._db.execute('''delete from sigfiles where filename = ?''', + (path,)) def filterPkg(path): if isinstance(path, Event):