Ship config.ini with defaults; log errors to file; fix OPDS catalog name

This commit is contained in:
JanB 2016-04-15 18:23:00 +02:00
parent b99c793aa2
commit 952d389dc5
8 changed files with 46 additions and 25 deletions

11
config.ini Normal file
View File

@ -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

View File

@ -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'] = {}

View File

@ -16,11 +16,11 @@
<link rel="search"
href="{{url_for('feed_osd')}}"
type="application/opensearchdescription+xml"/>
<title>library</title>
<title>Calibre Web</title>
<updated>2010-01-10T10:03:10Z</updated>
<author>
<name>cytec</name>
<uri>http://opds-spec.org</uri>
<name>Calibre Web</name>
<uri>https://github.com/janeczku/calibre-web</uri>
</author>
{% for entry in entries %}

View File

@ -16,11 +16,11 @@
<link rel="search"
href="{{url_for('feed_osd')}}"
type="application/opensearchdescription+xml"/>
<title>library</title>
<title>Calibre Web</title>
<updated>2010-01-10T10:03:10Z</updated>
<author>
<name>Spec Writer</name>
<uri>http://opds-spec.org</uri>
<name>Calibre Web</name>
<uri>https://github.com/janeczku/calibre-web</uri>
</author>

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
<LongName>library</LongName>
<ShortName>library</ShortName>
<Description>Search the ebook catalog.</Description>
<Developer>cytec</Developer>
<Contact>iamcytec@googlemail.com</Contact>
<LongName>Calibre Web</LongName>
<ShortName>Calibre Web</ShortName>
<Description>Calibre Web ebook catalog</Description>
<Developer>janeczku</Developer>
<Contact>https://github.com/janeczku/calibre-web</Contact>
<Url type="text/html"
template="{{url_for('search')}}?query={searchTerms}"/>

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
<LongName>library</LongName>
<ShortName>library</ShortName>
<Description>Search the ebook catalog.</Description>
<Developer>cytec</Developer>
<Contact>iamcytec@googlemail.com</Contact>
<LongName>Calibre Web</LongName>
<ShortName>Calibre Web</ShortName>
<Description>Calibre Web ebook catalog</Description>
<Developer>janeczku</Developer>
<Contact>https://github.com/janeczku/calibre-web</Contact>
<Url type="text/html"
template="{{url_for('search')}}?query={searchTerms}"/>

View File

@ -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)

View File

@ -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