Ship config.ini with defaults; log errors to file; fix OPDS catalog name
This commit is contained in:
parent
b99c793aa2
commit
952d389dc5
11
config.ini
Normal file
11
config.ini
Normal 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
|
|
@ -2,6 +2,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
from configobj import ConfigObj
|
from configobj import ConfigObj
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,6 +21,9 @@ def CheckSection(sec):
|
||||||
def check_setting_str(config, cfg_name, item_name, def_val, log=True):
|
def check_setting_str(config, cfg_name, item_name, def_val, log=True):
|
||||||
try:
|
try:
|
||||||
my_val = config[cfg_name][item_name]
|
my_val = config[cfg_name][item_name]
|
||||||
|
if my_val == "":
|
||||||
|
my_val = def_val
|
||||||
|
config[cfg_name][item_name] = my_val
|
||||||
except:
|
except:
|
||||||
my_val = def_val
|
my_val = def_val
|
||||||
try:
|
try:
|
||||||
|
@ -43,9 +47,10 @@ def check_setting_int(config, cfg_name, item_name, def_val):
|
||||||
return my_val
|
return my_val
|
||||||
|
|
||||||
CheckSection('General')
|
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())
|
APP_DB_ROOT = check_setting_str(CFG, 'General', 'APP_DB_ROOT', os.getcwd())
|
||||||
MAIN_DIR = check_setting_str(CFG, 'General', 'MAIN_DIR', 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)
|
PORT = check_setting_int(CFG, 'General', 'PORT', 8083)
|
||||||
NEWEST_BOOKS = check_setting_str(CFG, 'General', 'NEWEST_BOOKS', 60)
|
NEWEST_BOOKS = check_setting_str(CFG, 'General', 'NEWEST_BOOKS', 60)
|
||||||
RANDOM_BOOKS = check_setting_int(CFG, 'General', 'RANDOM_BOOKS', 4)
|
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"
|
SYS_ENCODING="UTF-8"
|
||||||
|
|
||||||
|
if DB_ROOT == "":
|
||||||
|
print "Calibre database directory (DB_ROOT) is not configured"
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
configval={}
|
configval={}
|
||||||
configval["DB_ROOT"] = DB_ROOT
|
configval["DB_ROOT"] = DB_ROOT
|
||||||
configval["APP_DB_ROOT"] = APP_DB_ROOT
|
configval["APP_DB_ROOT"] = APP_DB_ROOT
|
||||||
configval["MAIN_DIR"] = MAIN_DIR
|
configval["MAIN_DIR"] = MAIN_DIR
|
||||||
|
configval["LOG_DIR"] = LOG_DIR
|
||||||
configval["PORT"] = PORT
|
configval["PORT"] = PORT
|
||||||
configval["NEWEST_BOOKS"] = NEWEST_BOOKS
|
configval["NEWEST_BOOKS"] = NEWEST_BOOKS
|
||||||
configval["DEVELOPMENT"] = DEVELOPMENT
|
configval["DEVELOPMENT"] = DEVELOPMENT
|
||||||
|
@ -74,6 +84,7 @@ def save_config(configval):
|
||||||
new_config['General']['DB_ROOT'] = configval["DB_ROOT"]
|
new_config['General']['DB_ROOT'] = configval["DB_ROOT"]
|
||||||
new_config['General']['APP_DB_ROOT'] = configval["APP_DB_ROOT"]
|
new_config['General']['APP_DB_ROOT'] = configval["APP_DB_ROOT"]
|
||||||
new_config['General']['MAIN_DIR'] = configval["MAIN_DIR"]
|
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']['PORT'] = configval["PORT"]
|
||||||
new_config['General']['NEWEST_BOOKS'] = configval["NEWEST_BOOKS"]
|
new_config['General']['NEWEST_BOOKS'] = configval["NEWEST_BOOKS"]
|
||||||
new_config['Advanced'] = {}
|
new_config['Advanced'] = {}
|
||||||
|
|
|
@ -16,11 +16,11 @@
|
||||||
<link rel="search"
|
<link rel="search"
|
||||||
href="{{url_for('feed_osd')}}"
|
href="{{url_for('feed_osd')}}"
|
||||||
type="application/opensearchdescription+xml"/>
|
type="application/opensearchdescription+xml"/>
|
||||||
<title>library</title>
|
<title>Calibre Web</title>
|
||||||
<updated>2010-01-10T10:03:10Z</updated>
|
<updated>2010-01-10T10:03:10Z</updated>
|
||||||
<author>
|
<author>
|
||||||
<name>cytec</name>
|
<name>Calibre Web</name>
|
||||||
<uri>http://opds-spec.org</uri>
|
<uri>https://github.com/janeczku/calibre-web</uri>
|
||||||
</author>
|
</author>
|
||||||
|
|
||||||
{% for entry in entries %}
|
{% for entry in entries %}
|
||||||
|
|
|
@ -16,11 +16,11 @@
|
||||||
<link rel="search"
|
<link rel="search"
|
||||||
href="{{url_for('feed_osd')}}"
|
href="{{url_for('feed_osd')}}"
|
||||||
type="application/opensearchdescription+xml"/>
|
type="application/opensearchdescription+xml"/>
|
||||||
<title>library</title>
|
<title>Calibre Web</title>
|
||||||
<updated>2010-01-10T10:03:10Z</updated>
|
<updated>2010-01-10T10:03:10Z</updated>
|
||||||
<author>
|
<author>
|
||||||
<name>Spec Writer</name>
|
<name>Calibre Web</name>
|
||||||
<uri>http://opds-spec.org</uri>
|
<uri>https://github.com/janeczku/calibre-web</uri>
|
||||||
</author>
|
</author>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
|
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
|
||||||
<LongName>library</LongName>
|
<LongName>Calibre Web</LongName>
|
||||||
<ShortName>library</ShortName>
|
<ShortName>Calibre Web</ShortName>
|
||||||
<Description>Search the ebook catalog.</Description>
|
<Description>Calibre Web ebook catalog</Description>
|
||||||
<Developer>cytec</Developer>
|
<Developer>janeczku</Developer>
|
||||||
<Contact>iamcytec@googlemail.com</Contact>
|
<Contact>https://github.com/janeczku/calibre-web</Contact>
|
||||||
|
|
||||||
<Url type="text/html"
|
<Url type="text/html"
|
||||||
template="{{url_for('search')}}?query={searchTerms}"/>
|
template="{{url_for('search')}}?query={searchTerms}"/>
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
|
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
|
||||||
<LongName>library</LongName>
|
<LongName>Calibre Web</LongName>
|
||||||
<ShortName>library</ShortName>
|
<ShortName>Calibre Web</ShortName>
|
||||||
<Description>Search the ebook catalog.</Description>
|
<Description>Calibre Web ebook catalog</Description>
|
||||||
<Developer>cytec</Developer>
|
<Developer>janeczku</Developer>
|
||||||
<Contact>iamcytec@googlemail.com</Contact>
|
<Contact>https://github.com/janeczku/calibre-web</Contact>
|
||||||
|
|
||||||
<Url type="text/html"
|
<Url type="text/html"
|
||||||
template="{{url_for('search')}}?query={searchTerms}"/>
|
template="{{url_for('search')}}?query={searchTerms}"/>
|
||||||
|
|
10
cps/web.py
10
cps/web.py
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
import mimetypes
|
import mimetypes
|
||||||
import logging
|
import logging
|
||||||
|
from logging.handlers import RotatingFileHandler
|
||||||
import sys
|
import sys
|
||||||
import textwrap
|
import textwrap
|
||||||
mimetypes.add_type('application/xhtml+xml','.xhtml')
|
mimetypes.add_type('application/xhtml+xml','.xhtml')
|
||||||
|
@ -32,13 +33,12 @@ from shutil import copyfile
|
||||||
|
|
||||||
app = (Flask(__name__))
|
app = (Flask(__name__))
|
||||||
|
|
||||||
# Log only in production mode.
|
formatter = logging.Formatter(
|
||||||
#if not app.debug:
|
"[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s")
|
||||||
file_handler = logging.StreamHandler(sys.stdout)
|
file_handler = RotatingFileHandler(os.path.join(config.LOG_DIR, "calibre-web.log"), maxBytes=10000, backupCount=1)
|
||||||
file_handler.setLevel(logging.INFO)
|
file_handler.setLevel(logging.INFO)
|
||||||
|
file_handler.setFormatter(formatter)
|
||||||
app.logger.addHandler(file_handler)
|
app.logger.addHandler(file_handler)
|
||||||
app.logger_name = 'calibre web'
|
|
||||||
app.logger.setLevel(logging.INFO)
|
|
||||||
app.logger.info('Starting Calibre Web...')
|
app.logger.info('Starting Calibre Web...')
|
||||||
|
|
||||||
Principal(app)
|
Principal(app)
|
||||||
|
|
|
@ -25,9 +25,8 @@ Also available as [Docker image](https://registry.hub.docker.com/u/janeczku/cali
|
||||||
|
|
||||||
## Quick start
|
## Quick start
|
||||||
|
|
||||||
1. Execute the command: `python cps.py` (it will throw an error)
|
1. Open config.ini and set DB_ROOT to the path of the folder where your Calibre library (metadata.db) lives
|
||||||
2. Edit 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
|
||||||
3. If you want to enable public user registration set PUBLIC_REG to 1
|
|
||||||
4. Execute the command: `python cps.py`
|
4. Execute the command: `python cps.py`
|
||||||
5. Point your browser to `http://localhost:8083` or `http://localhost:8083/feed` for the OPDS catalog
|
5. Point your browser to `http://localhost:8083` or `http://localhost:8083/feed` for the OPDS catalog
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user