From 89c0904ac99a72fa38907432d50154c623434a02 Mon Sep 17 00:00:00 2001 From: bodybybuddha Date: Thu, 13 Sep 2018 21:24:21 -0400 Subject: [PATCH] Fix to #625 - Check to see if target book format already exists before executing conversion. --- cps/worker.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/cps/worker.py b/cps/worker.py index a842c1de..5f231f25 100644 --- a/cps/worker.py +++ b/cps/worker.py @@ -232,10 +232,29 @@ class WorkerThread(threading.Thread): bookid = self.queue[self.current]['bookid'] format_old_ext = u'.' + self.queue[self.current]['settings']['old_book_format'].lower() format_new_ext = u'.' + self.queue[self.current]['settings']['new_book_format'].lower() + + # check to see if destination format already exists - + # if it does - mark the conversion task as complete and return a success + # this will allow send to kindle workflow to continue to work + if os.path.isfile(file_path + format_new_ext): + web.app.logger.info("Book id %d already converted to %s", bookid, format_new_ext) + cur_book = web.db.session.query(web.db.Books).filter(web.db.Books.id == bookid).first() + self.queue[self.current]['path'] = file_path + self.queue[self.current]['title'] = cur_book.title + self.queue[self.current]['status'] = STAT_FINISH_SUCCESS + self.UIqueue[self.current]['status'] = _('Finished') + self.UIqueue[self.current]['progress'] = "100 %" + self.UIqueue[self.current]['runtime'] = self._formatRuntime( + datetime.now() - self.queue[self.current]['starttime']) + return file_path + format_new_ext + else: + web.app.logger.info("Book id %d - target format of %s does not existing. Moving forward with convert.", bookid, format_new_ext) + # check if converter-executable is existing if not os.path.exists(web.ub.config.config_converterpath): self._handleError(_(u"Convertertool %(converter)s not found", converter=web.ub.config.config_converterpath)) return + try: # check which converter to use kindlegen is "1" if format_old_ext == '.epub' and format_new_ext == '.mobi':