From 94f20ad00be7edb2c81e02679876699064f88ea6 Mon Sep 17 00:00:00 2001 From: Thenlie Date: Sat, 16 Aug 2025 11:27:25 -0600 Subject: [PATCH] set up environment variables --- .env.example | 2 ++ .gitignore | 3 +++ AdvSearchPage.py | 11 +++++++++-- BaseSearcher.py | 2 ++ CherryPy.conf | 5 ++++- Page.py | 3 ++- templates/menu.html | 2 +- templates/site-layout.html | 9 ++++----- 8 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..453c3c8 --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +PG_USER=gutenberg +STATIC_DIR=static # 'gutenberg' for dev/prod \ No newline at end of file diff --git a/.gitignore b/.gitignore index 894a44c..860ebbe 100644 --- a/.gitignore +++ b/.gitignore @@ -102,3 +102,6 @@ venv.bak/ # mypy .mypy_cache/ + +# local static files +static/ diff --git a/AdvSearchPage.py b/AdvSearchPage.py index 7d8283b..b38c33b 100644 --- a/AdvSearchPage.py +++ b/AdvSearchPage.py @@ -22,6 +22,7 @@ """ +import os import re import cherrypy @@ -40,14 +41,20 @@ from catalog import catname +from dotenv import load_dotenv +load_dotenv() + +cherrypy.config.update({ + 'pguser': os.getenv('PG_USER'), + 'staticdir': os.getenv('STATIC_DIR') +}) + config = cherrypy.config BROWSE_KEYS = {'lang': 'l', 'locc': 'lcc'} PAGESIZE = 100 MAX_RESULTS = 5000 - - class AdvSearcher(BaseSearcher.OpenSearch): """ this object passes the context for the page renderer """ def __init__(self): diff --git a/BaseSearcher.py b/BaseSearcher.py index de15b5b..cbd54f8 100644 --- a/BaseSearcher.py +++ b/BaseSearcher.py @@ -15,6 +15,7 @@ from __future__ import unicode_literals from __future__ import division +import os import datetime import logging @@ -381,6 +382,7 @@ class OpenSearch(object): } def __init__(self): + self.staticdir = os.getenv('STATIC_DIR') self.format = None self.page = None self.template = None diff --git a/CherryPy.conf b/CherryPy.conf index 41d1cbb..4317ba2 100644 --- a/CherryPy.conf +++ b/CherryPy.conf @@ -19,7 +19,6 @@ server.thread_pool_max: 20 pghost: 'localhost' pgport: 5432 pgdatabase: 'gutenberg' -pguser: 'postgres' host: 'www.gutenberg.org' host_https: 1 @@ -81,6 +80,10 @@ tools.expires.on: True tools.expires.secs: 0 tools.expires.force: True +[/static] +tools.staticdir.on: True +tools.staticdir.dir: CherryPyApp.install_dir + "/static" + [/index.html] tools.staticfile.on: True tools.staticfile.filename: CherryPyApp.install_dir + '/test/index.html' diff --git a/Page.py b/Page.py index 523ee6d..64cc464 100644 --- a/Page.py +++ b/Page.py @@ -11,9 +11,9 @@ Base class for all pages. """ - from __future__ import unicode_literals +import os import logging import cherrypy @@ -31,6 +31,7 @@ class Page(object): def __init__(self): self.supported_book_mediatypes = [ mt.epub, mt.mobi ] + self.staticdir = os.getenv('STATIC_DIR') @staticmethod diff --git a/templates/menu.html b/templates/menu.html index 5c015e3..8297464 100644 --- a/templates/menu.html +++ b/templates/menu.html @@ -8,7 +8,7 @@ diff --git a/templates/site-layout.html b/templates/site-layout.html index 245e95b..c131e5a 100644 --- a/templates/site-layout.html +++ b/templates/site-layout.html @@ -17,10 +17,10 @@ .page_content a.subtle_link:hover {color:#003366} - - - - + + + +