From 0e0e72fb71dadc005e7d8fa9a87bc46b679631ea Mon Sep 17 00:00:00 2001 From: OzzieIsaacs Date: Sun, 19 Mar 2017 17:14:16 +0100 Subject: [PATCH] Fixes for gevent/gdrive --- cps.py | 16 ++++++++++------ cps/gdriveutils.py | 2 +- cps/templates/config_edit.html | 2 ++ cps/ub.py | 1 - cps/web.py | 29 +++++++++-------------------- optional-requirements.txt | 13 +++++++++++++ requirements.txt | 13 ------------- 7 files changed, 35 insertions(+), 41 deletions(-) create mode 100644 optional-requirements.txt diff --git a/cps.py b/cps.py index 373e9432..180be500 100755 --- a/cps.py +++ b/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) diff --git a/cps/gdriveutils.py b/cps/gdriveutils.py index 5cf52307..55341419 100644 --- a/cps/gdriveutils.py +++ b/cps/gdriveutils.py @@ -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 diff --git a/cps/templates/config_edit.html b/cps/templates/config_edit.html index fc002801..62a27245 100644 --- a/cps/templates/config_edit.html +++ b/cps/templates/config_edit.html @@ -7,6 +7,7 @@ + {% if gdrive %}
@@ -46,6 +47,7 @@
{% endif %} + {% endif %}
diff --git a/cps/ub.py b/cps/ub.py index f7ba2fed..44a3808d 100644 --- a/cps/ub.py +++ b/cps/ub.py @@ -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 diff --git a/cps/web.py b/cps/web.py index 4188afdd..6855f84d 100755 --- a/cps/web.py +++ b/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 diff --git a/optional-requirements.txt b/optional-requirements.txt new file mode 100644 index 00000000..71c7b4ea --- /dev/null +++ b/optional-requirements.txt @@ -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 diff --git a/requirements.txt b/requirements.txt index 8670a2f9..5678ef5e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 \ No newline at end of file