mirror of
https://github.com/janeczku/calibre-web
synced 2024-11-30 21:40:00 +00:00
Fix Encoding issues for python2
This commit is contained in:
parent
32af660f86
commit
572b5427c7
8
cps.py
8
cps.py
@ -23,8 +23,12 @@ import os
|
||||
|
||||
|
||||
# Insert local directories into path
|
||||
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
||||
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'vendor'))
|
||||
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.join(os.path.dirname(os.path.abspath(__file__)), 'vendor'))
|
||||
|
||||
|
||||
from cps import create_app
|
||||
|
@ -87,8 +87,8 @@ global_WorkerThread = WorkerThread()
|
||||
from .server import WebServer
|
||||
web_server = WebServer()
|
||||
|
||||
from .ldap import Ldap
|
||||
ldap = Ldap()
|
||||
from .ldap_login import Ldap
|
||||
ldap1 = Ldap()
|
||||
|
||||
babel = Babel()
|
||||
|
||||
@ -97,6 +97,12 @@ log = logger.create()
|
||||
|
||||
def create_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)
|
||||
|
||||
log.info('Starting Calibre Web...')
|
||||
@ -106,7 +112,7 @@ def create_app():
|
||||
web_server.init_app(app, config)
|
||||
db.setup_db()
|
||||
babel.init_app(app)
|
||||
ldap.init_app(app)
|
||||
ldap1.init_app(app)
|
||||
global_WorkerThread.start()
|
||||
return app
|
||||
|
||||
|
@ -40,7 +40,7 @@ from sqlalchemy import and_
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
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 .helper import speaking_language, check_valid_domain, check_unrar, send_test_mail, generate_random_password, \
|
||||
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
|
||||
|
||||
feature_support = dict()
|
||||
feature_support['ldap'] = ldap.ldap_supported()
|
||||
feature_support['ldap'] = ldap1.ldap_supported()
|
||||
|
||||
try:
|
||||
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')
|
||||
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")
|
||||
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 = 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')
|
||||
TEMPLATES_DIR = os.path.join(BASE_DIR, 'cps', 'templates')
|
||||
TRANSLATIONS_DIR = os.path.join(BASE_DIR, 'cps', 'translations')
|
||||
|
@ -342,7 +342,7 @@ def setup_db():
|
||||
try:
|
||||
if not os.path.exists(dbpath):
|
||||
raise
|
||||
engine = create_engine('sqlite:///' + dbpath,
|
||||
engine = create_engine('sqlite:///{0}'.format(dbpath),
|
||||
echo=False,
|
||||
isolation_level="SERIALIZABLE",
|
||||
connect_args={'check_same_thread': False})
|
||||
|
@ -16,10 +16,11 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import division, print_function, unicode_literals
|
||||
import base64
|
||||
|
||||
try:
|
||||
from flask_simpleldap import LDAP, LDAPException
|
||||
from flask_simpleldap import LDAP # , LDAPException
|
||||
ldap_support = True
|
||||
except ImportError:
|
||||
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 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 .pagination import Pagination
|
||||
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__)
|
||||
|
||||
log = logger.create()
|
||||
ldap_support = ldap.ldap_supported()
|
||||
ldap_support = ldap1.ldap_supported()
|
||||
|
||||
|
||||
def requires_basic_auth_if_no_ano(f):
|
||||
@wraps(f)
|
||||
def decorated(*args, **kwargs):
|
||||
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
|
||||
if config.config_anonbrowse != 1:
|
||||
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
|
||||
|
||||
|
||||
'''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/")
|
||||
@requires_basic_auth_if_no_ano
|
||||
def feed_index():
|
||||
|
@ -25,7 +25,7 @@ import signal
|
||||
import socket
|
||||
|
||||
try:
|
||||
from gevent.pyiwsgi import WSGIServer
|
||||
from gevent.pywsgi import WSGIServer
|
||||
from gevent.pool import Pool
|
||||
from gevent import __version__ as _version
|
||||
VERSION = {'Gevent': 'v' + _version}
|
||||
|
@ -40,18 +40,12 @@ from sqlalchemy.orm import relationship, sessionmaker
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from werkzeug.security import generate_password_hash
|
||||
|
||||
'''try:
|
||||
import ldap
|
||||
except ImportError:
|
||||
pass'''
|
||||
|
||||
from . import constants, logger, cli
|
||||
|
||||
|
||||
session = None
|
||||
|
||||
|
||||
engine = create_engine('sqlite:///{0}'.format(cli.settingspath), echo=False)
|
||||
engine = create_engine(u'sqlite:///{0}'.format(cli.settingspath), echo=False)
|
||||
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.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 .gdriveutils import getFileFromEbooksFolder, do_gdrive_download
|
||||
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
|
||||
|
||||
feature_support = dict()
|
||||
feature_support['ldap'] = ldap.ldap_supported()
|
||||
feature_support['ldap'] = ldap1.ldap_supported()
|
||||
|
||||
try:
|
||||
from .oauth_bb import oauth_check, register_user_with_oauth, logout_oauth_user, get_oauth_status
|
||||
@ -1093,17 +1093,17 @@ def login():
|
||||
.first()
|
||||
if config.config_login_type == 1 and user and feature_support['ldap']:
|
||||
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)
|
||||
flash(_(u"you are now logged in as: '%(nickname)s'", nickname=user.nickname),
|
||||
category="success")
|
||||
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))
|
||||
ipAdress = request.headers.get('X-Forwarded-For', request.remote_addr)
|
||||
log.info('LDAP Login failed for user "%s" IP-adress: %s', form['username'], ipAdress)
|
||||
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')
|
||||
flash(_(u"Could not login. LDAP server down, please contact your administrator"), category="error")
|
||||
'''except LDAPException as exception:
|
||||
|
@ -326,6 +326,8 @@ class WorkerThread(threading.Thread):
|
||||
nextline = p.stdout.readline()
|
||||
if os.name == 'nt' and sys.version_info < (3, 0):
|
||||
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'))
|
||||
# parse progress string from calibre-converter
|
||||
progress = re.search("(\d+)%\s.*", nextline)
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user