Skip to content

Commit

Permalink
Merge pull request #1568 from philborman/master
Browse files Browse the repository at this point in the history
New cover page options, more permission messages if refused
  • Loading branch information
philborman authored Sep 20, 2018
2 parents e80a636 + 59db4d3 commit 65493e7
Show file tree
Hide file tree
Showing 13 changed files with 114 additions and 78 deletions.
3 changes: 2 additions & 1 deletion data/interfaces/bookstrap/issues.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ <h1>${title}</h1>
<select name="action" id="action" class="form-control input-sm">
<option value="Remove" selected>Remove</option>
<option value="Delete">Delete</option>
<option value="NewCover">New Cover</option>
<option value="reCover1">Cover Page 1</option>
<option value="reCover2">Cover Page 2</option>
</select>
<button type="submit" class=" btn btn-m btn-primary" onclick="validateForm()">Go</button>
%if lazylibrarian.CONFIG['TOGGLES'] == True:
Expand Down
7 changes: 4 additions & 3 deletions example_preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
def makeBytestr(txt):
# convert unicode to bytestring, needed for os.walk and os.listdir
# listdir falls over if given unicode startdir and a filename in a subdir can't be decoded to ascii
if txt is None or not txt:
if not txt:
return b''
elif not isinstance(txt, text_type): # nothing to do if already bytestring
return txt
Expand All @@ -41,7 +41,7 @@ def makeBytestr(txt):
def makeUnicode(txt):
# convert a bytestring to unicode, don't know what encoding it might be so try a few
# it could be a file on a windows filesystem, unix...
if txt is None or not txt:
if not txt:
return u''
elif isinstance(txt, text_type):
return txt
Expand Down Expand Up @@ -108,7 +108,8 @@ def makeUnicode(txt):
for ftype in wanted_formats:
if not os.path.exists(os.path.join(bookfolder, basename + ftype)):
pplog.write("No %s\n" % ftype)
params = [converter, os.path.join(bookfolder, sourcefile), os.path.join(bookfolder, basename + ftype)]
params = [converter, os.path.join(bookfolder, sourcefile),
os.path.join(bookfolder, basename + ftype)]
try:
res = subprocess.check_output(params, stderr=subprocess.STDOUT)
if created:
Expand Down
4 changes: 2 additions & 2 deletions lazylibrarian/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
'writeOPF': '&id= [&refresh] write out an opf file for a bookid, optionally overwrite existing opf',
'writeAllOPF': '[&refresh] write out opf files for all books, optionally overwrite existing opf',
'renameAudio': '&id Rename an audiobook using configured pattern',
'playlistAudio': '&id Create playlist for an audiobook',
'createPlaylist': '&id Create playlist for an audiobook',
'nameVars': '&id Show the name variables that would be used for a bookid',
'showCaps': '&provider= get a list of capabilities from a provider',
'calibreList': '[&toread=] [&read=] get a list of books in calibre library',
Expand Down Expand Up @@ -347,7 +347,7 @@ def _renameAudio(self, **kwargs):
return
self.data = audioProcess(kwargs['id'], rename=True)

def _playlistAudio(self, **kwargs):
def _createPlaylist(self, **kwargs):
if 'id' not in kwargs:
self.data = 'Missing parameter: id'
return
Expand Down
2 changes: 1 addition & 1 deletion lazylibrarian/directparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def redirect_url(genhost, url):
def GEN(book=None, prov=None, test=False):
errmsg = ''
provider = "libgen.io"
if prov is None:
if not prov:
prov = 'GEN'
host = lazylibrarian.CONFIG[prov + '_HOST']
if not host.startswith('http'):
Expand Down
4 changes: 2 additions & 2 deletions lazylibrarian/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def md5_utf8(txt):
def makeUnicode(txt):
# convert a bytestring to unicode, don't know what encoding it might be so try a few
# it could be a file on a windows filesystem, unix...
if txt is None or not txt:
if not txt:
return u''
elif isinstance(txt, text_type):
return txt
Expand All @@ -375,7 +375,7 @@ def makeUnicode(txt):
def makeBytestr(txt):
# convert unicode to bytestring, needed for os.walk and os.listdir
# listdir falls over if given unicode startdir and a filename in a subdir can't be decoded to ascii
if txt is None or not txt:
if not txt:
return b''
elif not isinstance(txt, text_type): # nothing to do if already bytestring
return txt
Expand Down
6 changes: 3 additions & 3 deletions lazylibrarian/gb.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def find_results(self, searchterm=None, queue=None):

try:
jsonresults, in_cache = gb_json_request(URL)
if jsonresults is None:
if not jsonresults:
number_results = 0
else:
if not in_cache:
Expand Down Expand Up @@ -285,7 +285,7 @@ def get_author_books(self, authorid=None, authorname=None, bookstatus="Skipped",

try:
jsonresults, in_cache = gb_json_request(URL, useCache=not refresh)
if jsonresults is None:
if not jsonresults:
number_results = 0
else:
if not in_cache:
Expand Down Expand Up @@ -620,7 +620,7 @@ def find_book(self, bookid=None, bookstatus=None, audiostatus=None):
str(bookid) + "?key=" + lazylibrarian.CONFIG['GB_API']
jsonresults, in_cache = gb_json_request(URL)

if jsonresults is None:
if not jsonresults:
logger.debug('No results found for %s' % bookid)
return

Expand Down
2 changes: 1 addition & 1 deletion lazylibrarian/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ def createMagCovers(refresh=False):
def createMagCover(issuefile=None, refresh=False, pagenum=1):
if not lazylibrarian.CONFIG['IMP_MAGCOVER'] or not pagenum:
return 'unwanted'
if issuefile is None or not os.path.isfile(issuefile):
if not issuefile or not os.path.isfile(issuefile):
logger.debug('No issuefile %s' % issuefile)
return 'failed'

Expand Down
38 changes: 37 additions & 1 deletion lazylibrarian/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,19 @@ def processDir(reset=False, startdir=None, ignoreclient=False):
except Exception as why:
logger.error("Unable to rename %s, %s %s" %
(pp_path, type(why).__name__, str(why)))
if not os.access(pp_path, os.R_OK):
logger.error("%s is not readable" % pp_path)
if not os.access(pp_path, os.W_OK):
logger.error("%s is not writeable" % pp_path)
if not os.access(pp_path, os.X_OK):
logger.error("%s is not executable" % pp_path)
parent = os.path.dirname(pp_path)
try:
with open(os.path.join(parent, 'll_temp'), 'w') as f:
f.write('test')
os.remove(os.path.join(parent, 'll_temp'))
except Exception as why:
logger.error("Directory %s is not writeable: %s" % (parent, why))
logger.warn('Residual files remain in %s' % pp_path)

ppcount += check_residual(download_dir)
Expand Down Expand Up @@ -1384,7 +1397,19 @@ def process_book(pp_path=None, bookID=None):
_ = safe_move(pp_path, pp_path + '.fail')
logger.warn('Residual files remain in %s.fail' % pp_path)
except Exception as e:
logger.error("[importBook] Unable to rename %s, %s %s" % (pp_path, type(e).__name__, str(e)))
logger.error("Unable to rename %s, %s %s" %
(pp_path, type(e).__name__, str(e)))
if not os.access(pp_path, os.R_OK):
logger.error("%s is not readable" % pp_path)
if not os.access(pp_path, os.W_OK):
logger.error("%s is not writeable" % pp_path)
parent = os.path.dirname(pp_path)
try:
with open(os.path.join(parent, 'll_temp'), 'w') as f:
f.write('test')
os.remove(os.path.join(parent, 'll_temp'))
except Exception as why:
logger.error("Directory %s is not writeable: %s" % (parent, why))
logger.warn('Residual files remain in %s' % pp_path)

was_snatched = myDB.match('SELECT NZBurl FROM wanted WHERE BookID=? and Status="Snatched"', (bookID,))
Expand Down Expand Up @@ -1660,6 +1685,17 @@ def processDestination(pp_path=None, dest_path=None, authorname=None, bookname=N
if is_valid_booktype(destfile, booktype=booktype):
newbookfile = destfile
except Exception as why:
if not os.access(srcfile, os.R_OK):
logger.error("File [%s] is not readable" % srcfile)
if not os.access(srcfile, os.W_OK):
logger.error("File [%s] is not writeable" % srcfile)
parent = os.path.dirname(destfile)
try:
with open(os.path.join(parent, 'll_temp'), 'w') as f:
f.write('test')
os.remove(os.path.join(parent, 'll_temp'))
except Exception as why:
logger.error("Directory [%s] is not writeable: %s" % (parent, why))
return False, "Unable to %s file %s to %s: %s %s" % \
(typ, srcfile, destfile, type(why).__name__, str(why))
else:
Expand Down
2 changes: 1 addition & 1 deletion lazylibrarian/resultlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def findBestResult(resultlist, book, searchtype, source):
rejected = False

url = res[prefix + 'url']
if url is None:
if not url:
rejected = True
logger.debug("Rejecting %s, no URL found" % resultTitle)

Expand Down
4 changes: 2 additions & 2 deletions lazylibrarian/searchbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def search_book(books=None, library=None):
try:
threadname = threading.currentThread().name
if "Thread-" in threadname:
if books is None:
if not books:
threading.currentThread().name = "SEARCHALLBOOKS"
else:
threading.currentThread().name = "SEARCHBOOKS"
Expand All @@ -53,7 +53,7 @@ def search_book(books=None, library=None):
searchlist = []
searchbooks = []

if books is None:
if not books:
# We are performing a backlog search
cmd = 'SELECT BookID, AuthorName, Bookname, BookSub, BookAdded, books.Status, AudioStatus '
cmd += 'from books,authors WHERE (books.Status="Wanted" OR AudioStatus="Wanted") '
Expand Down
4 changes: 2 additions & 2 deletions lazylibrarian/searchmag.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ def search_magazines(mags=None, reset=False):
try:
threadname = threading.currentThread().name
if "Thread-" in threadname:
if mags is None:
if not mags:
threading.currentThread().name = "SEARCHALLMAG"
else:
threading.currentThread().name = "SEARCHMAG"

myDB = database.DBConnection()
searchlist = []

if mags is None: # backlog search
if not mags: # backlog search
searchmags = myDB.select('SELECT Title, Regex, DateType, LastAcquired, \
IssueDate from magazines WHERE Status="Active"')
else:
Expand Down
4 changes: 2 additions & 2 deletions lazylibrarian/searchrss.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,15 @@ def search_rss_book(books=None, library=None):
try:
threadname = threading.currentThread().name
if "Thread-" in threadname:
if books is None:
if not books:
threading.currentThread().name = "SEARCHALLRSS"
else:
threading.currentThread().name = "SEARCHRSS"

myDB = database.DBConnection()

searchbooks = []
if books is None:
if not books:
# We are performing a backlog search
cmd = 'SELECT BookID, AuthorName, Bookname, BookSub, BookAdded, books.Status, AudioStatus '
cmd += 'from books,authors WHERE (books.Status="Wanted" OR AudioStatus="Wanted") '
Expand Down
112 changes: 55 additions & 57 deletions lazylibrarian/webServe.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,13 +956,13 @@ def config(self):
for mag in magazines:
title = mag['Title']
regex = mag['Regex']
if regex is None:
if not regex:
regex = ""
reject = mag['Reject']
if reject is None:
if not reject:
reject = ""
datetype = mag['DateType']
if datetype is None:
if not datetype:
datetype = ""
coverpage = check_int(mag['CoverPage'], 1)
mags_list.append({
Expand Down Expand Up @@ -1212,7 +1212,7 @@ def configUpdate(self, **kwargs):
@cherrypy.expose
def search(self, name):
self.label_thread('SEARCH')
if name is None or not name:
if not name:
raise cherrypy.HTTPRedirect("home")

myDB = database.DBConnection()
Expand Down Expand Up @@ -3289,59 +3289,57 @@ def markIssues(self, action=None, **args):
title = ''
args.pop('book_table_length', None)

for item in args:
issue = myDB.match('SELECT IssueFile,Title,IssueDate from issues WHERE IssueID=?', (item,))
if issue:
title = issue['Title']
if action == 'NewCover':
cmd = 'select coverpage from magazines where Title=?'
res = myDB.match(cmd, (title,))
if res:
createMagCover(issue['IssueFile'], refresh=True, pagenum=check_int(res['coverpage'], 1))
if action == "Delete":
result = self.deleteIssue(issue['IssueFile'])
if result:
logger.info('Issue %s of %s deleted from disc' % (issue['IssueDate'], issue['Title']))
if action == "Remove" or action == "Delete":
myDB.action('DELETE from issues WHERE IssueID=?', (item,))
logger.info('Issue %s of %s removed from database' % (issue['IssueDate'], issue['Title']))
# Set magazine_issuedate to issuedate of most recent issue we have
# Set latestcover to most recent issue cover
# Set magazine_lastacquired to acquired date of most recent issue we have
# Set magazine_added to acquired date of earliest issue we have
cmd = 'select IssueDate,IssueAcquired,IssueFile from issues where title=?'
cmd += ' order by IssueDate '
newest = myDB.match(cmd + 'DESC', (title,))
oldest = myDB.match(cmd + 'ASC', (title,))
controlValueDict = {'Title': title}
if newest and oldest:
old_acquired = ''
new_acquired = ''
cover = ''
issuefile = newest['IssueFile']
if os.path.exists(issuefile):
cover = os.path.splitext(issuefile)[0] + '.jpg'
mtime = os.path.getmtime(issuefile)
new_acquired = datetime.date.isoformat(datetime.date.fromtimestamp(mtime))
issuefile = oldest['IssueFile']
if os.path.exists(issuefile):
mtime = os.path.getmtime(issuefile)
old_acquired = datetime.date.isoformat(datetime.date.fromtimestamp(mtime))

newValueDict = {
'IssueDate': newest['IssueDate'],
'LatestCover': cover,
'LastAcquired': new_acquired,
'MagazineAdded': old_acquired
}
else:
newValueDict = {
'IssueDate': '',
'LastAcquired': '',
'LatestCover': '',
'MagazineAdded': ''
}
myDB.upsert("magazines", newValueDict, controlValueDict)
if action:
for item in args:
issue = myDB.match('SELECT IssueFile,Title,IssueDate from issues WHERE IssueID=?', (item,))
if issue:
title = issue['Title']
if 'reCover' in action:
createMagCover(issue['IssueFile'], refresh=True, pagenum=check_int(action[-1], 1))
if action == "Delete":
result = self.deleteIssue(issue['IssueFile'])
if result:
logger.info('Issue %s of %s deleted from disc' % (issue['IssueDate'], issue['Title']))
if action == "Remove" or action == "Delete":
myDB.action('DELETE from issues WHERE IssueID=?', (item,))
logger.info('Issue %s of %s removed from database' % (issue['IssueDate'], issue['Title']))
# Set magazine_issuedate to issuedate of most recent issue we have
# Set latestcover to most recent issue cover
# Set magazine_lastacquired to acquired date of most recent issue we have
# Set magazine_added to acquired date of earliest issue we have
cmd = 'select IssueDate,IssueAcquired,IssueFile from issues where title=?'
cmd += ' order by IssueDate '
newest = myDB.match(cmd + 'DESC', (title,))
oldest = myDB.match(cmd + 'ASC', (title,))
controlValueDict = {'Title': title}
if newest and oldest:
old_acquired = ''
new_acquired = ''
cover = ''
issuefile = newest['IssueFile']
if os.path.exists(issuefile):
cover = os.path.splitext(issuefile)[0] + '.jpg'
mtime = os.path.getmtime(issuefile)
new_acquired = datetime.date.isoformat(datetime.date.fromtimestamp(mtime))
issuefile = oldest['IssueFile']
if os.path.exists(issuefile):
mtime = os.path.getmtime(issuefile)
old_acquired = datetime.date.isoformat(datetime.date.fromtimestamp(mtime))

newValueDict = {
'IssueDate': newest['IssueDate'],
'LatestCover': cover,
'LastAcquired': new_acquired,
'MagazineAdded': old_acquired
}
else:
newValueDict = {
'IssueDate': '',
'LastAcquired': '',
'LatestCover': '',
'MagazineAdded': ''
}
myDB.upsert("magazines", newValueDict, controlValueDict)
if title:
raise cherrypy.HTTPRedirect("issuePage?title=%s" % quote_plus(title))
else:
Expand Down

0 comments on commit 65493e7

Please sign in to comment.