From e05174a55ed01a9b01b131021560a1f0c68ce0a1 Mon Sep 17 00:00:00 2001 From: Phil Borman Date: Wed, 19 Sep 2018 18:48:55 +0200 Subject: [PATCH 1/4] Tidied is None to boolean empty value --- example_preprocessor.py | 7 ++++--- lazylibrarian/directparser.py | 2 +- lazylibrarian/formatter.py | 4 ++-- lazylibrarian/gb.py | 6 +++--- lazylibrarian/images.py | 2 +- lazylibrarian/resultlist.py | 2 +- lazylibrarian/searchbook.py | 4 ++-- lazylibrarian/searchmag.py | 4 ++-- lazylibrarian/searchrss.py | 4 ++-- 9 files changed, 18 insertions(+), 17 deletions(-) diff --git a/example_preprocessor.py b/example_preprocessor.py index 5c0b200cb..dec339932 100755 --- a/example_preprocessor.py +++ b/example_preprocessor.py @@ -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 @@ -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 @@ -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: diff --git a/lazylibrarian/directparser.py b/lazylibrarian/directparser.py index dbdc9666d..e19af089b 100644 --- a/lazylibrarian/directparser.py +++ b/lazylibrarian/directparser.py @@ -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'): diff --git a/lazylibrarian/formatter.py b/lazylibrarian/formatter.py index a792f63ae..d29ec802f 100644 --- a/lazylibrarian/formatter.py +++ b/lazylibrarian/formatter.py @@ -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 @@ -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 diff --git a/lazylibrarian/gb.py b/lazylibrarian/gb.py index ce4905d32..53e124a5c 100644 --- a/lazylibrarian/gb.py +++ b/lazylibrarian/gb.py @@ -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: @@ -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: @@ -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 diff --git a/lazylibrarian/images.py b/lazylibrarian/images.py index 6d45f48c4..a7c64ae56 100644 --- a/lazylibrarian/images.py +++ b/lazylibrarian/images.py @@ -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' diff --git a/lazylibrarian/resultlist.py b/lazylibrarian/resultlist.py index be7341524..0e16986c9 100644 --- a/lazylibrarian/resultlist.py +++ b/lazylibrarian/resultlist.py @@ -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) diff --git a/lazylibrarian/searchbook.py b/lazylibrarian/searchbook.py index 9552cf9c7..53a5296b1 100644 --- a/lazylibrarian/searchbook.py +++ b/lazylibrarian/searchbook.py @@ -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" @@ -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") ' diff --git a/lazylibrarian/searchmag.py b/lazylibrarian/searchmag.py index f7f52e750..0bd855958 100644 --- a/lazylibrarian/searchmag.py +++ b/lazylibrarian/searchmag.py @@ -40,7 +40,7 @@ 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" @@ -48,7 +48,7 @@ def search_magazines(mags=None, reset=False): 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: diff --git a/lazylibrarian/searchrss.py b/lazylibrarian/searchrss.py index fe9a72e36..7e296cb3b 100644 --- a/lazylibrarian/searchrss.py +++ b/lazylibrarian/searchrss.py @@ -161,7 +161,7 @@ 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" @@ -169,7 +169,7 @@ def search_rss_book(books=None, library=None): 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") ' From cbc84ff0130ac36632ba72bfdc8032160aa230be Mon Sep 17 00:00:00 2001 From: Phil Borman Date: Wed, 19 Sep 2018 18:51:08 +0200 Subject: [PATCH 2/4] Renamed createPlaylist --- lazylibrarian/api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lazylibrarian/api.py b/lazylibrarian/api.py index 744076252..ff6096f11 100644 --- a/lazylibrarian/api.py +++ b/lazylibrarian/api.py @@ -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', @@ -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 From 382511e0114fd245113ae9003a00b740b3b9f67c Mon Sep 17 00:00:00 2001 From: Phil Borman Date: Thu, 20 Sep 2018 09:15:41 +0200 Subject: [PATCH 3/4] More info if copy/move permission errors --- lazylibrarian/postprocess.py | 38 +++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/lazylibrarian/postprocess.py b/lazylibrarian/postprocess.py index fc9902aed..796879bde 100644 --- a/lazylibrarian/postprocess.py +++ b/lazylibrarian/postprocess.py @@ -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) @@ -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,)) @@ -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: From 59db4d3ef861fdd1630a872f97db1a7e252cdcb5 Mon Sep 17 00:00:00 2001 From: Phil Borman Date: Thu, 20 Sep 2018 09:16:35 +0200 Subject: [PATCH 4/4] Issue dropdown generate cover from pages 1 or 2 --- data/interfaces/bookstrap/issues.html | 3 +- lazylibrarian/webServe.py | 112 +++++++++++++------------- 2 files changed, 57 insertions(+), 58 deletions(-) diff --git a/data/interfaces/bookstrap/issues.html b/data/interfaces/bookstrap/issues.html index a5620da35..dbd75bfad 100644 --- a/data/interfaces/bookstrap/issues.html +++ b/data/interfaces/bookstrap/issues.html @@ -29,7 +29,8 @@

${title}

%if lazylibrarian.CONFIG['TOGGLES'] == True: diff --git a/lazylibrarian/webServe.py b/lazylibrarian/webServe.py index 2e012f35f..bbcb38e4e 100644 --- a/lazylibrarian/webServe.py +++ b/lazylibrarian/webServe.py @@ -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({ @@ -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() @@ -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: