diff --git a/CherryPy.conf b/CherryPy.conf index 31fb9ff..05614d7 100644 --- a/CherryPy.conf +++ b/CherryPy.conf @@ -12,7 +12,7 @@ server.socket_queue_size: 10 server.thread_pool: 20 server.thread_pool_max: 20 -# change host params in .autocat3 or /etc/autocat3.conf files +# change host and postgres params in .autocat3 or /etc/autocat3.conf files pghost: 'localhost' pgport: 5432 pgdatabase: 'gutenberg' @@ -20,6 +20,7 @@ pguser: 'postgres' host: 'www.gutenberg.org' host_mobile: 'm.gutenberg.org' +host_https: 1 file_host: 'www.gutenberg.org' sqlalchemy.pool_size: 20 @@ -72,8 +73,8 @@ tools.sessions.on: True tools.sessions.table_name = "cherrypy.sessions" tools.sessions.timeout: 30 tools.sessions.path: '/' -# change host in .autocat3 or /etc/autocat3.conf files tools.sessions.domain: 'gutenberg.org' +#tools.sessions.domain: 'localhost' tools.expires.on: True tools.expires.secs: 0 @@ -81,4 +82,8 @@ tools.expires.force: True [/index.html] tools.staticfile.on: True -tools.staticfile.filename: CherryPyApp.install_dir + '/templates/index.html' +tools.staticfile.filename: CherryPyApp.install_dir + '/test/index.html' + +[/test.pdf] +tools.staticfile.on: True +tools.staticfile.filename: CherryPyApp.install_dir + '/test/test.pdf' diff --git a/CherryPyApp.py b/CherryPyApp.py index 793f206..099da2a 100644 --- a/CherryPyApp.py +++ b/CherryPyApp.py @@ -54,10 +54,7 @@ plugins.Timer = Timer.TimerPlugin install_dir = os.path.dirname (os.path.abspath (__file__)) CHERRYPY_CONFIG = os.path.join(install_dir, 'CherryPy.conf') -LOCAL_CONFIG = ( - os.path.join(install_dir, 'CherryPy.conf'), - os.path.expanduser('~/.autocat3'), '/etc/autocat3.conf' -) +LOCAL_CONFIG = [os.path.expanduser('~/.autocat3'), '/etc/autocat3.conf'] class MyRoutesDispatcher (cherrypy.dispatch.RoutesDispatcher): """ Dispatcher that tells us the matched route. @@ -92,13 +89,6 @@ def main (): config_filename = None cherrypy.config.update (CHERRYPY_CONFIG) - for config_filename in LOCAL_CONFIG: - try: - cherrypy.config.update (config_filename) - break - except IOError: - pass - # Rotating Logs # @@ -121,6 +111,8 @@ def main (): h.setLevel (logging.DEBUG) h.setFormatter (cherrypy._cplogging.logfmt) cherrypy.log.access_log.addHandler (h) + + if not cherrypy.config['daemonize']: ch = logging.StreamHandler () @@ -132,8 +124,15 @@ def main (): # cherrypy.log ('*' * 80, context = 'ENGINE', severity = logging.INFO) - cherrypy.log ("Using config file '%s'." % config_filename, + cherrypy.log ("Using config file '%s'." % CHERRYPY_CONFIG, context = 'ENGINE', severity = logging.INFO) + for config_filename in LOCAL_CONFIG: + try: + cherrypy.config.update (config_filename) + cherrypy.log ('loaded %s' % config_filename, context = 'ENGINE', severity = logging.INFO) + break + except IOError: + pass # after cherrypy.config is parsed Formatters.init () @@ -308,7 +307,7 @@ def main (): cherrypy.log ("Mounting root", context = 'ENGINE', severity = logging.INFO) - app = cherrypy.tree.mount (root = None, config = config_filename) + app = cherrypy.tree.mount (root = None, config = CHERRYPY_CONFIG) app.merge ({'/': {'request.dispatch': d}}) return app diff --git a/CloudStorage.py b/CloudStorage.py index f9ec8e6..054b481 100644 --- a/CloudStorage.py +++ b/CloudStorage.py @@ -65,9 +65,10 @@ class CloudOAuth2Session (requests_oauthlib.OAuth2Session): # pylint: disable=R0 prefix = self.name_prefix host = config['file_host'] + host_https = config['host_https'] urlgen = routes.URLGenerator (cherrypy.routes_mapper, { 'HTTP_HOST': host, - 'HTTPS': 1 + 'HTTPS': host_https }) client_id = config[prefix + '_client_id'] @@ -297,7 +298,11 @@ class EbookMetaData (object): def get_source_url (self): """ Return the url of the ebook file on gutenberg.org. """ - + protocol = 'https://' if cherrypy.config['host_https'] else 'http://' + if self.id == 99999: + # test filename + return urllib.parse.urljoin ( + protocol + str(cherrypy.config['file_host']) , 'test.pdf') return urllib.parse.urljoin ( - 'https://' + cherrypy.config['file_host'], + protocol + cherrypy.config['file_host'], 'ebooks/%d.%s' % (self.id, self.filetype)) diff --git a/templates/index.html b/templates/index.html deleted file mode 100644 index 7d6870e..0000000 --- a/templates/index.html +++ /dev/null @@ -1,19 +0,0 @@ - - - - - -
-

Download Test

-

-Dropbox -

-

-Google Drive -

-

-OneDrive -

-
- - \ No newline at end of file diff --git a/test/index.html b/test/index.html new file mode 100644 index 0000000..4267333 --- /dev/null +++ b/test/index.html @@ -0,0 +1,19 @@ + + + + + +
+

Download Test

+

+Dropbox +

+

+Google Drive +

+

+OneDrive +

+
+ + \ No newline at end of file diff --git a/test/test.pdf b/test/test.pdf new file mode 100644 index 0000000..d2b1fd8 Binary files /dev/null and b/test/test.pdf differ