Merge branch 'dev'

This commit is contained in:
lilydjwg 2013-04-14 14:56:33 +08:00
commit c45990c568
3 changed files with 31 additions and 12 deletions

View file

@ -13,5 +13,6 @@ DEPENDENCIES
TODO TODO
==== ====
* [high] adding and then removing it before adding complete will result in not-in-database removing
* [low] support symlinking packages here * [low] support symlinking packages here
* [low] verify packages * [low] verify packages

View file

@ -4,7 +4,7 @@ import logging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
multikeys = {'depend', 'makepkgopt', 'optdepend', 'replaces', 'conflict', multikeys = {'depend', 'makepkgopt', 'optdepend', 'replaces', 'conflict',
'provides', 'license', 'backup', 'group'} 'provides', 'license', 'backup', 'group', 'makedepend'}
def _add_to_dict(d, key, value): def _add_to_dict(d, key, value):
if key in multikeys: if key in multikeys:

View file

@ -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):
if path.endswith('.sig'):
act = ActionInfo(path, action, pkgpath=path[:-4])
callback = self._record_signatures
else:
act = ActionInfo(path, action) act = ActionInfo(path, action)
d, file = os.path.split(path) 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':
@ -315,7 +324,7 @@ class EventHandler(pyinotify.ProcessEvent):
try: try:
info = pkgreader.readpkg(act.path) info = pkgreader.readpkg(act.path)
except: 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 = None
info = pickle.dumps(info) info = pickle.dumps(info)
@ -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):