diff --git a/cps/helper.py b/cps/helper.py index db9526b3..704d0bb1 100755 --- a/cps/helper.py +++ b/cps/helper.py @@ -3,6 +3,7 @@ from cps import db, ub from cps import config +from flask import current_app as app import smtplib import sys @@ -29,19 +30,17 @@ def update_download(book_id, user_id): def make_mobi(book_id): kindlegen = os.path.join(config.MAIN_DIR, "vendor", "kindlegen") if not os.path.exists(kindlegen): - print "make_mobie: kindlegen binary not found in: %s" % kindlegen + app.logger.error("make_mobi: kindlegen binary not found in: %s" % kindlegen) return None book = db.session.query(db.Books).filter(db.Books.id == book_id).first() data = db.session.query(db.Data).filter(db.Data.book == book.id).filter(db.Data.format == 'EPUB').first() if not data: - print "make_mobie: epub format not found for book id: %d" % book_id + app.logger.error("make_mobi: epub format not found for book id: %d" % book_id) return None file_path = os.path.join(config.DB_ROOT, book.path, data.name) - # print os.path.getsize(file_path + ".epub") if os.path.exists(file_path + ".epub"): - # print u"conversion started for %s" % book.title check = subprocess.call([kindlegen, file_path + ".epub"], stdout=subprocess.PIPE) if not check or check < 2: book.data.append(db.Data( @@ -53,15 +52,14 @@ def make_mobi(book_id): db.session.commit() return file_path + ".mobi" else: - print "make_mobie: kindlegen failed to convert book" + app.logger.error("make_mobi: kindlegen failed with error while converting book") return None else: - print "make_mobie: epub not found: " + file_path + ".epub" + app.logger.error("make_mobie: epub not found: %s.epub" % file_path) return None def send_mail(book_id, kindle_mail): '''Send email with attachments''' - is_mobi = False is_azw = False is_azw3 = False @@ -73,14 +71,12 @@ def send_mail(book_id, kindle_mail): msg = MIMEMultipart() msg['From'] = settings["mail_from"] msg['To'] = kindle_mail - msg['Subject'] = 'Sent to Kindle' + msg['Subject'] = 'Send to Kindle' text = 'This email has been sent via calibre web.' msg.attach(MIMEText(text)) use_ssl = settings.get('mail_use_ssl', 0) - print "use ssl: %d" % use_ssl - # attach files #msg.attach(self.get_attachment(file_path)) @@ -92,24 +88,15 @@ def send_mail(book_id, kindle_mail): for entry in data: if entry.format == "MOBI": formats["mobi"] = os.path.join(config.DB_ROOT, book.path, entry.name + ".mobi") - if entry.format == "AZW": - formats["azw"] = os.path.join(config.DB_ROOT, book.path, entry.name + ".azw") - if entry.format == "AZW3": - formats["azw3"] = os.path.join(config.DB_ROOT, book.path, entry.name + ".azw3") if entry.format == "EPUB": formats["epub"] = os.path.join(config.DB_ROOT, book.path, entry.name + ".epub") if entry.format == "PDF": formats["pdf"] = os.path.join(config.DB_ROOT, book.path, entry.name + ".pdf") if len(formats) == 0: - print "no formats found" - return "Could not find any formats that can be send by email" - - if 'azw3' in formats: - msg.attach(get_attachment(formats['azw3'])) - elif 'azw' in formats: - msg.attach(get_attachment(formats['azw'])) - elif 'mobi' in formats: + return "Could not find any formats suitable for sending by email" + + if 'mobi' in formats: msg.attach(get_attachment(formats['mobi'])) elif 'epub' in formats: filepath = make_mobi(book.id) @@ -120,7 +107,7 @@ def send_mail(book_id, kindle_mail): elif 'pdf' in formats: msg.attach(get_attachment(formats['pdf'])) else: - return "Could not find any formats that can be send by email" + return "Could not find any formats suitable for sending by email" # convert MIME message to string fp = StringIO() @@ -141,9 +128,9 @@ def send_mail(book_id, kindle_mail): mailserver.login(settings["mail_login"], settings["mail_password"]) mailserver.sendmail(settings["mail_login"], kindle_mail, msg) mailserver.quit() - except smtplib.SMTPException: - traceback.print_exc() - return "Error communicating with the mail server, please check the logs for details." + except (socket.error, smtplib.SMTPRecipientsRefused, smtplib.SMTPException), e: + app.logger.error(traceback.print_exc()) + return "Failed to send mail: %s" % str(e) return None diff --git a/cps/static/css/style.css b/cps/static/css/style.css index 46e872b3..52e2f1e4 100644 --- a/cps/static/css/style.css +++ b/cps/static/css/style.css @@ -8,9 +8,9 @@ a{color: #45b29d}a:hover{color: #444;} .container-fluid img{display:block;max-width:100%;height:auto} .container-fluid .discover{margin-bottom:50px} .container-fluid .new-books{border-top:1px solid #ccc}.container-fluid .new-books h2{margin:50px 0 0 0} -.container-fluid .book{margin-top:20px}.container-fluid .book .cover{height:225px;position:relative}.container-fluid .book .cover img{border:1px solid #ccc;border-radius:5px;box-sizeing:border-box;height:100%;bottom:0;position:absolute} +.container-fluid .book{margin-top:20px}.container-fluid .book .cover{height:225px;position:relative}.container-fluid .book .cover img{border:3px solid #fff;border-radius:5px;box-sizeing:border-box;height:100%;bottom:0;position:absolute;-webkit-box-shadow: 0 5px 8px -6px #777;-moz-box-shadow: 0 5px 8px -6px #777;box-shadow: 0 5px 8px -6px #777;} .container-fluid .book .meta{margin-top:10px}.container-fluid .book .meta p{margin:0} -.container-fluid .book .meta .title{font-weight:bold;font-size:16px;color:#444} +.container-fluid .book .meta .title{font-weight:bold;font-size:15px;color:#444} .container-fluid .book .meta .author{font-size:12px;color:#999} .container-fluid .book .meta .rating{margin-top:5px}.rating .glyphicon-star{color:#999}.rating .glyphicon-star.good{color:#45b29d} .navbar-brand{font-family: 'Grand Hotel', cursive; font-size: 35px; color: #45b29d !important;} @@ -20,3 +20,11 @@ a{color: #45b29d}a:hover{color: #444;} span.glyphicon.glyphicon-tags {padding-right: 5px;color: #999;vertical-align: text-top;} .book-meta {padding-bottom: 20px;} .book-meta .tags a {display: inline;} +.container-fluid .single .cover img { + border: 3px solid #fff; + border-radius: 5px; + box-sizeing: border-box; + -webkit-box-shadow: 0 5px 8px -6px #777; + -moz-box-shadow: 0 5px 8px -6px #777; + box-shadow: 0 5px 8px -6px #777; +} \ No newline at end of file diff --git a/cps/templates/detail.html b/cps/templates/detail.html index 0a735db9..316ab098 100644 --- a/cps/templates/detail.html +++ b/cps/templates/detail.html @@ -126,7 +126,6 @@ {% endif %} {% if g.user.roleĀ %} -