Implement update interval for downloading metadata source plugins

This commit is contained in:
Kovid Goyal 2017-02-28 10:35:39 +05:30
parent e0f1fa9206
commit 889ec6e491
2 changed files with 8 additions and 3 deletions

View File

@ -57,6 +57,8 @@ def update_plugin(name):
def main(report_error, report_action=prints):
try:
if time.time() - cache.mtime() < UPDATE_INTERVAL:
return
try:
report_action('Fetching metadata source hashes...')
needed = update_needed()
@ -78,9 +80,6 @@ def main(report_error, report_action=prints):
def update_sources(wait_for_completion=False):
if update_sources.worker is not None:
return False
epoch = cache.get('last_update', 0)
if time.time() - epoch < UPDATE_INTERVAL:
return False
update_sources.errors = errs = []
update_sources.worker = t = Thread(
target=main, args=(errs.append, debug_print), name='MSourcesUpdater')

View File

@ -286,6 +286,12 @@ class XMLConfig(dict):
self.refresh()
def mtime(self):
try:
return os.path.getmtime(self.file_path)
except EnvironmentError:
return 0
def raw_to_object(self, raw):
return plistlib.readPlistFromString(raw)