|
|
|
@ -7,6 +7,7 @@ import os.path as osp |
|
|
|
import sqlite3 |
|
|
|
import subprocess |
|
|
|
import time |
|
|
|
import traceback |
|
|
|
|
|
|
|
FORCE_ADMIN = not config.getboolean('global','no_admin',fallback=False) |
|
|
|
TEST = True |
|
|
|
@ -14,7 +15,7 @@ DB_PATH = config.getpath('global','db_path') |
|
|
|
ext_database = sqlite3.connect(DB_PATH) |
|
|
|
|
|
|
|
|
|
|
|
EXE_PATH = config.getpath('global',modified_time_updater) |
|
|
|
EXE_PATH = config.getpath('global','modified_time_updater') |
|
|
|
|
|
|
|
def update_mtimes(starts): |
|
|
|
if not is_admin() and FORCE_ADMIN: |
|
|
|
@ -25,7 +26,6 @@ def update_mtimes(starts): |
|
|
|
def build(after,starts): |
|
|
|
if isinstance(after,datetime.datetime): |
|
|
|
after = after.timestamp() |
|
|
|
starts = map(osp.expandvars,starts) |
|
|
|
starts = map(lambda item: item.replace('"','').replace("'",''),starts) |
|
|
|
for path in starts: |
|
|
|
for root,dirs,files in os.walk(path,topdown=True): |
|
|
|
@ -54,16 +54,17 @@ def set_updating(ext,con,updating=True): |
|
|
|
status = 1 |
|
|
|
else: |
|
|
|
status = 0 |
|
|
|
cur.execute('UPDATE update_status SET status=? WHERE ext=?;'[self.ext,self.status]) |
|
|
|
cur.execute('UPDATE update_status SET status=? WHERE ext=?;',[status,ext]) |
|
|
|
con.commit() |
|
|
|
|
|
|
|
def get_updating(ext,cur): |
|
|
|
cur.execute('SELECT status FROM update_status WHERE ext=?;',[self.ext]) |
|
|
|
return cur.fetchone()[0][0] == 1 |
|
|
|
cur.execute('SELECT status FROM update_status WHERE ext=?;',[ext]) |
|
|
|
return cur.fetchone()[0] == 1 |
|
|
|
|
|
|
|
def update(ext,update_mtimes): |
|
|
|
def update(ext,do_update_mtimes): |
|
|
|
set_updating(ext,ext_database) |
|
|
|
cur = ext_database.cursor() |
|
|
|
c = config.getint('global','commit_interval',fallback = 30) |
|
|
|
try: |
|
|
|
cur.execute('SELECT MAX(update_time) FROM updates WHERE ext=?;',[ext]) |
|
|
|
last_update = cur.fetchone()[0] |
|
|
|
@ -71,25 +72,29 @@ def update(ext,update_mtimes): |
|
|
|
|
|
|
|
params = ( |
|
|
|
'.'+ext, |
|
|
|
ext_databasefig.getlist(ext,'paths'), |
|
|
|
config.getpaths(ext,'paths'), |
|
|
|
last_update, |
|
|
|
update_mtimes |
|
|
|
do_update_mtimes |
|
|
|
) |
|
|
|
|
|
|
|
files = list(_update(*params)) |
|
|
|
files = _update(*params) |
|
|
|
count = 0 |
|
|
|
|
|
|
|
for count,row in enumerate(files): |
|
|
|
row.append(_time) |
|
|
|
cur.execute('INSERT OR IGNORE INTO {} VALUES (?,?,?);'.format(ext),row) |
|
|
|
if (count+1) % 30 == 0: |
|
|
|
count += 1 |
|
|
|
if count % c == 0: |
|
|
|
ext_database.commit() |
|
|
|
|
|
|
|
cur.execute('INSERT INTO updates VALUES (?, ?, ?);',[ext,_time,count+1]) |
|
|
|
ext_database.commit() |
|
|
|
set_updating(ext,ext_database,False) |
|
|
|
|
|
|
|
except Exception as e: |
|
|
|
set_updating(ext,ext_database,False) |
|
|
|
traceback.print_exc() |
|
|
|
input() |
|
|
|
raise e |
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
@ -97,4 +102,5 @@ if __name__ == "__main__": |
|
|
|
parser.add_argument('ext') |
|
|
|
parser.add_argument('-m','--update-modified-time',action='store_true') |
|
|
|
args = parser.parse_args() |
|
|
|
print(args) |
|
|
|
update(args.ext,args.update_modified_time) |