mirror of
https://github.com/lilydjwg/archrepo2.git
synced 2025-03-10 12:02:43 +00:00
add signature management
This commit is contained in:
parent
71338599b5
commit
29906bfc3b
1 changed files with 28 additions and 10 deletions
38
repomon.py
38
repomon.py
|
@ -26,13 +26,13 @@ import dbutil
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
# handles only x86_64, i686 and any arch packages
|
# 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):
|
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:
|
if four is not None:
|
||||||
return super().__new__(cls, path, action, four, five)
|
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 = cls.parseFilename(file)
|
||||||
self.action = action
|
self.action = action
|
||||||
self.path = path
|
self.path = path
|
||||||
|
@ -207,6 +207,8 @@ class EventHandler(pyinotify.ProcessEvent):
|
||||||
mtime int,
|
mtime int,
|
||||||
state int,
|
state int,
|
||||||
info blob)''')
|
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')]
|
dirs = [os.path.join(base, x) for x in ('any', 'i686', 'x86_64')]
|
||||||
self.files = files = set()
|
self.files = files = set()
|
||||||
|
@ -219,6 +221,7 @@ class EventHandler(pyinotify.ProcessEvent):
|
||||||
|
|
||||||
def _initial_update(self, files):
|
def _initial_update(self, files):
|
||||||
oldfiles = {f[0] for f in self._db.execute('select filename from pkginfo')}
|
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):
|
for f in sorted(filterfalse(filterPkg, files - oldfiles), key=pkgsortkey):
|
||||||
self.dispatch(f, 'add')
|
self.dispatch(f, 'add')
|
||||||
|
@ -263,14 +266,20 @@ class EventHandler(pyinotify.ProcessEvent):
|
||||||
self.dispatch(event.pathname, 'add')
|
self.dispatch(event.pathname, 'add')
|
||||||
|
|
||||||
def dispatch(self, path, action):
|
def dispatch(self, path, action):
|
||||||
act = ActionInfo(path, action)
|
if path.endswith('.sig'):
|
||||||
d, file = os.path.split(path)
|
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)
|
base, arch = os.path.split(d)
|
||||||
|
|
||||||
# rename if a packager has added to a wrong directory
|
# 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
|
# 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)
|
newd = os.path.join(base, act.arch)
|
||||||
newpath = os.path.join(newd, file)
|
newpath = os.path.join(newd, file)
|
||||||
os.rename(path, newpath)
|
os.rename(path, newpath)
|
||||||
|
@ -289,7 +298,7 @@ class EventHandler(pyinotify.ProcessEvent):
|
||||||
os.symlink(os.path.join('..', arch, file), newpath)
|
os.symlink(os.path.join('..', arch, file), newpath)
|
||||||
except FileExistsError:
|
except FileExistsError:
|
||||||
pass
|
pass
|
||||||
self._real_dispatch(newd, ActionInfo(newpath, action))
|
callback(newd, ActionInfo(newpath, action))
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
os.unlink(newpath)
|
os.unlink(newpath)
|
||||||
|
@ -298,7 +307,7 @@ class EventHandler(pyinotify.ProcessEvent):
|
||||||
# someone deleted the file for us
|
# someone deleted the file for us
|
||||||
pass
|
pass
|
||||||
|
|
||||||
self._real_dispatch(d, act)
|
callback(d, act)
|
||||||
|
|
||||||
def _real_dispatch(self, d, act):
|
def _real_dispatch(self, d, act):
|
||||||
if act.action == 'add':
|
if act.action == 'add':
|
||||||
|
@ -338,8 +347,17 @@ class EventHandler(pyinotify.ProcessEvent):
|
||||||
act.callback = callback
|
act.callback = callback
|
||||||
self.repomans[d].add_action(act)
|
self.repomans[d].add_action(act)
|
||||||
|
|
||||||
# def process_default(self, event):
|
def _record_signatures(self, d, action):
|
||||||
# print(event)
|
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):
|
def filterPkg(path):
|
||||||
if isinstance(path, Event):
|
if isinstance(path, Event):
|
||||||
|
|
Loading…
Add table
Reference in a new issue