cur.execute('CREATE TABLE IF NOT EXISTS updates ( `ext` TEXT, `update_time` INTEGER, `file_count` INTEGER);')
cur.execute('CREATE TABLE IF NOT EXISTS `update_status` ( `ext` TEXT UNIQUE, `status` INTEGER, PRIMARY KEY(`ext`);')
defregexp(expr,item,case):
ifcase:
@ -31,6 +33,8 @@ class Searcher:
def__init__(self,ext,case_sensitive=True):
self.cur=ext_database.cursor()
self.ext=ext
self.updating=False
self.update_thread=None
self.case=case_sensitive
self.index='{}_index'.format(ext)
self.__init_table__()
@ -38,25 +42,57 @@ class Searcher:
def__init_table__(self):
self.cur.execute('CREATE TABLE IF NOT EXISTS {} (`name` TEXT,`fullpath` TEXT, `update_time` INTEGER,UNIQUE(name,fullpath));'.format(self.ext))
self.cur.execute('CREATE INDEX IF NOT EXISTS {} ON {} ( `name`, `fullpath` )'.format(self.index,self.ext))
self.cur.execute('INSERT OR IGNORE INTO update_status VALUES (?, 0)',[self.ext])
);
self.cur.execute(
'INSERT INTO updates (ext,update_time,file_count) SELECT :ext, 0, 0 WHERE NOT EXISTS(SELECT 1 FROM updates WHERE ext = :ext AND update_time = 0 AND file_count = 0);',
{'ext':self.ext}
)
self.commit()
defupdate(self,update_mtimes):
self.cur.execute('SELECT MAX(update_time) FROM updates WHERE ext=?;',[self.ext])
last_update=self.cur.fetchone()[0]
# input(str(last_update))
_time=int(time.time())
files=_update.update(
self.ext,
config.getlist(self.ext,'paths'),
last_update,
update_mtimes
)
self.cur.executemany('INSERT OR IGNORE INTO {} VALUES (?,?,?)'.format(self.ext),(row+[_time]forrowinfiles))
self.cur.execute('INSERT INTO updates VALUES (?, ?, ?)',[self.ext,_time,len(files)])