From 7257b74cfdc863008f6e6d097fa666d4dc86c578 Mon Sep 17 00:00:00 2001 From: Phil Borman Date: Fri, 22 Dec 2017 17:37:33 +0100 Subject: [PATCH] Hard coded english names for git dates --- lazylibrarian/__init__.py | 6 ++++++ lazylibrarian/versioncheck.py | 21 ++++++++++----------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/lazylibrarian/__init__.py b/lazylibrarian/__init__.py index a566c5250..f2f2fb50b 100644 --- a/lazylibrarian/__init__.py +++ b/lazylibrarian/__init__.py @@ -639,6 +639,12 @@ def config_read(reloaded=False): ebook_dir = check_setting('str', 'General', 'destination_dir', '') CFG.set('General', 'ebook_dir', ebook_dir) CFG.remove_option('General', 'destination_dir') + # legacy type conversion + if CFG.has_option('Git', 'git_updated'): + val = CFG.get('Git', 'git_updated') + newval = check_int(val, 0) + if newval != val: + CFG.set('Git', 'git_updated', newval) # legacy name conversions, separate out host/port for provider in ['NZBGet', 'UTORRENT', 'QBITTORRENT', 'TRANSMISSION']: if not CFG.has_option(provider, '%s_port' % provider.lower()): diff --git a/lazylibrarian/versioncheck.py b/lazylibrarian/versioncheck.py index e036d43a1..4a32f8465 100644 --- a/lazylibrarian/versioncheck.py +++ b/lazylibrarian/versioncheck.py @@ -22,7 +22,6 @@ import tarfile import threading import time -import locale import lazylibrarian import lib.requests as requests @@ -30,8 +29,6 @@ from lazylibrarian.common import USER_AGENT, proxyList from lazylibrarian.formatter import check_int -LOCALE_LOCK = threading.Lock() - def logmsg(level, msg): # log messages to logger if initialised, or print if not. @@ -267,13 +264,14 @@ def getLatestVersion_FromGit(): timestamp = check_int(lazylibrarian.CONFIG['GIT_UPDATED'], 0) age = '' if timestamp: - with LOCALE_LOCK: - saved = locale.setlocale(locale.LC_ALL) - try: - locale.setlocale(locale.LC_ALL, 'C') - age = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(timestamp)) - finally: - locale.setlocale(locale.LC_ALL, saved) + # timestring for 'If-Modified-Since' needs to be english short day/month names and in gmt + # we already have english month names stored in MONTHNAMES[] but need capitalising + # so use hard coded versions here instead + DAYNAMES = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] + MONNAMES = ['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] + tm = time.gmtime(timestamp) + age = "%s, %02d %s %04d %02d:%02d:%02d GMT" %(DAYNAMES[tm.tm_wday], tm.tm_mday, + MONNAMES[tm.tm_mon], tm.tm_year, tm.tm_hour, tm.tm_min, tm.tm_sec) try: headers = {'User-Agent': USER_AGENT} if age: @@ -487,8 +485,9 @@ def update(): os.remove(new_path) os.renames(old_path, new_path) - # Update version.txt + # Update version.txt and timestamo updateVersionFile(lazylibrarian.CONFIG['LATEST_VERSION']) + lazylibrarian.CONFIG['GIT_UPDATED'] = str(int(time.time())) return True else: logmsg('error', "(update) Cannot perform update - Install Type not set")