1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-12-25 09:30:31 +00:00

logging, tmp cleanup

This commit is contained in:
Pavel Yakunin 2016-06-05 19:42:18 +03:00
parent 027e103ce3
commit 44df873f33
2 changed files with 23 additions and 13 deletions

View File

@ -1,12 +1,22 @@
__author__ = 'lemmsh' __author__ = 'lemmsh'
import logging
logger = logging.getLogger("book_formats")
import uploader import uploader
import os import os
try: try:
from wand.image import Image from wand.image import Image
use_generic_pdf_cover = False use_generic_pdf_cover = False
except ImportError, e: except ImportError, e:
logger.warning('cannot import Image, generating pdf covers for pdf uploads will not work')
use_generic_pdf_cover = True use_generic_pdf_cover = True
try:
from PyPDF2 import PdfFileReader
use_pdf_meta = True
except ImportError, e:
logger.warning('cannot import PyPDF2, extracting pdf metadata will not work')
use_pdf_meta = False
def process(tmp_file_path, original_file_name, original_file_extension): def process(tmp_file_path, original_file_name, original_file_extension):
if (".PDF" == original_file_extension.upper()): if (".PDF" == original_file_extension.upper()):
@ -15,11 +25,13 @@ def process(tmp_file_path, original_file_name, original_file_extension):
def pdf_meta(tmp_file_path, original_file_name, original_file_extension): def pdf_meta(tmp_file_path, original_file_name, original_file_extension):
from PyPDF2 import PdfFileReader
pdf = PdfFileReader(open(tmp_file_path, 'rb')) if (use_pdf_meta):
doc_info = pdf.getDocumentInfo() pdf = PdfFileReader(open(tmp_file_path, 'rb'))
print("!!!!!!!!!!!!!!") doc_info = pdf.getDocumentInfo()
print(doc_info.producer) else:
doc_info = None
if (doc_info is not None): if (doc_info is not None):
author = doc_info.author author = doc_info.author
title = doc_info.title title = doc_info.title

View File

@ -23,13 +23,7 @@ import base64
from sqlalchemy.sql import * from sqlalchemy.sql import *
import json import json
import datetime import datetime
import book_formats
from uuid import uuid4 from uuid import uuid4
try:
from wand.image import Image
use_generic_pdf_cover = False
except ImportError, e:
use_generic_pdf_cover = True
from shutil import copyfile from shutil import copyfile
app = (Flask(__name__)) app = (Flask(__name__))
@ -41,6 +35,9 @@ file_handler.setLevel(logging.INFO)
file_handler.setFormatter(formatter) file_handler.setFormatter(formatter)
app.logger.addHandler(file_handler) app.logger.addHandler(file_handler)
app.logger.info('Starting Calibre Web...') app.logger.info('Starting Calibre Web...')
logging.getLogger("book_formats").addHandler(file_handler)
logging.getLogger("book_formats").setLevel(logging.INFO)
Principal(app) Principal(app)
@ -1077,6 +1074,7 @@ def edit_book(book_id):
return render_template('edit_book.html', book=book, authors=author_names, cc=cc) return render_template('edit_book.html', book=book, authors=author_names, cc=cc)
import uploader import uploader
from shutil import move
@app.route("/upload", methods = ["GET", "POST"]) @app.route("/upload", methods = ["GET", "POST"])
@login_required @login_required
@ -1107,7 +1105,7 @@ def upload():
flash("Failed to create path %s (Permission denied)." % filepath, category="error") flash("Failed to create path %s (Permission denied)." % filepath, category="error")
return redirect(url_for('index')) return redirect(url_for('index'))
try: try:
copyfile(meta.file_path, saved_filename) #remove as well move(meta.file_path, saved_filename) #remove as well
except OSError: except OSError:
flash("Failed to store file %s (Permission denied)." % saved_filename, category="error") flash("Failed to store file %s (Permission denied)." % saved_filename, category="error")
return redirect(url_for('index')) return redirect(url_for('index'))
@ -1119,7 +1117,7 @@ def upload():
copyfile(os.path.join(basedir, "static/generic_cover.jpg"), os.path.join(filepath, "cover.jpg")) copyfile(os.path.join(basedir, "static/generic_cover.jpg"), os.path.join(filepath, "cover.jpg"))
else: else:
has_cover = 1 has_cover = 1
copyfile(meta.cover, os.path.join(filepath, "cover.jpg")) move(meta.cover, os.path.join(filepath, "cover.jpg"))
is_author = db.session.query(db.Authors).filter(db.Authors.name == author).first() is_author = db.session.query(db.Authors).filter(db.Authors.name == author).first()
if is_author: if is_author: