mirror of
https://github.com/janeczku/calibre-web
synced 2024-12-25 17:40:31 +00:00
Merge branch 'fix/syntax-python3-20170305' into travis
This commit is contained in:
commit
da8d0c2a9f
4
cps.py
4
cps.py
@ -6,7 +6,9 @@ import sys
|
||||
|
||||
base_path = os.path.dirname(os.path.abspath(__file__))
|
||||
# Insert local directories into path
|
||||
sys.path.insert(0, os.path.join(base_path, 'vendor'))
|
||||
sys.path.append(base_path)
|
||||
sys.path.append(os.path.join(base_path, 'cps'))
|
||||
sys.path.append(os.path.join(base_path, 'vendor'))
|
||||
|
||||
from cps import web
|
||||
from tornado.wsgi import WSGIContainer
|
||||
|
@ -14,28 +14,28 @@ try:
|
||||
from wand.image import Image
|
||||
from wand import version as ImageVersion
|
||||
use_generic_pdf_cover = False
|
||||
except ImportError, e:
|
||||
except ImportError as e:
|
||||
logger.warning('cannot import Image, generating pdf covers for pdf uploads will not work: %s', e)
|
||||
use_generic_pdf_cover = True
|
||||
try:
|
||||
from PyPDF2 import PdfFileReader
|
||||
from PyPDF2 import __version__ as PyPdfVersion
|
||||
use_pdf_meta = True
|
||||
except ImportError, e:
|
||||
except ImportError as e:
|
||||
logger.warning('cannot import PyPDF2, extracting pdf metadata will not work: %s', e)
|
||||
use_pdf_meta = False
|
||||
|
||||
try:
|
||||
import epub
|
||||
use_epub_meta = True
|
||||
except ImportError, e:
|
||||
except ImportError as e:
|
||||
logger.warning('cannot import epub, extracting epub metadata will not work: %s', e)
|
||||
use_epub_meta = False
|
||||
|
||||
try:
|
||||
import fb2
|
||||
use_fb2_meta = True
|
||||
except ImportError, e:
|
||||
except ImportError as e:
|
||||
logger.warning('cannot import fb2, extracting fb2 metadata will not work: %s', e)
|
||||
use_fb2_meta = False
|
||||
|
||||
@ -48,7 +48,7 @@ def process(tmp_file_path, original_file_name, original_file_extension):
|
||||
return epub.get_epub_info(tmp_file_path, original_file_name, original_file_extension)
|
||||
if ".FB2" == original_file_extension.upper() and use_fb2_meta is True:
|
||||
return fb2.get_fb2_info(tmp_file_path, original_file_extension)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
logger.warning('cannot parse metadata, using default: %s', e)
|
||||
return default_meta(tmp_file_path, original_file_name, original_file_extension)
|
||||
|
||||
|
@ -294,7 +294,8 @@ def setup_db():
|
||||
return False
|
||||
|
||||
dbpath = os.path.join(config.config_calibre_dir, "metadata.db")
|
||||
engine = create_engine('sqlite:///{0}'.format(dbpath.encode('utf-8')), echo=False, isolation_level="SERIALIZABLE")
|
||||
#engine = create_engine('sqlite:///{0}'.format(dbpath.encode('utf-8')), echo=False, isolation_level="SERIALIZABLE")
|
||||
engine = create_engine('sqlite:///'+ dbpath, echo=False, isolation_level="SERIALIZABLE")
|
||||
try:
|
||||
conn = engine.connect()
|
||||
|
||||
|
@ -37,16 +37,16 @@ def get_fb2_info(tmp_file_path, original_file_extension):
|
||||
first_name = u''
|
||||
return first_name + ' ' + middle_name + ' ' + last_name
|
||||
|
||||
author = unicode(", ".join(map(get_author, authors)))
|
||||
author = str(", ".join(map(get_author, authors)))
|
||||
|
||||
title = tree.xpath('/fb:FictionBook/fb:description/fb:title-info/fb:book-title/text()', namespaces=ns)
|
||||
if len(title):
|
||||
title = unicode(title[0])
|
||||
title = str(title[0])
|
||||
else:
|
||||
title = u''
|
||||
description = tree.xpath('/fb:FictionBook/fb:description/fb:publish-info/fb:book-name/text()', namespaces=ns)
|
||||
if len(description):
|
||||
description = unicode(description[0])
|
||||
description = str(description[0])
|
||||
else:
|
||||
description = u''
|
||||
|
||||
|
@ -13,11 +13,17 @@ import os
|
||||
import traceback
|
||||
import re
|
||||
import unicodedata
|
||||
try:
|
||||
from StringIO import StringIO
|
||||
from email import encoders
|
||||
from email.MIMEBase import MIMEBase
|
||||
from email.MIMEMultipart import MIMEMultipart
|
||||
from email.MIMEText import MIMEText
|
||||
except ImportError:
|
||||
from io import StringIO
|
||||
from email.mime.base import MIMEBase
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.text import MIMEText
|
||||
from email import encoders
|
||||
from email.generator import Generator
|
||||
from email.utils import formatdate
|
||||
from email.utils import make_msgid
|
||||
@ -147,7 +153,7 @@ def send_raw_email(kindle_mail, msg):
|
||||
|
||||
smtplib.stderr = org_stderr
|
||||
|
||||
except (socket.error, smtplib.SMTPRecipientsRefused, smtplib.SMTPException), e:
|
||||
except (socket.error, smtplib.SMTPRecipientsRefused, smtplib.SMTPException) as e:
|
||||
app.logger.error(traceback.print_exc())
|
||||
return _("Failed to send mail: %s" % str(e))
|
||||
|
||||
@ -239,7 +245,7 @@ def get_valid_filename(value, replace_whitespace=True):
|
||||
value=value.replace(u'ß',u'ss')
|
||||
value = unicodedata.normalize('NFKD', value)
|
||||
re_slugify = re.compile('[\W\s-]', re.UNICODE)
|
||||
value = unicode(re_slugify.sub('', value).strip())
|
||||
value = str(re_slugify.sub('', value).strip())
|
||||
if replace_whitespace:
|
||||
#*+:\"/<>? werden durch _ ersetzt
|
||||
value = re.sub('[\*\+:\\\"/<>\?]+', u'_', value, flags=re.U)
|
||||
|
@ -10,6 +10,7 @@ import os
|
||||
import logging
|
||||
from werkzeug.security import generate_password_hash
|
||||
from flask_babel import gettext as _
|
||||
from builtins import str
|
||||
|
||||
dbpath = os.path.join(os.path.normpath(os.path.dirname(os.path.realpath(__file__)) + os.sep + ".." + os.sep), "app.db")
|
||||
engine = create_engine('sqlite:///{0}'.format(dbpath), echo=False)
|
||||
@ -90,7 +91,7 @@ class UserBase:
|
||||
return False
|
||||
|
||||
def get_id(self):
|
||||
return unicode(self.id)
|
||||
return str(self.id)
|
||||
|
||||
def filter_language(self):
|
||||
return self.default_language
|
||||
|
19
cps/web.py
19
cps/web.py
@ -47,12 +47,19 @@ import db
|
||||
from shutil import move, copyfile
|
||||
from tornado.ioloop import IOLoop
|
||||
from tornado import version as tornadoVersion
|
||||
from builtins import str
|
||||
|
||||
try:
|
||||
from imp import reload
|
||||
from past.builtins import xrange
|
||||
except:
|
||||
pass
|
||||
|
||||
try:
|
||||
from wand.image import Image
|
||||
|
||||
use_generic_pdf_cover = False
|
||||
except ImportError, e:
|
||||
except ImportError as e:
|
||||
use_generic_pdf_cover = True
|
||||
from cgi import escape
|
||||
|
||||
@ -1044,8 +1051,8 @@ def stats():
|
||||
stdin=subprocess.PIPE)
|
||||
p.wait()
|
||||
for lines in p.stdout.readlines():
|
||||
if re.search('Amazon kindlegen\(', lines):
|
||||
versions['KindlegenVersion'] = lines
|
||||
if re.search('Amazon kindlegen\(', str(lines)):
|
||||
versions['KindlegenVersion'] = str(lines)
|
||||
versions['PythonVersion'] = sys.version
|
||||
versions['babel'] = babelVersion
|
||||
versions['sqlalchemy'] = sqlalchemyVersion
|
||||
@ -2186,12 +2193,12 @@ def upload():
|
||||
return redirect(url_for('index'))
|
||||
try:
|
||||
copyfile(meta.file_path, saved_filename)
|
||||
except OSError, e:
|
||||
except OSError as e:
|
||||
flash(_(u"Failed to store file %s (Permission denied)." % saved_filename), category="error")
|
||||
return redirect(url_for('index'))
|
||||
try:
|
||||
os.unlink(meta.file_path)
|
||||
except OSError, e:
|
||||
except OSError as e:
|
||||
flash(_(u"Failed to delete file %s (Permission denied)." % meta.file_path), category="warning")
|
||||
|
||||
file_size = os.path.getsize(saved_filename)
|
||||
@ -2223,7 +2230,7 @@ def upload():
|
||||
db.session.add(db_language)
|
||||
# combine path and normalize path from windows systems
|
||||
path = os.path.join(author_dir, title_dir).replace('\\','/')
|
||||
db_book = db.Books(title, "", db_author.sort, datetime.datetime.now(), datetime.datetime(101, 01, 01), 1,
|
||||
db_book = db.Books(title, "", db_author.sort, datetime.datetime.now(), datetime.datetime(101, 1, 1), 1,
|
||||
datetime.datetime.now(), path, has_cover, db_author, [], db_language)
|
||||
db_book.authors.append(db_author)
|
||||
if db_language is not None:
|
||||
|
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
future
|
||||
sqlalchemy
|
Loading…
Reference in New Issue
Block a user