Fixes for gevent/gdrive
This commit is contained in:
parent
907a2eca68
commit
0e0e72fb71
16
cps.py
16
cps.py
|
@ -11,19 +11,23 @@ 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
|
||||
from tornado.httpserver import HTTPServer
|
||||
from tornado.ioloop import IOLoop
|
||||
from gevent.wsgi import WSGIServer
|
||||
try:
|
||||
from gevent.wsgi import WSGIServer
|
||||
gevent_present = True
|
||||
except ImportError:
|
||||
from tornado.wsgi import WSGIContainer
|
||||
from tornado.httpserver import HTTPServer
|
||||
from tornado.ioloop import IOLoop
|
||||
gevent_present = False
|
||||
|
||||
if __name__ == '__main__':
|
||||
if web.ub.DEVELOPMENT:
|
||||
web.app.run(host="0.0.0.0", port=web.ub.config.config_port, debug=True)
|
||||
else:
|
||||
try:
|
||||
if gevent_present:
|
||||
web.app.logger.info('Attempting to start gevent')
|
||||
web.start_gevent()
|
||||
except ImportError:
|
||||
else:
|
||||
web.app.logger.info('Falling back to Tornado')
|
||||
http_server = HTTPServer(WSGIContainer(web.app))
|
||||
http_server.listen(web.ub.config.config_port)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
try:
|
||||
from pydrive.auth import GoogleAuth
|
||||
from pydrive.drive import GoogleDrive
|
||||
from apiclient import errors
|
||||
except ImportError:
|
||||
pass
|
||||
import os, time
|
||||
|
@ -12,7 +13,6 @@ from sqlalchemy import exc
|
|||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import *
|
||||
|
||||
from apiclient import errors
|
||||
|
||||
import web
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
<label for="config_calibre_dir">{{_('Location of Calibre database')}}</label>
|
||||
<input type="text" class="form-control" name="config_calibre_dir" id="config_calibre_dir" value="{% if content.config_calibre_dir != None %}{{ content.config_calibre_dir }}{% endif %}" autocomplete="off">
|
||||
</div>
|
||||
{% if gdrive %}
|
||||
<div class="form-group required">
|
||||
<input type="checkbox" id="config_use_google_drive" name="config_use_google_drive" {% if content.config_use_google_drive %}checked{% endif %} >
|
||||
<label for="config_use_google_drive">{{_('Use google drive?')}}</label>
|
||||
|
@ -46,6 +47,7 @@
|
|||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="form-group">
|
||||
<label for="config_port">{{_('Server Port')}}</label>
|
||||
<input type="number" min="1" max="65535" class="form-control" name="config_port" id="config_port" value="{% if content.config_port != None %}{{ content.config_port }}{% endif %}" autocomplete="off" required>
|
||||
|
|
|
@ -187,7 +187,6 @@ class Anonymous(AnonymousUserMixin, UserBase):
|
|||
self.role = data.role
|
||||
self.sidebar_view = data.sidebar_view
|
||||
self.default_language = data.default_language
|
||||
self.default_language = data.default_language
|
||||
self.locale = data.locale
|
||||
self.anon_browse = settings.config_anonbrowse
|
||||
|
||||
|
|
29
cps/web.py
29
cps/web.py
|
@ -11,9 +11,8 @@ import mimetypes
|
|||
import logging
|
||||
from logging.handlers import RotatingFileHandler
|
||||
import textwrap
|
||||
from flask import Flask, render_template, session, request, Response, redirect, url_for, send_from_directory, \
|
||||
make_response, g, flash, abort, send_file, Markup, \
|
||||
stream_with_context
|
||||
from flask import Flask, render_template, request, Response, redirect, url_for, send_from_directory, \
|
||||
make_response, g, flash, abort, Markup, stream_with_context
|
||||
from flask import __version__ as flaskVersion
|
||||
import ub
|
||||
from ub import config
|
||||
|
@ -26,7 +25,7 @@ from sqlalchemy.exc import IntegrityError
|
|||
from sqlalchemy import __version__ as sqlalchemyVersion
|
||||
from math import ceil
|
||||
from flask_login import LoginManager, login_user, logout_user, login_required, current_user
|
||||
from flask_principal import Principal, Identity, AnonymousIdentity, identity_changed
|
||||
from flask_principal import Principal
|
||||
from flask_principal import __version__ as flask_principalVersion
|
||||
from flask_babel import Babel
|
||||
from flask_babel import gettext as _
|
||||
|
@ -1266,16 +1265,6 @@ def stats():
|
|||
return render_title_template('stats.html', bookcounter=counter, authorcounter=authors, versions=versions,
|
||||
categorycounter=categorys, seriecounter=series, title=_(u"Statistics"))
|
||||
|
||||
|
||||
#@app.route("/load_gdrive")
|
||||
#@login_required
|
||||
#@admin_required
|
||||
#def load_all_gdrive_folder_ids():
|
||||
# books=db.session.query(db.Books).all()
|
||||
# for book in books:
|
||||
# gdriveutils.getFolderId(book.path, Gdrive.Instance().drive)
|
||||
# return
|
||||
|
||||
@app.route("/gdrive/authenticate")
|
||||
@login_required
|
||||
@admin_required
|
||||
|
@ -1320,7 +1309,7 @@ def revoke_watch_gdrive():
|
|||
if last_watch_response:
|
||||
try:
|
||||
response=gdriveutils.stopChannel(Gdrive.Instance().drive, last_watch_response['id'], last_watch_response['resourceId'])
|
||||
except HttpError, e:
|
||||
except HttpError:
|
||||
pass
|
||||
settings = ub.session.query(ub.Settings).first()
|
||||
settings.config_google_drive_watch_changes_response=None
|
||||
|
@ -2116,13 +2105,13 @@ def configuration_helper(origin):
|
|||
logging.getLogger("book_formats").setLevel(config.config_log_level)
|
||||
except e:
|
||||
flash(e, category="error")
|
||||
return render_title_template("config_edit.html", content=config, origin=origin,
|
||||
return render_title_template("config_edit.html", content=config, origin=origin, gdrive=gdrive_support,
|
||||
title=_(u"Basic Configuration"))
|
||||
if db_change:
|
||||
reload(db)
|
||||
if not db.setup_db():
|
||||
flash(_(u'DB location is not valid, please enter correct path'), category="error")
|
||||
return render_title_template("config_edit.html", content=config, origin=origin,
|
||||
return render_title_template("config_edit.html", content=config, origin=origin, gdrive=gdrive_support,
|
||||
title=_(u"Basic Configuration"))
|
||||
if reboot_required:
|
||||
# db.engine.dispose() # ToDo verify correct
|
||||
|
@ -2136,7 +2125,7 @@ def configuration_helper(origin):
|
|||
if origin:
|
||||
success = True
|
||||
return render_title_template("config_edit.html", origin=origin, success=success, content=config,
|
||||
show_authenticate_google_drive=not is_gdrive_ready(),
|
||||
show_authenticate_google_drive=not is_gdrive_ready(), gdrive=gdrive_support,
|
||||
title=_(u"Basic Configuration"))
|
||||
|
||||
|
||||
|
@ -2328,10 +2317,10 @@ def edit_user(user_id):
|
|||
elif "show_best_rated" not in to_save and content.show_best_rated_books():
|
||||
content.sidebar_view -= ub.SIDEBAR_BEST_RATED
|
||||
|
||||
if "show_read_and_unread" in to_save:
|
||||
if "show_read_and_unread" in to_save and not content.show_read_and_unread():
|
||||
content.sidebar_view += ub.SIDEBAR_READ_AND_UNREAD
|
||||
elif "show_read_and_unread" not in to_save and content.show_read_and_unread():
|
||||
content.sidebar_view += ub.SIDEBAR_READ_AND_UNREAD
|
||||
content.sidebar_view -= ub.SIDEBAR_READ_AND_UNREAD
|
||||
|
||||
if "show_author" in to_save and not content.show_author():
|
||||
content.sidebar_view += ub.SIDEBAR_AUTHOR
|
||||
|
|
13
optional-requirements.txt
Normal file
13
optional-requirements.txt
Normal file
|
@ -0,0 +1,13 @@
|
|||
gevent==1.2.1
|
||||
google-api-python-client==1.6.1
|
||||
greenlet==0.4.12
|
||||
httplib2==0.9.2
|
||||
lxml==3.7.2
|
||||
oauth2client==4.0.0
|
||||
pyasn1-modules==0.0.8
|
||||
pyasn1==0.1.9
|
||||
PyDrive==1.3.1
|
||||
PyYAML==3.12
|
||||
rsa==3.4.2
|
||||
six==1.10.0
|
||||
uritemplate==3.0.0
|
|
@ -3,23 +3,10 @@ Flask-Babel==0.11.1
|
|||
Flask-Login>=0.3.2
|
||||
Flask-Principal>=0.3.2
|
||||
Flask>=0.11
|
||||
gevent==1.2.1
|
||||
google-api-python-client==1.6.1
|
||||
greenlet==0.4.12
|
||||
httplib2==0.9.2
|
||||
iso-639>=0.4.5
|
||||
lxml==3.7.2
|
||||
oauth2client==4.0.0
|
||||
pyasn1-modules==0.0.8
|
||||
pyasn1==0.1.9
|
||||
PyDrive==1.3.1
|
||||
PyPDF2==1.26.0
|
||||
pytz>=2016.10
|
||||
PyYAML==3.12
|
||||
requests>=2.11.1
|
||||
rsa==3.4.2
|
||||
six==1.10.0
|
||||
SQLAlchemy>=0.8.4
|
||||
tornado>=4.1
|
||||
uritemplate==3.0.0
|
||||
Wand>=0.4.4
|
Loading…
Reference in New Issue
Block a user