From 952d389dc516b061beba528d46c96fbbcfcd009b Mon Sep 17 00:00:00 2001 From: JanB Date: Fri, 15 Apr 2016 18:23:00 +0200 Subject: [PATCH] Ship config.ini with defaults; log errors to file; fix OPDS catalog name --- config.ini | 11 +++++++++++ cps/config.py | 13 ++++++++++++- cps/templates/feed.xml | 6 +++--- cps/templates/index.xml | 6 +++--- cps/templates/osd.xml | 10 +++++----- cps/templates/search.xml | 10 +++++----- cps/web.py | 10 +++++----- readme.md | 5 ++--- 8 files changed, 46 insertions(+), 25 deletions(-) create mode 100644 config.ini diff --git a/config.ini b/config.ini new file mode 100644 index 00000000..bdeb6e10 --- /dev/null +++ b/config.ini @@ -0,0 +1,11 @@ +[General] +DB_ROOT = +APP_DB_ROOT = +MAIN_DIR = +LOG_DIR = +PORT = 8083 +NEWEST_BOOKS = 60 +[Advanced] +TITLE_REGEX = ^(A|The|An|Der|Die|Das|Den|Ein|Eine|Einen|Dem|Des|Einem|Eines)\s+ +DEVELOPMENT = 0 +PUBLIC_REG = 0 diff --git a/cps/config.py b/cps/config.py index 6a22d50e..254576f4 100755 --- a/cps/config.py +++ b/cps/config.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- import os +import sys from configobj import ConfigObj @@ -20,6 +21,9 @@ def CheckSection(sec): def check_setting_str(config, cfg_name, item_name, def_val, log=True): try: my_val = config[cfg_name][item_name] + if my_val == "": + my_val = def_val + config[cfg_name][item_name] = my_val except: my_val = def_val try: @@ -43,9 +47,10 @@ def check_setting_int(config, cfg_name, item_name, def_val): return my_val CheckSection('General') -DB_ROOT = check_setting_str(CFG, 'General', 'DB_ROOT', os.path.join(os.getcwd(), "Calibre Library")) +DB_ROOT = check_setting_str(CFG, 'General', 'DB_ROOT', "") APP_DB_ROOT = check_setting_str(CFG, 'General', 'APP_DB_ROOT', os.getcwd()) MAIN_DIR = check_setting_str(CFG, 'General', 'MAIN_DIR', os.getcwd()) +LOG_DIR = check_setting_str(CFG, 'General', 'LOG_DIR', os.getcwd()) PORT = check_setting_int(CFG, 'General', 'PORT', 8083) NEWEST_BOOKS = check_setting_str(CFG, 'General', 'NEWEST_BOOKS', 60) RANDOM_BOOKS = check_setting_int(CFG, 'General', 'RANDOM_BOOKS', 4) @@ -57,10 +62,15 @@ PUBLIC_REG = bool(check_setting_int(CFG, 'Advanced', 'PUBLIC_REG', 0)) SYS_ENCODING="UTF-8" +if DB_ROOT == "": + print "Calibre database directory (DB_ROOT) is not configured" + sys.exit(1) + configval={} configval["DB_ROOT"] = DB_ROOT configval["APP_DB_ROOT"] = APP_DB_ROOT configval["MAIN_DIR"] = MAIN_DIR +configval["LOG_DIR"] = LOG_DIR configval["PORT"] = PORT configval["NEWEST_BOOKS"] = NEWEST_BOOKS configval["DEVELOPMENT"] = DEVELOPMENT @@ -74,6 +84,7 @@ def save_config(configval): new_config['General']['DB_ROOT'] = configval["DB_ROOT"] new_config['General']['APP_DB_ROOT'] = configval["APP_DB_ROOT"] new_config['General']['MAIN_DIR'] = configval["MAIN_DIR"] + new_config['General']['LOG_DIR'] = configval["LOG_DIR"] new_config['General']['PORT'] = configval["PORT"] new_config['General']['NEWEST_BOOKS'] = configval["NEWEST_BOOKS"] new_config['Advanced'] = {} diff --git a/cps/templates/feed.xml b/cps/templates/feed.xml index 458c3d3e..b798cf0f 100644 --- a/cps/templates/feed.xml +++ b/cps/templates/feed.xml @@ -16,11 +16,11 @@ - library + Calibre Web 2010-01-10T10:03:10Z - cytec - http://opds-spec.org + Calibre Web + https://github.com/janeczku/calibre-web {% for entry in entries %} diff --git a/cps/templates/index.xml b/cps/templates/index.xml index 54e00dc3..b7d8c959 100644 --- a/cps/templates/index.xml +++ b/cps/templates/index.xml @@ -16,11 +16,11 @@ - library + Calibre Web 2010-01-10T10:03:10Z - Spec Writer - http://opds-spec.org + Calibre Web + https://github.com/janeczku/calibre-web diff --git a/cps/templates/osd.xml b/cps/templates/osd.xml index 6bab7c13..c43fe9ff 100644 --- a/cps/templates/osd.xml +++ b/cps/templates/osd.xml @@ -1,11 +1,11 @@ - library - library - Search the ebook catalog. - cytec - iamcytec@googlemail.com + Calibre Web + Calibre Web + Calibre Web ebook catalog + janeczku + https://github.com/janeczku/calibre-web diff --git a/cps/templates/search.xml b/cps/templates/search.xml index 58fe6c23..95f5c58a 100644 --- a/cps/templates/search.xml +++ b/cps/templates/search.xml @@ -1,11 +1,11 @@ - library - library - Search the ebook catalog. - cytec - iamcytec@googlemail.com + Calibre Web + Calibre Web + Calibre Web ebook catalog + janeczku + https://github.com/janeczku/calibre-web diff --git a/cps/web.py b/cps/web.py index bce91a84..4b308151 100755 --- a/cps/web.py +++ b/cps/web.py @@ -3,6 +3,7 @@ import mimetypes import logging +from logging.handlers import RotatingFileHandler import sys import textwrap mimetypes.add_type('application/xhtml+xml','.xhtml') @@ -32,13 +33,12 @@ from shutil import copyfile app = (Flask(__name__)) -# Log only in production mode. -#if not app.debug: -file_handler = logging.StreamHandler(sys.stdout) +formatter = logging.Formatter( + "[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s") +file_handler = RotatingFileHandler(os.path.join(config.LOG_DIR, "calibre-web.log"), maxBytes=10000, backupCount=1) file_handler.setLevel(logging.INFO) +file_handler.setFormatter(formatter) app.logger.addHandler(file_handler) -app.logger_name = 'calibre web' -app.logger.setLevel(logging.INFO) app.logger.info('Starting Calibre Web...') Principal(app) diff --git a/readme.md b/readme.md index 0ced9fee..51eef07a 100755 --- a/readme.md +++ b/readme.md @@ -25,9 +25,8 @@ Also available as [Docker image](https://registry.hub.docker.com/u/janeczku/cali ## Quick start -1. Execute the command: `python cps.py` (it will throw an error) -2. Edit config.ini and set DB_ROOT to the path of the folder where your Calibre library (metadata.db) lives -3. If you want to enable public user registration set PUBLIC_REG to 1 +1. Open config.ini and set DB_ROOT to the path of the folder where your Calibre library (metadata.db) lives +3. To enable public user registration set PUBLIC_REG to 1 4. Execute the command: `python cps.py` 5. Point your browser to `http://localhost:8083` or `http://localhost:8083/feed` for the OPDS catalog