diff --git a/LazyLibrarian.py b/LazyLibrarian.py
index 50973a2eb..646839131 100755
--- a/LazyLibrarian.py
+++ b/LazyLibrarian.py
@@ -13,6 +13,7 @@
import lazylibrarian
from lazylibrarian import webStart, logger, versioncheck, dbupgrade
+from lazylibrarian.formatter import check_int
# The following should probably be made configurable at the settings level
# This fix is put in place for systems with broken SSL (like QNAP)
@@ -167,11 +168,12 @@ def main():
# version check button will still override this if you want to
lazylibrarian.CONFIG['LATEST_VERSION'] = lazylibrarian.CONFIG['CURRENT_VERSION']
lazylibrarian.CONFIG['COMMITS_BEHIND'] = 0
-
- if not lazylibrarian.CONFIG['GIT_UPDATED']:
- if lazylibrarian.CONFIG['CURRENT_VERSION'] == lazylibrarian.CONFIG['LATEST_VERSION']:
- if lazylibrarian.CONFIG['INSTALL_TYPE'] == 'git' and lazylibrarian.CONFIG['COMMITS_BEHIND'] == 0:
- lazylibrarian.CONFIG['GIT_UPDATED'] = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime())
+ else:
+ if check_int(lazylibrarian.CONFIG['GIT_UPDATED'], 0) == 0:
+ if lazylibrarian.CONFIG['CURRENT_VERSION'] == lazylibrarian.CONFIG['LATEST_VERSION']:
+ if lazylibrarian.CONFIG['INSTALL_TYPE'] == 'git' and lazylibrarian.CONFIG['COMMITS_BEHIND'] == 0:
+ lazylibrarian.CONFIG['GIT_UPDATED'] = str(int(time.time()))
+ logger.debug('Setting update timestamp to now')
version_file = os.path.join(lazylibrarian.PROG_DIR, 'version.txt')
if not os.path.isfile(version_file) and lazylibrarian.CONFIG['INSTALL_TYPE'] == 'source':
diff --git a/data/interfaces/bookstrap/config.html b/data/interfaces/bookstrap/config.html
index 2fa565cb9..304135ef7 100644
--- a/data/interfaces/bookstrap/config.html
+++ b/data/interfaces/bookstrap/config.html
@@ -91,7 +91,7 @@
${title}
Log Level:
- 0=Quiet, 1=Normal, 2=Debug
+ 0=Errors/Warnings, 1=Normal, 2=Debug
+
+
+ Calibre Magazines Auto Add Directory:
+
+ Directory for a copy to be placed for auto add process
+
+
+ <%
+ if lazylibrarian.CONFIG['IMP_AUTOADD_MAGONLY'] == True:
+ checked = 'checked="checked"'
+ else:
+ checked = ''
+ %>
+
+
+ Only add magazine, not opf or jpg
+
+
diff --git a/lazylibrarian/__init__.py b/lazylibrarian/__init__.py
index cb0ecd17b..a566c5250 100644
--- a/lazylibrarian/__init__.py
+++ b/lazylibrarian/__init__.py
@@ -34,7 +34,7 @@
searchmag, magazinescan, bookwork, importer, grsync
from lazylibrarian.cache import fetchURL
from lazylibrarian.common import restartJobs, logHeader
-from lazylibrarian.formatter import getList, bookSeries, plural, unaccented, check_int
+from lazylibrarian.formatter import getList, bookSeries, plural, unaccented, check_int, unaccented_str
from lib.apscheduler.scheduler import Scheduler
# Transient globals NOT stored in config
@@ -153,7 +153,8 @@
'REJECT_MAXAUDIO', 'REJECT_MINAUDIO', 'NEWAUDIO_STATUS', 'TOGGLES', 'AUDIO_TAB',
'USER_ACCOUNTS', 'GR_SYNC', 'GR_SECRET', 'GR_OAUTH_TOKEN', 'GR_OAUTH_SECRET',
'GR_OWNED', 'GR_WANTED', 'GR_UNIQUE', 'GR_FOLLOW', 'GR_FOLLOWNEW', 'GOODREADS_INTERVAL',
- 'AUDIOBOOK_DEST_FILE', 'SINGLE_USER', 'FMT_SERNAME', 'FMT_SERNUM', 'FMT_SERIES']
+ 'AUDIOBOOK_DEST_FILE', 'SINGLE_USER', 'FMT_SERNAME', 'FMT_SERNUM', 'FMT_SERIES',
+ 'AUTOADDMAG', 'AUTOADD_MAGONLY']
CONFIG_DEFINITIONS = {
# Name Type Section Default
'USER_ACCOUNTS': ('bool', 'General', 0),
@@ -207,6 +208,8 @@
'IMP_MONTHLANG': ('str', 'General', ''),
'IMP_AUTOADD': ('str', 'General', ''),
'IMP_AUTOADD_BOOKONLY': ('bool', 'General', 0),
+ 'IMP_AUTOADDMAG': ('str', 'General', ''),
+ 'IMP_AUTOADD_MAGONLY': ('bool', 'General', 0),
'IMP_AUTOSEARCH': ('bool', 'General', 0),
'IMP_CALIBREDB': ('str', 'General', ''),
'CALIBRE_USE_SERVER': ('bool', 'General', 0),
@@ -223,7 +226,7 @@
'GIT_USER': ('str', 'Git', 'dobytang'),
'GIT_REPO': ('str', 'Git', 'lazylibrarian'),
'GIT_BRANCH': ('str', 'Git', 'master'),
- 'GIT_UPDATED': ('str', 'Git', ''),
+ 'GIT_UPDATED': ('int', 'Git', 0),
'INSTALL_TYPE': ('str', 'Git', ''),
'CURRENT_VERSION': ('str', 'Git', ''),
'LATEST_VERSION': ('str', 'Git', ''),
@@ -551,11 +554,13 @@ def initialize():
logger.info("Log level set to [%s]- Log Directory is [%s] - Config level is [%s]" % (
CONFIG['LOGLEVEL'], CONFIG['LOGDIR'], CFGLOGLEVEL))
if CONFIG['LOGLEVEL'] > 2:
- logger.info("Screen Log set to FULL DEBUG")
+ logger.info("Screen Log set to EXTENDED DEBUG")
elif CONFIG['LOGLEVEL'] == 2:
logger.info("Screen Log set to DEBUG")
+ elif CONFIG['LOGLEVEL'] == 1:
+ logger.info("Screen Log set to INFO")
else:
- logger.info("Screen Log set to INFO/WARN/ERROR")
+ logger.info("Screen Log set to WARN/ERROR")
config_read()
@@ -850,6 +855,14 @@ def config_write():
# if CONFIG['LOGLEVEL'] > 2:
# logger.debug("Leaving %s unchanged (%s)" % (key, value))
CONFIG[key] = value
+
+ if isinstance(value, unicode):
+ try:
+ value = value.encode(SYS_ENCODING)
+ except UnicodeError:
+ logger.debug("Unable to convert value of %s (%s) to SYS_ENCODING" % (key, repr(value)))
+ value = unaccented_str(value)
+
CFG.set(section, key.lower(), value)
# sanity check for typos...
diff --git a/lazylibrarian/bookwork.py b/lazylibrarian/bookwork.py
index cb049878c..18fd6bb01 100644
--- a/lazylibrarian/bookwork.py
+++ b/lazylibrarian/bookwork.py
@@ -308,7 +308,7 @@ def bookRename(bookid):
'$Title', exists['BookName']).replace(
'$Series', seriesInfo(bookid)).replace(
'$SerName', seriesInfo(bookid, 'Name')).replace(
- '$SerNum', seriesInfo(bookid, 'Num')).replace (
+ '$SerNum', seriesInfo(bookid, 'Num')).replace(
'$$', ' ')
new_basename = ' '.join(new_basename.split()).strip()
diff --git a/lazylibrarian/logger.py b/lazylibrarian/logger.py
index ef296438c..e988f8a51 100644
--- a/lazylibrarian/logger.py
+++ b/lazylibrarian/logger.py
@@ -111,11 +111,13 @@ def log(message, level):
def debug(message):
- lazylibrarian_log.log(message, level='DEBUG')
+ if lazylibrarian.LOGLEVEL > 1:
+ lazylibrarian_log.log(message, level='DEBUG')
def info(message):
- lazylibrarian_log.log(message, level='INFO')
+ if lazylibrarian.LOGLEVEL > 0:
+ lazylibrarian_log.log(message, level='INFO')
def warn(message):
diff --git a/lazylibrarian/postprocess.py b/lazylibrarian/postprocess.py
index fcddb7e03..ce497e28d 100644
--- a/lazylibrarian/postprocess.py
+++ b/lazylibrarian/postprocess.py
@@ -625,6 +625,9 @@ def processDir(reset=False):
# create a thumbnail cover for the new issue
create_cover(dest_file)
processMAGOPF(dest_file, book['BookID'], book['AuxInfo'], iss_id)
+ if lazylibrarian.CONFIG['IMP_AUTOADDMAG']:
+ dest_path = os.path.dirname(dest_file)
+ processAutoAdd(dest_path, booktype='mag')
# calibre or ll copied/moved the files we want, now delete source files
@@ -1028,7 +1031,7 @@ def processExtras(dest_file=None, global_name=None, bookid=None, book_type="eBoo
if match:
update_totals(match['AuthorID'])
- if book_type != 'eBook': # only do autoadd/img/opf for ebooks
+ elif book_type != 'eBook': # only do autoadd/img/opf for ebooks
return
cmd = 'SELECT AuthorName,BookID,BookName,BookDesc,BookIsbn,BookImg,BookDate,BookLang,BookPub'
@@ -1335,15 +1338,18 @@ def processDestination(pp_path=None, dest_path=None, authorname=None, bookname=N
return True, newbookfile
-def processAutoAdd(src_path=None):
+def processAutoAdd(src_path=None, booktype='book'):
# Called to copy/move the book files to an auto add directory for the likes of Calibre which can't do nested dirs
# ensure directory is unicode so we get unicode results from listdir
if isinstance(src_path, str) and hasattr(src_path, "decode"):
src_path = src_path.decode(lazylibrarian.SYS_ENCODING)
autoadddir = lazylibrarian.CONFIG['IMP_AUTOADD']
+ if booktype == 'mag':
+ autoadddir = lazylibrarian.CONFIG['IMP_AUTOADDMAG']
if not os.path.exists(autoadddir):
- logger.error('AutoAdd directory [%s] is missing or not set - cannot perform autoadd' % autoadddir)
+ logger.error('AutoAdd directory for %s [%s] is missing or not set - cannot perform autoadd' % (
+ booktype, autoadddir))
return False
# Now try and copy all the book files into a single dir.
try:
@@ -1357,7 +1363,7 @@ def processAutoAdd(src_path=None):
# ignores author/title data in opf file if there is any embedded in book
match = False
- if lazylibrarian.CONFIG['ONE_FORMAT']:
+ if booktype == 'book' and lazylibrarian.CONFIG['ONE_FORMAT']:
booktype_list = getList(lazylibrarian.CONFIG['EBOOK_TYPE'])
for booktype in booktype_list:
while not match:
@@ -1368,9 +1374,13 @@ def processAutoAdd(src_path=None):
break
copied = False
for name in names:
- if match and is_valid_booktype(name, booktype="book") and not name.endswith(match):
+ if match and is_valid_booktype(name, booktype=booktype) and not name.endswith(match):
logger.debug('Skipping %s' % os.path.splitext(name)[1])
- elif lazylibrarian.CONFIG['IMP_AUTOADD_BOOKONLY'] and not is_valid_booktype(name, booktype="book"):
+ elif booktype == 'book' and lazylibrarian.CONFIG['IMP_AUTOADD_BOOKONLY'] and not \
+ is_valid_booktype(name, booktype="book"):
+ logger.debug('Skipping %s' % name)
+ elif booktype == 'mag' and lazylibrarian.CONFIG['IMP_AUTOADD_MAGONLY'] and not \
+ is_valid_booktype(name, booktype="mag"):
logger.debug('Skipping %s' % name)
else:
srcname = os.path.join(src_path, name)
diff --git a/lazylibrarian/versioncheck.py b/lazylibrarian/versioncheck.py
index 315165d8a..e036d43a1 100644
--- a/lazylibrarian/versioncheck.py
+++ b/lazylibrarian/versioncheck.py
@@ -22,6 +22,7 @@
import tarfile
import threading
import time
+import locale
import lazylibrarian
import lib.requests as requests
@@ -29,6 +30,8 @@
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.
@@ -261,7 +264,16 @@ def getLatestVersion_FromGit():
logmsg('debug',
'(getLatestVersion_FromGit) Retrieving latest version information from github command=[%s]' % url)
- age = lazylibrarian.CONFIG['GIT_UPDATED']
+ 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)
try:
headers = {'User-Agent': USER_AGENT}
if age:
@@ -336,7 +348,6 @@ def getCommitDifferenceFromGit():
logmsg('info', '[VersionCheck] - New version is available. You are one commit behind')
elif commits == 0:
logmsg('info', '[VersionCheck] - lazylibrarian is up to date ')
- # lazylibrarian.CONFIG['GIT_UPDATED'] = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime())
elif commits < 0:
msg = '[VersionCheck] - You are running an unknown version of lazylibrarian. '
msg += 'Run the updater to identify your version'
@@ -402,13 +413,12 @@ def update():
logmsg('info', '(update) No update available, not updating')
logmsg('info', '(update) Output: ' + str(output))
success = False
- # lazylibrarian.CONFIG['GIT_UPDATED'] = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime())
elif 'Aborting' in line or 'local changes' in line:
logmsg('error', '(update) Unable to update from git: ' + line)
logmsg('info', '(update) Output: ' + str(output))
success = False
if success:
- lazylibrarian.CONFIG['GIT_UPDATED'] = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime())
+ lazylibrarian.CONFIG['GIT_UPDATED'] = str(int(time.time()))
return True
elif lazylibrarian.CONFIG['INSTALL_TYPE'] == 'source':
@@ -479,7 +489,6 @@ def update():
# Update version.txt
updateVersionFile(lazylibrarian.CONFIG['LATEST_VERSION'])
- # lazylibrarian.CONFIG['GIT_UPDATED'] = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime())
return True
else:
logmsg('error', "(update) Cannot perform update - Install Type not set")