From 89b288bf5f21017d0e018c6d84703b77aec55c40 Mon Sep 17 00:00:00 2001 From: Phil Borman Date: Wed, 20 Dec 2017 12:16:41 +0100 Subject: [PATCH 1/4] Loglevel changes --- data/interfaces/bookstrap/config.html | 2 +- lazylibrarian/__init__.py | 6 ++++-- lazylibrarian/logger.py | 6 ++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/data/interfaces/bookstrap/config.html b/data/interfaces/bookstrap/config.html index 2fa565cb9..65f4bebfc 100644 --- a/data/interfaces/bookstrap/config.html +++ b/data/interfaces/bookstrap/config.html @@ -91,7 +91,7 @@

${title}

- 0=Quiet, 1=Normal, 2=Debug + 0=Errors/Warnings, 1=Normal, 2=Debug
diff --git a/lazylibrarian/__init__.py b/lazylibrarian/__init__.py index cb0ecd17b..3cac9a247 100644 --- a/lazylibrarian/__init__.py +++ b/lazylibrarian/__init__.py @@ -551,11 +551,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() 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): From d592e61a650df678d38c3f1f8a36bdba621b8178 Mon Sep 17 00:00:00 2001 From: Phil Borman Date: Wed, 20 Dec 2017 12:23:53 +0100 Subject: [PATCH 2/4] Code tidying --- lazylibrarian/bookwork.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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() From 139d5e1bdf3e5b2ef19e7acb61c50bdee29e69f4 Mon Sep 17 00:00:00 2001 From: Phil Borman Date: Thu, 21 Dec 2017 18:37:36 +0100 Subject: [PATCH 3/4] GIT_UPDATED changed to timestamp, use english locale to talk to git --- LazyLibrarian.py | 12 +++++++----- lazylibrarian/__init__.py | 12 ++++++++++-- lazylibrarian/versioncheck.py | 19 ++++++++++++++----- 3 files changed, 31 insertions(+), 12 deletions(-) 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/lazylibrarian/__init__.py b/lazylibrarian/__init__.py index 3cac9a247..652e8acba 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 @@ -223,7 +223,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', ''), @@ -852,6 +852,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/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") From 8a479956d89306e7c74c9fc597eb6ffdb37746bd Mon Sep 17 00:00:00 2001 From: Phil Borman Date: Thu, 21 Dec 2017 19:46:19 +0100 Subject: [PATCH 4/4] AutoAdd directory for magazines --- data/interfaces/bookstrap/config.html | 20 +++++++++++++++++++- lazylibrarian/__init__.py | 5 ++++- lazylibrarian/postprocess.py | 22 ++++++++++++++++------ 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/data/interfaces/bookstrap/config.html b/data/interfaces/bookstrap/config.html index 65f4bebfc..304135ef7 100644 --- a/data/interfaces/bookstrap/config.html +++ b/data/interfaces/bookstrap/config.html @@ -1377,7 +1377,7 @@

${title}

- + Directory for a copy to be placed for auto add process
@@ -1393,6 +1393,24 @@

${title}

Only add eBook, not opf or jpg
+
+
+ + + Directory for a copy to be placed for auto add process +
+
+ <% + if lazylibrarian.CONFIG['IMP_AUTOADD_MAGONLY'] == True: + checked = 'checked="checked"' + else: + checked = '' + %> + +
+
diff --git a/lazylibrarian/__init__.py b/lazylibrarian/__init__.py index 652e8acba..a566c5250 100644 --- a/lazylibrarian/__init__.py +++ b/lazylibrarian/__init__.py @@ -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), 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)