mirror of
https://github.com/janeczku/calibre-web
synced 2024-11-28 12:30:00 +00:00
Fix Encoding issues for python2
This commit is contained in:
parent
32af660f86
commit
572b5427c7
4
cps.py
4
cps.py
@ -23,6 +23,10 @@ import os
|
|||||||
|
|
||||||
|
|
||||||
# Insert local directories into path
|
# Insert local directories into path
|
||||||
|
if sys.version_info < (3, 0):
|
||||||
|
sys.path.append(os.path.dirname(os.path.abspath(__file__.decode('utf-8'))))
|
||||||
|
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__.decode('utf-8'))), 'vendor'))
|
||||||
|
else:
|
||||||
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
||||||
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'vendor'))
|
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'vendor'))
|
||||||
|
|
||||||
|
@ -87,8 +87,8 @@ global_WorkerThread = WorkerThread()
|
|||||||
from .server import WebServer
|
from .server import WebServer
|
||||||
web_server = WebServer()
|
web_server = WebServer()
|
||||||
|
|
||||||
from .ldap import Ldap
|
from .ldap_login import Ldap
|
||||||
ldap = Ldap()
|
ldap1 = Ldap()
|
||||||
|
|
||||||
babel = Babel()
|
babel = Babel()
|
||||||
|
|
||||||
@ -97,6 +97,12 @@ log = logger.create()
|
|||||||
|
|
||||||
def create_app():
|
def create_app():
|
||||||
app.wsgi_app = ReverseProxied(app.wsgi_app)
|
app.wsgi_app = ReverseProxied(app.wsgi_app)
|
||||||
|
# For python2 convert path to unicode
|
||||||
|
if sys.version_info < (3, 0):
|
||||||
|
app.static_folder = app.static_folder.decode('utf-8')
|
||||||
|
app.root_path = app.root_path.decode('utf-8')
|
||||||
|
app.instance_path = app.instance_path .decode('utf-8')
|
||||||
|
|
||||||
cache_buster.init_cache_busting(app)
|
cache_buster.init_cache_busting(app)
|
||||||
|
|
||||||
log.info('Starting Calibre Web...')
|
log.info('Starting Calibre Web...')
|
||||||
@ -106,7 +112,7 @@ def create_app():
|
|||||||
web_server.init_app(app, config)
|
web_server.init_app(app, config)
|
||||||
db.setup_db()
|
db.setup_db()
|
||||||
babel.init_app(app)
|
babel.init_app(app)
|
||||||
ldap.init_app(app)
|
ldap1.init_app(app)
|
||||||
global_WorkerThread.start()
|
global_WorkerThread.start()
|
||||||
return app
|
return app
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ from sqlalchemy import and_
|
|||||||
from sqlalchemy.exc import IntegrityError
|
from sqlalchemy.exc import IntegrityError
|
||||||
from werkzeug.security import generate_password_hash
|
from werkzeug.security import generate_password_hash
|
||||||
|
|
||||||
from . import constants, logger, ldap
|
from . import constants, logger, ldap1
|
||||||
from . import db, ub, web_server, get_locale, config, updater_thread, babel, gdriveutils
|
from . import db, ub, web_server, get_locale, config, updater_thread, babel, gdriveutils
|
||||||
from .helper import speaking_language, check_valid_domain, check_unrar, send_test_mail, generate_random_password, \
|
from .helper import speaking_language, check_valid_domain, check_unrar, send_test_mail, generate_random_password, \
|
||||||
send_registration_mail
|
send_registration_mail
|
||||||
@ -48,7 +48,7 @@ from .gdriveutils import is_gdrive_ready, gdrive_support, downloadFile, deleteDa
|
|||||||
from .web import admin_required, render_title_template, before_request, unconfigured, login_required_if_no_ano
|
from .web import admin_required, render_title_template, before_request, unconfigured, login_required_if_no_ano
|
||||||
|
|
||||||
feature_support = dict()
|
feature_support = dict()
|
||||||
feature_support['ldap'] = ldap.ldap_supported()
|
feature_support['ldap'] = ldap1.ldap_supported()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from goodreads.client import GoodreadsClient
|
from goodreads.client import GoodreadsClient
|
||||||
|
12
cps/cli.py
12
cps/cli.py
@ -82,6 +82,18 @@ parser.add_argument('-i', metavar='ip-adress', help='Server IP-Adress to listen'
|
|||||||
parser.add_argument('-s', metavar='user:pass', help='Sets specific username to new password')
|
parser.add_argument('-s', metavar='user:pass', help='Sets specific username to new password')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if sys.version_info < (3, 0):
|
||||||
|
if args.p:
|
||||||
|
args.p = args.p.decode('utf-8')
|
||||||
|
if args.g:
|
||||||
|
args.g = args.g.decode('utf-8')
|
||||||
|
if args.k:
|
||||||
|
args.k = args.k.decode('utf-8')
|
||||||
|
if args.c:
|
||||||
|
args.c = args.c.decode('utf-8')
|
||||||
|
if args.s:
|
||||||
|
args.s = args.s.decode('utf-8')
|
||||||
|
|
||||||
|
|
||||||
settingspath = args.p or os.path.join(_CONFIG_DIR, "app.db")
|
settingspath = args.p or os.path.join(_CONFIG_DIR, "app.db")
|
||||||
gdpath = args.g or os.path.join(_CONFIG_DIR, "gdrive.db")
|
gdpath = args.g or os.path.join(_CONFIG_DIR, "gdrive.db")
|
||||||
|
@ -24,7 +24,12 @@ from collections import namedtuple
|
|||||||
|
|
||||||
|
|
||||||
# Base dir is parent of current file, necessary if called from different folder
|
# Base dir is parent of current file, necessary if called from different folder
|
||||||
BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)),os.pardir))
|
if sys.version_info < (3, 0):
|
||||||
|
BASE_DIR = os.path.abspath(os.path.join(
|
||||||
|
os.path.dirname(os.path.abspath(__file__)),os.pardir)).decode('utf-8')
|
||||||
|
else:
|
||||||
|
BASE_DIR = os.path.abspath(os.path.join(
|
||||||
|
os.path.dirname(os.path.abspath(__file__)),os.pardir))
|
||||||
STATIC_DIR = os.path.join(BASE_DIR, 'cps', 'static')
|
STATIC_DIR = os.path.join(BASE_DIR, 'cps', 'static')
|
||||||
TEMPLATES_DIR = os.path.join(BASE_DIR, 'cps', 'templates')
|
TEMPLATES_DIR = os.path.join(BASE_DIR, 'cps', 'templates')
|
||||||
TRANSLATIONS_DIR = os.path.join(BASE_DIR, 'cps', 'translations')
|
TRANSLATIONS_DIR = os.path.join(BASE_DIR, 'cps', 'translations')
|
||||||
|
@ -342,7 +342,7 @@ def setup_db():
|
|||||||
try:
|
try:
|
||||||
if not os.path.exists(dbpath):
|
if not os.path.exists(dbpath):
|
||||||
raise
|
raise
|
||||||
engine = create_engine('sqlite:///' + dbpath,
|
engine = create_engine('sqlite:///{0}'.format(dbpath),
|
||||||
echo=False,
|
echo=False,
|
||||||
isolation_level="SERIALIZABLE",
|
isolation_level="SERIALIZABLE",
|
||||||
connect_args={'check_same_thread': False})
|
connect_args={'check_same_thread': False})
|
||||||
|
@ -16,10 +16,11 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from __future__ import division, print_function, unicode_literals
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from flask_simpleldap import LDAP, LDAPException
|
from flask_simpleldap import LDAP # , LDAPException
|
||||||
ldap_support = True
|
ldap_support = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
ldap_support = False
|
ldap_support = False
|
15
cps/opds.py
15
cps/opds.py
@ -31,7 +31,7 @@ from flask_login import current_user
|
|||||||
from sqlalchemy.sql.expression import func, text, or_, and_
|
from sqlalchemy.sql.expression import func, text, or_, and_
|
||||||
from werkzeug.security import check_password_hash
|
from werkzeug.security import check_password_hash
|
||||||
|
|
||||||
from . import logger, config, db, ub, ldap
|
from . import logger, config, db, ub, ldap1
|
||||||
from .helper import fill_indexpage, get_download_link, get_book_cover
|
from .helper import fill_indexpage, get_download_link, get_book_cover
|
||||||
from .pagination import Pagination
|
from .pagination import Pagination
|
||||||
from .web import common_filters, get_search_results, render_read_books, download_required
|
from .web import common_filters, get_search_results, render_read_books, download_required
|
||||||
@ -40,14 +40,14 @@ from .web import common_filters, get_search_results, render_read_books, download
|
|||||||
opds = Blueprint('opds', __name__)
|
opds = Blueprint('opds', __name__)
|
||||||
|
|
||||||
log = logger.create()
|
log = logger.create()
|
||||||
ldap_support = ldap.ldap_supported()
|
ldap_support = ldap1.ldap_supported()
|
||||||
|
|
||||||
|
|
||||||
def requires_basic_auth_if_no_ano(f):
|
def requires_basic_auth_if_no_ano(f):
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
def decorated(*args, **kwargs):
|
def decorated(*args, **kwargs):
|
||||||
if config.config_login_type == 1 and ldap_support:
|
if config.config_login_type == 1 and ldap_support:
|
||||||
return ldap.ldap.basic_auth_required(*args, **kwargs)
|
return ldap1.ldap.basic_auth_required(*args, **kwargs)
|
||||||
auth = request.authorization
|
auth = request.authorization
|
||||||
if config.config_anonbrowse != 1:
|
if config.config_anonbrowse != 1:
|
||||||
if not auth or not check_auth(auth.username, auth.password):
|
if not auth or not check_auth(auth.username, auth.password):
|
||||||
@ -57,15 +57,6 @@ def requires_basic_auth_if_no_ano(f):
|
|||||||
return decorated
|
return decorated
|
||||||
|
|
||||||
|
|
||||||
'''def basic_auth_required_check(condition):
|
|
||||||
print("susi")
|
|
||||||
def decorator(f):
|
|
||||||
if condition and ldap_support:
|
|
||||||
return ldap.ldap.basic_auth_required(f)
|
|
||||||
return requires_basic_auth_if_no_ano(f)
|
|
||||||
return decorator'''
|
|
||||||
|
|
||||||
|
|
||||||
@opds.route("/opds/")
|
@opds.route("/opds/")
|
||||||
@requires_basic_auth_if_no_ano
|
@requires_basic_auth_if_no_ano
|
||||||
def feed_index():
|
def feed_index():
|
||||||
|
@ -25,7 +25,7 @@ import signal
|
|||||||
import socket
|
import socket
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from gevent.pyiwsgi import WSGIServer
|
from gevent.pywsgi import WSGIServer
|
||||||
from gevent.pool import Pool
|
from gevent.pool import Pool
|
||||||
from gevent import __version__ as _version
|
from gevent import __version__ as _version
|
||||||
VERSION = {'Gevent': 'v' + _version}
|
VERSION = {'Gevent': 'v' + _version}
|
||||||
|
@ -40,18 +40,12 @@ from sqlalchemy.orm import relationship, sessionmaker
|
|||||||
from sqlalchemy.ext.declarative import declarative_base
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
from werkzeug.security import generate_password_hash
|
from werkzeug.security import generate_password_hash
|
||||||
|
|
||||||
'''try:
|
|
||||||
import ldap
|
|
||||||
except ImportError:
|
|
||||||
pass'''
|
|
||||||
|
|
||||||
from . import constants, logger, cli
|
from . import constants, logger, cli
|
||||||
|
|
||||||
|
|
||||||
session = None
|
session = None
|
||||||
|
|
||||||
|
engine = create_engine(u'sqlite:///{0}'.format(cli.settingspath), echo=False)
|
||||||
engine = create_engine('sqlite:///{0}'.format(cli.settingspath), echo=False)
|
|
||||||
Base = declarative_base()
|
Base = declarative_base()
|
||||||
|
|
||||||
|
|
||||||
|
10
cps/web.py
10
cps/web.py
@ -41,7 +41,7 @@ from werkzeug.exceptions import default_exceptions
|
|||||||
from werkzeug.datastructures import Headers
|
from werkzeug.datastructures import Headers
|
||||||
from werkzeug.security import generate_password_hash, check_password_hash
|
from werkzeug.security import generate_password_hash, check_password_hash
|
||||||
|
|
||||||
from . import constants, logger, isoLanguages, ldap
|
from . import constants, logger, isoLanguages, ldap1
|
||||||
from . import global_WorkerThread, searched_ids, lm, babel, db, ub, config, get_locale, app, language_table
|
from . import global_WorkerThread, searched_ids, lm, babel, db, ub, config, get_locale, app, language_table
|
||||||
from .gdriveutils import getFileFromEbooksFolder, do_gdrive_download
|
from .gdriveutils import getFileFromEbooksFolder, do_gdrive_download
|
||||||
from .helper import common_filters, get_search_results, fill_indexpage, speaking_language, check_valid_domain, \
|
from .helper import common_filters, get_search_results, fill_indexpage, speaking_language, check_valid_domain, \
|
||||||
@ -52,7 +52,7 @@ from .pagination import Pagination
|
|||||||
from .redirect import redirect_back
|
from .redirect import redirect_back
|
||||||
|
|
||||||
feature_support = dict()
|
feature_support = dict()
|
||||||
feature_support['ldap'] = ldap.ldap_supported()
|
feature_support['ldap'] = ldap1.ldap_supported()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from .oauth_bb import oauth_check, register_user_with_oauth, logout_oauth_user, get_oauth_status
|
from .oauth_bb import oauth_check, register_user_with_oauth, logout_oauth_user, get_oauth_status
|
||||||
@ -1093,17 +1093,17 @@ def login():
|
|||||||
.first()
|
.first()
|
||||||
if config.config_login_type == 1 and user and feature_support['ldap']:
|
if config.config_login_type == 1 and user and feature_support['ldap']:
|
||||||
try:
|
try:
|
||||||
if ldap.ldap.bind_user(form['username'], form['password']) is not None:
|
if ldap1.ldap.bind_user(form['username'], form['password']) is not None:
|
||||||
login_user(user, remember=True)
|
login_user(user, remember=True)
|
||||||
flash(_(u"you are now logged in as: '%(nickname)s'", nickname=user.nickname),
|
flash(_(u"you are now logged in as: '%(nickname)s'", nickname=user.nickname),
|
||||||
category="success")
|
category="success")
|
||||||
return redirect_back(url_for("web.index"))
|
return redirect_back(url_for("web.index"))
|
||||||
except ldap.ldap.INVALID_CREDENTIALS as e:
|
except ldap1.ldap.INVALID_CREDENTIALS as e:
|
||||||
log.error('Login Error: ' + str(e))
|
log.error('Login Error: ' + str(e))
|
||||||
ipAdress = request.headers.get('X-Forwarded-For', request.remote_addr)
|
ipAdress = request.headers.get('X-Forwarded-For', request.remote_addr)
|
||||||
log.info('LDAP Login failed for user "%s" IP-adress: %s', form['username'], ipAdress)
|
log.info('LDAP Login failed for user "%s" IP-adress: %s', form['username'], ipAdress)
|
||||||
flash(_(u"Wrong Username or Password"), category="error")
|
flash(_(u"Wrong Username or Password"), category="error")
|
||||||
except ldap.ldap.SERVER_DOWN:
|
except ldap1.ldap.SERVER_DOWN:
|
||||||
log.info('LDAP Login failed, LDAP Server down')
|
log.info('LDAP Login failed, LDAP Server down')
|
||||||
flash(_(u"Could not login. LDAP server down, please contact your administrator"), category="error")
|
flash(_(u"Could not login. LDAP server down, please contact your administrator"), category="error")
|
||||||
'''except LDAPException as exception:
|
'''except LDAPException as exception:
|
||||||
|
@ -326,6 +326,8 @@ class WorkerThread(threading.Thread):
|
|||||||
nextline = p.stdout.readline()
|
nextline = p.stdout.readline()
|
||||||
if os.name == 'nt' and sys.version_info < (3, 0):
|
if os.name == 'nt' and sys.version_info < (3, 0):
|
||||||
nextline = nextline.decode('windows-1252')
|
nextline = nextline.decode('windows-1252')
|
||||||
|
elif os.name == 'posix' and sys.version_info < (3, 0):
|
||||||
|
nextline = nextline.decode('utf-8')
|
||||||
log.debug(nextline.strip('\r\n'))
|
log.debug(nextline.strip('\r\n'))
|
||||||
# parse progress string from calibre-converter
|
# parse progress string from calibre-converter
|
||||||
progress = re.search("(\d+)%\s.*", nextline)
|
progress = re.search("(\d+)%\s.*", nextline)
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user