Skip to content

Commit e0414cb

Browse files
authored
Merge pull request #1149 from philborman/master
Autoadd option for magazines, git change to force English locale
2 parents dfe58a0 + 8a47995 commit e0414cb

File tree

7 files changed

+80
-26
lines changed

7 files changed

+80
-26
lines changed

LazyLibrarian.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import lazylibrarian
1515
from lazylibrarian import webStart, logger, versioncheck, dbupgrade
16+
from lazylibrarian.formatter import check_int
1617

1718
# The following should probably be made configurable at the settings level
1819
# This fix is put in place for systems with broken SSL (like QNAP)
@@ -167,11 +168,12 @@ def main():
167168
# version check button will still override this if you want to
168169
lazylibrarian.CONFIG['LATEST_VERSION'] = lazylibrarian.CONFIG['CURRENT_VERSION']
169170
lazylibrarian.CONFIG['COMMITS_BEHIND'] = 0
170-
171-
if not lazylibrarian.CONFIG['GIT_UPDATED']:
172-
if lazylibrarian.CONFIG['CURRENT_VERSION'] == lazylibrarian.CONFIG['LATEST_VERSION']:
173-
if lazylibrarian.CONFIG['INSTALL_TYPE'] == 'git' and lazylibrarian.CONFIG['COMMITS_BEHIND'] == 0:
174-
lazylibrarian.CONFIG['GIT_UPDATED'] = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime())
171+
else:
172+
if check_int(lazylibrarian.CONFIG['GIT_UPDATED'], 0) == 0:
173+
if lazylibrarian.CONFIG['CURRENT_VERSION'] == lazylibrarian.CONFIG['LATEST_VERSION']:
174+
if lazylibrarian.CONFIG['INSTALL_TYPE'] == 'git' and lazylibrarian.CONFIG['COMMITS_BEHIND'] == 0:
175+
lazylibrarian.CONFIG['GIT_UPDATED'] = str(int(time.time()))
176+
logger.debug('Setting update timestamp to now')
175177

176178
version_file = os.path.join(lazylibrarian.PROG_DIR, 'version.txt')
177179
if not os.path.isfile(version_file) and lazylibrarian.CONFIG['INSTALL_TYPE'] == 'source':

data/interfaces/bookstrap/config.html

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ <h1>${title}</h1>
9191
<div class="form-group">
9292
<label for="loglevel">Log Level:</label>
9393
<input type="text" id="loglevel" name="loglevel" value="${lazylibrarian.LOGLEVEL}" class="form-control" placeholder="Log Level">
94-
<span class="help-block">0=Quiet, 1=Normal, 2=Debug</span>
94+
<span class="help-block">0=Errors/Warnings, 1=Normal, 2=Debug</span>
9595
</div>
9696
<div class="form-group">
9797
<label for="displaylength">Table Display Length:</label>
@@ -1377,7 +1377,7 @@ <h1>${title}</h1>
13771377
</fieldset>
13781378
<fieldset>
13791379
<div class="form-group">
1380-
<label for="imp_autoadd">Calibre Auto Add Directory:</label>
1380+
<label for="imp_autoadd">Calibre Books Auto Add Directory:</label>
13811381
<input type="text" id="imp_autoadd" name="imp_autoadd" value="${lazylibrarian.CONFIG['IMP_AUTOADD']}" class="form-control">
13821382
<span class="help-block">Directory for a copy to be placed for auto add process</span>
13831383
</div>
@@ -1393,6 +1393,24 @@ <h1>${title}</h1>
13931393
Only add eBook, not opf or jpg</label>
13941394
</div>
13951395
</fieldset>
1396+
<fieldset>
1397+
<div class="form-group">
1398+
<label for="imp_autoadd">Calibre Magazines Auto Add Directory:</label>
1399+
<input type="text" id="imp_autoaddmag" name="imp_autoaddmag" value="${lazylibrarian.CONFIG['IMP_AUTOADDMAG']}" class="form-control">
1400+
<span class="help-block">Directory for a copy to be placed for auto add process</span>
1401+
</div>
1402+
<div class="checkbox">
1403+
<%
1404+
if lazylibrarian.CONFIG['IMP_AUTOADD_MAGONLY'] == True:
1405+
checked = 'checked="checked"'
1406+
else:
1407+
checked = ''
1408+
%>
1409+
<label for="imp_autoadd_magonly">
1410+
<input type="checkbox" id="imp_autoadd_magonly" name="imp_autoadd_magonly" value="1" ${checked} />
1411+
Only add magazine, not opf or jpg</label>
1412+
</div>
1413+
</fieldset>
13961414
</div>
13971415
<div class="col-md-4">
13981416
<fieldset>

lazylibrarian/__init__.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
searchmag, magazinescan, bookwork, importer, grsync
3535
from lazylibrarian.cache import fetchURL
3636
from lazylibrarian.common import restartJobs, logHeader
37-
from lazylibrarian.formatter import getList, bookSeries, plural, unaccented, check_int
37+
from lazylibrarian.formatter import getList, bookSeries, plural, unaccented, check_int, unaccented_str
3838
from lib.apscheduler.scheduler import Scheduler
3939

4040
# Transient globals NOT stored in config
@@ -153,7 +153,8 @@
153153
'REJECT_MAXAUDIO', 'REJECT_MINAUDIO', 'NEWAUDIO_STATUS', 'TOGGLES', 'AUDIO_TAB',
154154
'USER_ACCOUNTS', 'GR_SYNC', 'GR_SECRET', 'GR_OAUTH_TOKEN', 'GR_OAUTH_SECRET',
155155
'GR_OWNED', 'GR_WANTED', 'GR_UNIQUE', 'GR_FOLLOW', 'GR_FOLLOWNEW', 'GOODREADS_INTERVAL',
156-
'AUDIOBOOK_DEST_FILE', 'SINGLE_USER', 'FMT_SERNAME', 'FMT_SERNUM', 'FMT_SERIES']
156+
'AUDIOBOOK_DEST_FILE', 'SINGLE_USER', 'FMT_SERNAME', 'FMT_SERNUM', 'FMT_SERIES',
157+
'AUTOADDMAG', 'AUTOADD_MAGONLY']
157158
CONFIG_DEFINITIONS = {
158159
# Name Type Section Default
159160
'USER_ACCOUNTS': ('bool', 'General', 0),
@@ -207,6 +208,8 @@
207208
'IMP_MONTHLANG': ('str', 'General', ''),
208209
'IMP_AUTOADD': ('str', 'General', ''),
209210
'IMP_AUTOADD_BOOKONLY': ('bool', 'General', 0),
211+
'IMP_AUTOADDMAG': ('str', 'General', ''),
212+
'IMP_AUTOADD_MAGONLY': ('bool', 'General', 0),
210213
'IMP_AUTOSEARCH': ('bool', 'General', 0),
211214
'IMP_CALIBREDB': ('str', 'General', ''),
212215
'CALIBRE_USE_SERVER': ('bool', 'General', 0),
@@ -223,7 +226,7 @@
223226
'GIT_USER': ('str', 'Git', 'dobytang'),
224227
'GIT_REPO': ('str', 'Git', 'lazylibrarian'),
225228
'GIT_BRANCH': ('str', 'Git', 'master'),
226-
'GIT_UPDATED': ('str', 'Git', ''),
229+
'GIT_UPDATED': ('int', 'Git', 0),
227230
'INSTALL_TYPE': ('str', 'Git', ''),
228231
'CURRENT_VERSION': ('str', 'Git', ''),
229232
'LATEST_VERSION': ('str', 'Git', ''),
@@ -551,11 +554,13 @@ def initialize():
551554
logger.info("Log level set to [%s]- Log Directory is [%s] - Config level is [%s]" % (
552555
CONFIG['LOGLEVEL'], CONFIG['LOGDIR'], CFGLOGLEVEL))
553556
if CONFIG['LOGLEVEL'] > 2:
554-
logger.info("Screen Log set to FULL DEBUG")
557+
logger.info("Screen Log set to EXTENDED DEBUG")
555558
elif CONFIG['LOGLEVEL'] == 2:
556559
logger.info("Screen Log set to DEBUG")
560+
elif CONFIG['LOGLEVEL'] == 1:
561+
logger.info("Screen Log set to INFO")
557562
else:
558-
logger.info("Screen Log set to INFO/WARN/ERROR")
563+
logger.info("Screen Log set to WARN/ERROR")
559564

560565
config_read()
561566

@@ -850,6 +855,14 @@ def config_write():
850855
# if CONFIG['LOGLEVEL'] > 2:
851856
# logger.debug("Leaving %s unchanged (%s)" % (key, value))
852857
CONFIG[key] = value
858+
859+
if isinstance(value, unicode):
860+
try:
861+
value = value.encode(SYS_ENCODING)
862+
except UnicodeError:
863+
logger.debug("Unable to convert value of %s (%s) to SYS_ENCODING" % (key, repr(value)))
864+
value = unaccented_str(value)
865+
853866
CFG.set(section, key.lower(), value)
854867

855868
# sanity check for typos...

lazylibrarian/bookwork.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ def bookRename(bookid):
308308
'$Title', exists['BookName']).replace(
309309
'$Series', seriesInfo(bookid)).replace(
310310
'$SerName', seriesInfo(bookid, 'Name')).replace(
311-
'$SerNum', seriesInfo(bookid, 'Num')).replace (
311+
'$SerNum', seriesInfo(bookid, 'Num')).replace(
312312
'$$', ' ')
313313
new_basename = ' '.join(new_basename.split()).strip()
314314

lazylibrarian/logger.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,13 @@ def log(message, level):
111111

112112

113113
def debug(message):
114-
lazylibrarian_log.log(message, level='DEBUG')
114+
if lazylibrarian.LOGLEVEL > 1:
115+
lazylibrarian_log.log(message, level='DEBUG')
115116

116117

117118
def info(message):
118-
lazylibrarian_log.log(message, level='INFO')
119+
if lazylibrarian.LOGLEVEL > 0:
120+
lazylibrarian_log.log(message, level='INFO')
119121

120122

121123
def warn(message):

lazylibrarian/postprocess.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,9 @@ def processDir(reset=False):
625625
# create a thumbnail cover for the new issue
626626
create_cover(dest_file)
627627
processMAGOPF(dest_file, book['BookID'], book['AuxInfo'], iss_id)
628+
if lazylibrarian.CONFIG['IMP_AUTOADDMAG']:
629+
dest_path = os.path.dirname(dest_file)
630+
processAutoAdd(dest_path, booktype='mag')
628631

629632
# calibre or ll copied/moved the files we want, now delete source files
630633

@@ -1028,7 +1031,7 @@ def processExtras(dest_file=None, global_name=None, bookid=None, book_type="eBoo
10281031
if match:
10291032
update_totals(match['AuthorID'])
10301033

1031-
if book_type != 'eBook': # only do autoadd/img/opf for ebooks
1034+
elif book_type != 'eBook': # only do autoadd/img/opf for ebooks
10321035
return
10331036

10341037
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
13351338
return True, newbookfile
13361339

13371340

1338-
def processAutoAdd(src_path=None):
1341+
def processAutoAdd(src_path=None, booktype='book'):
13391342
# Called to copy/move the book files to an auto add directory for the likes of Calibre which can't do nested dirs
13401343
# ensure directory is unicode so we get unicode results from listdir
13411344
if isinstance(src_path, str) and hasattr(src_path, "decode"):
13421345
src_path = src_path.decode(lazylibrarian.SYS_ENCODING)
13431346
autoadddir = lazylibrarian.CONFIG['IMP_AUTOADD']
1347+
if booktype == 'mag':
1348+
autoadddir = lazylibrarian.CONFIG['IMP_AUTOADDMAG']
13441349

13451350
if not os.path.exists(autoadddir):
1346-
logger.error('AutoAdd directory [%s] is missing or not set - cannot perform autoadd' % autoadddir)
1351+
logger.error('AutoAdd directory for %s [%s] is missing or not set - cannot perform autoadd' % (
1352+
booktype, autoadddir))
13471353
return False
13481354
# Now try and copy all the book files into a single dir.
13491355
try:
@@ -1357,7 +1363,7 @@ def processAutoAdd(src_path=None):
13571363
# ignores author/title data in opf file if there is any embedded in book
13581364

13591365
match = False
1360-
if lazylibrarian.CONFIG['ONE_FORMAT']:
1366+
if booktype == 'book' and lazylibrarian.CONFIG['ONE_FORMAT']:
13611367
booktype_list = getList(lazylibrarian.CONFIG['EBOOK_TYPE'])
13621368
for booktype in booktype_list:
13631369
while not match:
@@ -1368,9 +1374,13 @@ def processAutoAdd(src_path=None):
13681374
break
13691375
copied = False
13701376
for name in names:
1371-
if match and is_valid_booktype(name, booktype="book") and not name.endswith(match):
1377+
if match and is_valid_booktype(name, booktype=booktype) and not name.endswith(match):
13721378
logger.debug('Skipping %s' % os.path.splitext(name)[1])
1373-
elif lazylibrarian.CONFIG['IMP_AUTOADD_BOOKONLY'] and not is_valid_booktype(name, booktype="book"):
1379+
elif booktype == 'book' and lazylibrarian.CONFIG['IMP_AUTOADD_BOOKONLY'] and not \
1380+
is_valid_booktype(name, booktype="book"):
1381+
logger.debug('Skipping %s' % name)
1382+
elif booktype == 'mag' and lazylibrarian.CONFIG['IMP_AUTOADD_MAGONLY'] and not \
1383+
is_valid_booktype(name, booktype="mag"):
13741384
logger.debug('Skipping %s' % name)
13751385
else:
13761386
srcname = os.path.join(src_path, name)

lazylibrarian/versioncheck.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@
2222
import tarfile
2323
import threading
2424
import time
25+
import locale
2526

2627
import lazylibrarian
2728
import lib.requests as requests
2829
from lazylibrarian import logger, version
2930
from lazylibrarian.common import USER_AGENT, proxyList
3031
from lazylibrarian.formatter import check_int
3132

33+
LOCALE_LOCK = threading.Lock()
34+
3235

3336
def logmsg(level, msg):
3437
# log messages to logger if initialised, or print if not.
@@ -261,7 +264,16 @@ def getLatestVersion_FromGit():
261264
logmsg('debug',
262265
'(getLatestVersion_FromGit) Retrieving latest version information from github command=[%s]' % url)
263266

264-
age = lazylibrarian.CONFIG['GIT_UPDATED']
267+
timestamp = check_int(lazylibrarian.CONFIG['GIT_UPDATED'], 0)
268+
age = ''
269+
if timestamp:
270+
with LOCALE_LOCK:
271+
saved = locale.setlocale(locale.LC_ALL)
272+
try:
273+
locale.setlocale(locale.LC_ALL, 'C')
274+
age = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(timestamp))
275+
finally:
276+
locale.setlocale(locale.LC_ALL, saved)
265277
try:
266278
headers = {'User-Agent': USER_AGENT}
267279
if age:
@@ -336,7 +348,6 @@ def getCommitDifferenceFromGit():
336348
logmsg('info', '[VersionCheck] - New version is available. You are one commit behind')
337349
elif commits == 0:
338350
logmsg('info', '[VersionCheck] - lazylibrarian is up to date ')
339-
# lazylibrarian.CONFIG['GIT_UPDATED'] = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime())
340351
elif commits < 0:
341352
msg = '[VersionCheck] - You are running an unknown version of lazylibrarian. '
342353
msg += 'Run the updater to identify your version'
@@ -402,13 +413,12 @@ def update():
402413
logmsg('info', '(update) No update available, not updating')
403414
logmsg('info', '(update) Output: ' + str(output))
404415
success = False
405-
# lazylibrarian.CONFIG['GIT_UPDATED'] = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime())
406416
elif 'Aborting' in line or 'local changes' in line:
407417
logmsg('error', '(update) Unable to update from git: ' + line)
408418
logmsg('info', '(update) Output: ' + str(output))
409419
success = False
410420
if success:
411-
lazylibrarian.CONFIG['GIT_UPDATED'] = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime())
421+
lazylibrarian.CONFIG['GIT_UPDATED'] = str(int(time.time()))
412422
return True
413423
elif lazylibrarian.CONFIG['INSTALL_TYPE'] == 'source':
414424

@@ -479,7 +489,6 @@ def update():
479489

480490
# Update version.txt
481491
updateVersionFile(lazylibrarian.CONFIG['LATEST_VERSION'])
482-
# lazylibrarian.CONFIG['GIT_UPDATED'] = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime())
483492
return True
484493
else:
485494
logmsg('error', "(update) Cannot perform update - Install Type not set")

0 commit comments

Comments
 (0)