From 33c6e72ca4a68de6766379d6b667127f2c62076b Mon Sep 17 00:00:00 2001 From: Phil Borman Date: Thu, 6 Jul 2017 11:12:13 +0200 Subject: [PATCH] Reworked debug messages --- lazylibrarian/notifiers/__init__.py | 2 +- lazylibrarian/notifiers/email_notify.py | 50 ++++++++++++------------- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/lazylibrarian/notifiers/__init__.py b/lazylibrarian/notifiers/__init__.py index 583411504..f6ed7798a 100644 --- a/lazylibrarian/notifiers/__init__.py +++ b/lazylibrarian/notifiers/__init__.py @@ -73,7 +73,7 @@ def notify_download(title, bookid=None): try: for n in notifiers: if n == 'email_notifier': - n.notify_download(title, bookid) + n.notify_download(title, bookid=bookid) else: n.notify_download(title) except Exception as e: diff --git a/lazylibrarian/notifiers/email_notify.py b/lazylibrarian/notifiers/email_notify.py index 38e32df59..339f4c57b 100644 --- a/lazylibrarian/notifiers/email_notify.py +++ b/lazylibrarian/notifiers/email_notify.py @@ -108,31 +108,30 @@ def notify_download(self, title, bookid=None, force=False): if lazylibrarian.CONFIG['EMAIL_NOTIFY_ONDOWNLOAD']: files = None event = notifyStrings[NOTIFY_DOWNLOAD] - if lazylibrarian.CONFIG['EMAIL_SENDFILE_ONDOWNLOAD'] and not bookid: - logger.debug('Requested to attach book, but no bookid') - elif bookid: - myDB = database.DBConnection() - data = myDB.match('SELECT BookFile,BookName from books where BookID=?', (bookid,)) - try: - if not data: + logger.debug('Email send attachment is %s' % lazylibrarian.CONFIG['EMAIL_SENDFILE_ONDOWNLOAD']) + if lazylibrarian.CONFIG['EMAIL_SENDFILE_ONDOWNLOAD']: + if not bookid: + logger.debug('Email request to attach book, but no bookid') + else: + myDB = database.DBConnection() + data = myDB.match('SELECT BookFile,BookName from books where BookID=?', (bookid,)) + if data: + filename = data['BookFile'] + title = data['BookName'] + logger.debug('Found %s for bookid %s' % (filename, bookid)) + else: logger.debug('[%s] is not a valid bookid' % bookid) - filename = data['BookFile'] - title = data['BookName'] - logger.debug('Found %s for bookid %s' % (filename, bookid)) - except Exception: - data = myDB.match('SELECT IssueFile,Title,IssueDate from issues where IssueID=?', (bookid,)) - try: - if not data: - logger.debug('[%s] is not a valid issueid' % bookid) - filename = data['IssueFile'] - title = "%s - %s" % (data['Title'], data['IssueDate']) - logger.debug('Found %s for issueid %s' % (filename, bookid)) - except Exception: - logger.debug("No attachment found for [%s]" % bookid) - filename = '' - if filename: - files = [filename] # could add cover_image, opf - event = "LazyLibrarian Download" + data = myDB.match('SELECT IssueFile,Title,IssueDate from issues where IssueID=?', (bookid,)) + if data: + filename = data['IssueFile'] + title = "%s - %s" % (data['Title'], data['IssueDate']) + logger.debug('Found %s for issueid %s' % (filename, bookid)) + else: + logger.debug('[%s] is not a valid bookid/issueid' % bookid) + filename = '' + if filename: + files = [filename] # could add cover_image, opf + event = "LazyLibrarian Download" return self._notify(message=title, event=event, force=force, files=files) return False @@ -143,7 +142,6 @@ def test_notify(self, title='Test'): data = myDB.match('SELECT bookid from books where bookfile <> ""') if data: return self.notify_download(title=message, bookid=data['bookid'], force=True) - - return self._notify(message=message, event=title, force=True) + return self.notify_download(title=message, bookid=None, force=True) notifier = EmailNotifier