reorder by version if unsure (upon starting)

This commit is contained in:
lilydjwg 2012-12-15 15:26:22 +08:00
parent 36206900f3
commit d2e4880186

View file

@ -12,6 +12,7 @@ import logging
import sqlite3 import sqlite3
import pyinotify import pyinotify
Event = pyinotify.Event
from tornado.ioloop import IOLoop from tornado.ioloop import IOLoop
import tornado.process import tornado.process
@ -158,12 +159,12 @@ 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')}
for f in files - oldfiles: for f in sorted(files - oldfiles, key=pkgsortkey):
if f.endswith('.pkg.tar.xz'): if not filterPkg(f):
self.dispatch(f, 'add') self.dispatch(f, 'add')
for f in oldfiles - files: for f in sorted(oldfiles - files, key=pkgsortkey):
if f.endswith('.pkg.tar.xz'): if not filterPkg(f):
self.dispatch(f, 'remove') self.dispatch(f, 'remove')
def process_IN_CLOSE_WRITE(self, event): def process_IN_CLOSE_WRITE(self, event):
@ -239,8 +240,8 @@ class EventHandler(pyinotify.ProcessEvent):
def _real_dispatch(self, d, act): def _real_dispatch(self, d, act):
if act.action == 'add': if act.action == 'add':
self._db.execute('update pkginfo set state = 0 where pkgname = ? and pkgarch = ?', (act.name, act.arch))
def callback(): def callback():
self._db.execute('update pkginfo set state = 0 where pkgname = ? and pkgarch = ?', (act.name, act.arch))
stat = os.stat(act.path) stat = os.stat(act.path)
mtime = int(stat.st_mtime) mtime = int(stat.st_mtime)
try: try:
@ -268,8 +269,14 @@ class EventHandler(pyinotify.ProcessEvent):
# def process_default(self, event): # def process_default(self, event):
# print(event) # print(event)
def filterPkg(event): def filterPkg(path):
return not _pkgfile_pat.search(event.pathname) if isinstance(path, Event):
path = path.pathname
return not _pkgfile_pat.search(path)
def pkgsortkey(path):
pkg = archpkg.PkgNameInfo.parseFilename(os.path.split(path)[1])
return (pkg.name, pkg.arch, pkg)
def main(conffile): def main(conffile):
config = configparser.ConfigParser() config = configparser.ConfigParser()