Skip to content

Commit

Permalink
Merge pull request #1149 from philborman/master
Browse files Browse the repository at this point in the history
Autoadd option for magazines, git change to force English locale
  • Loading branch information
philborman authored Dec 21, 2017
2 parents dfe58a0 + 8a47995 commit e0414cb
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 26 deletions.
12 changes: 7 additions & 5 deletions LazyLibrarian.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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':
Expand Down
22 changes: 20 additions & 2 deletions data/interfaces/bookstrap/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ <h1>${title}</h1>
<div class="form-group">
<label for="loglevel">Log Level:</label>
<input type="text" id="loglevel" name="loglevel" value="${lazylibrarian.LOGLEVEL}" class="form-control" placeholder="Log Level">
<span class="help-block">0=Quiet, 1=Normal, 2=Debug</span>
<span class="help-block">0=Errors/Warnings, 1=Normal, 2=Debug</span>
</div>
<div class="form-group">
<label for="displaylength">Table Display Length:</label>
Expand Down Expand Up @@ -1377,7 +1377,7 @@ <h1>${title}</h1>
</fieldset>
<fieldset>
<div class="form-group">
<label for="imp_autoadd">Calibre Auto Add Directory:</label>
<label for="imp_autoadd">Calibre Books Auto Add Directory:</label>
<input type="text" id="imp_autoadd" name="imp_autoadd" value="${lazylibrarian.CONFIG['IMP_AUTOADD']}" class="form-control">
<span class="help-block">Directory for a copy to be placed for auto add process</span>
</div>
Expand All @@ -1393,6 +1393,24 @@ <h1>${title}</h1>
Only add eBook, not opf or jpg</label>
</div>
</fieldset>
<fieldset>
<div class="form-group">
<label for="imp_autoadd">Calibre Magazines Auto Add Directory:</label>
<input type="text" id="imp_autoaddmag" name="imp_autoaddmag" value="${lazylibrarian.CONFIG['IMP_AUTOADDMAG']}" class="form-control">
<span class="help-block">Directory for a copy to be placed for auto add process</span>
</div>
<div class="checkbox">
<%
if lazylibrarian.CONFIG['IMP_AUTOADD_MAGONLY'] == True:
checked = 'checked="checked"'
else:
checked = ''
%>
<label for="imp_autoadd_magonly">
<input type="checkbox" id="imp_autoadd_magonly" name="imp_autoadd_magonly" value="1" ${checked} />
Only add magazine, not opf or jpg</label>
</div>
</fieldset>
</div>
<div class="col-md-4">
<fieldset>
Expand Down
23 changes: 18 additions & 5 deletions lazylibrarian/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand All @@ -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', ''),
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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...
Expand Down
2 changes: 1 addition & 1 deletion lazylibrarian/bookwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
6 changes: 4 additions & 2 deletions lazylibrarian/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
22 changes: 16 additions & 6 deletions lazylibrarian/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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)
Expand Down
19 changes: 14 additions & 5 deletions lazylibrarian/versioncheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@
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 @@ -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:
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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':

Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit e0414cb

Please sign in to comment.