add owner, mtime and pkgver to info database

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

View file

@ -4,6 +4,7 @@
import os import os
import sys import sys
import re import re
import pwd
import configparser import configparser
from functools import partial from functools import partial
import queue import queue
@ -140,6 +141,9 @@ class EventHandler(pyinotify.ProcessEvent):
(filename text unique, (filename text unique,
pkgname text, pkgname text,
pkgarch text, pkgarch text,
pkgver text,
owner text,
mtime int,
state int)''') state int)''')
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')]
@ -237,9 +241,19 @@ class EventHandler(pyinotify.ProcessEvent):
if act.action == 'add': if act.action == 'add':
self._db.execute('update pkginfo set state = 0 where pkgname = ? and pkgarch = ?', (act.name, act.arch)) self._db.execute('update pkginfo set state = 0 where pkgname = ? and pkgarch = ?', (act.name, act.arch))
def callback(): def callback():
stat = os.stat(act.path)
mtime = int(stat.st_mtime)
try:
owner = pwd.getpwuid(stat.st_uid).pw_name
except KeyError:
owner = 'uid_%d' % stat.st_uid
self._db.execute( self._db.execute(
'insert or replace into pkginfo (filename, pkgname, pkgarch, state) values (?, ?, ?, ?)', '''insert or replace into pkginfo
(act.path, act.name, act.arch, 1)) (filename, pkgname, pkgarch, pkgver, state, owner, mtime) values
(?, ?, ?, ?, ?, ?, ?)''',
(act.path, act.name, act.arch, act.fullversion, 1, owner, mtime))
else: else:
res = self._db.execute('select state from pkginfo where filename = ? and state = 1 limit 1', (act.path,)) res = self._db.execute('select state from pkginfo where filename = ? and state = 1 limit 1', (act.path,))
if tuple(res) == (): if tuple(res) == ():