Skip to content

Commit

Permalink
Merge pull request #1151 from philborman/master
Browse files Browse the repository at this point in the history
Hard coded english names for git dates
  • Loading branch information
philborman authored Dec 22, 2017
2 parents e0414cb + 7257b74 commit fa4f5ce
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
6 changes: 6 additions & 0 deletions lazylibrarian/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()):
Expand Down
21 changes: 10 additions & 11 deletions lazylibrarian/versioncheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,13 @@
import tarfile
import threading
import time
import locale

import lazylibrarian
import lib.requests as requests
from lazylibrarian import logger, version
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.
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit fa4f5ce

Please sign in to comment.