2019-07-13 18:45:48 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# This file is part of the Calibre-Web (https://github.com/janeczku/calibre-web)
|
|
|
|
# Copyright (C) 2019 OzzieIsaacs, pwr
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
from __future__ import division, print_function, unicode_literals
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
from collections import namedtuple
|
2021-07-26 05:52:01 +00:00
|
|
|
from sqlalchemy import __version__ as sql_version
|
|
|
|
|
|
|
|
sqlalchemy_version2 = ([int(x) for x in sql_version.split('.')] >= [2,0,0])
|
2019-07-13 18:45:48 +00:00
|
|
|
|
2021-02-07 08:20:37 +00:00
|
|
|
# if installed via pip this variable is set to true (empty file with name .HOMEDIR present)
|
|
|
|
HOME_CONFIG = os.path.isfile(os.path.join(os.path.dirname(os.path.abspath(__file__)), '.HOMEDIR'))
|
|
|
|
|
|
|
|
#In executables updater is not available, so variable is set to False there
|
2021-02-06 08:42:27 +00:00
|
|
|
UPDATER_AVAILABLE = True
|
2019-07-13 18:45:48 +00:00
|
|
|
|
|
|
|
# Base dir is parent of current file, necessary if called from different folder
|
|
|
|
if sys.version_info < (3, 0):
|
|
|
|
BASE_DIR = os.path.abspath(os.path.join(
|
|
|
|
os.path.dirname(os.path.abspath(__file__)),os.pardir)).decode('utf-8')
|
|
|
|
else:
|
|
|
|
BASE_DIR = os.path.abspath(os.path.join(
|
|
|
|
os.path.dirname(os.path.abspath(__file__)),os.pardir))
|
|
|
|
STATIC_DIR = os.path.join(BASE_DIR, 'cps', 'static')
|
|
|
|
TEMPLATES_DIR = os.path.join(BASE_DIR, 'cps', 'templates')
|
|
|
|
TRANSLATIONS_DIR = os.path.join(BASE_DIR, 'cps', 'translations')
|
2021-09-20 03:45:19 +00:00
|
|
|
|
|
|
|
# Cache dir - use CACHE_DIR environment variable, otherwise use the default directory: cps/cache
|
|
|
|
DEFAULT_CACHE_DIR = os.path.join(BASE_DIR, 'cps', 'cache')
|
|
|
|
CACHE_DIR = os.environ.get("CACHE_DIR", DEFAULT_CACHE_DIR)
|
2019-07-14 06:18:45 +00:00
|
|
|
|
|
|
|
if HOME_CONFIG:
|
|
|
|
home_dir = os.path.join(os.path.expanduser("~"),".calibre-web")
|
|
|
|
if not os.path.exists(home_dir):
|
|
|
|
os.makedirs(home_dir)
|
|
|
|
CONFIG_DIR = os.environ.get('CALIBRE_DBPATH', home_dir)
|
|
|
|
else:
|
2021-01-18 20:24:13 +00:00
|
|
|
CONFIG_DIR = os.environ.get('CALIBRE_DBPATH', BASE_DIR)
|
2019-07-13 18:45:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
ROLE_USER = 0 << 0
|
|
|
|
ROLE_ADMIN = 1 << 0
|
|
|
|
ROLE_DOWNLOAD = 1 << 1
|
|
|
|
ROLE_UPLOAD = 1 << 2
|
|
|
|
ROLE_EDIT = 1 << 3
|
|
|
|
ROLE_PASSWD = 1 << 4
|
|
|
|
ROLE_ANONYMOUS = 1 << 5
|
|
|
|
ROLE_EDIT_SHELFS = 1 << 6
|
|
|
|
ROLE_DELETE_BOOKS = 1 << 7
|
|
|
|
ROLE_VIEWER = 1 << 8
|
|
|
|
|
|
|
|
ALL_ROLES = {
|
|
|
|
"admin_role": ROLE_ADMIN,
|
|
|
|
"download_role": ROLE_DOWNLOAD,
|
|
|
|
"upload_role": ROLE_UPLOAD,
|
|
|
|
"edit_role": ROLE_EDIT,
|
|
|
|
"passwd_role": ROLE_PASSWD,
|
|
|
|
"edit_shelf_role": ROLE_EDIT_SHELFS,
|
|
|
|
"delete_role": ROLE_DELETE_BOOKS,
|
|
|
|
"viewer_role": ROLE_VIEWER,
|
|
|
|
}
|
|
|
|
|
|
|
|
DETAIL_RANDOM = 1 << 0
|
|
|
|
SIDEBAR_LANGUAGE = 1 << 1
|
|
|
|
SIDEBAR_SERIES = 1 << 2
|
|
|
|
SIDEBAR_CATEGORY = 1 << 3
|
|
|
|
SIDEBAR_HOT = 1 << 4
|
|
|
|
SIDEBAR_RANDOM = 1 << 5
|
|
|
|
SIDEBAR_AUTHOR = 1 << 6
|
|
|
|
SIDEBAR_BEST_RATED = 1 << 7
|
|
|
|
SIDEBAR_READ_AND_UNREAD = 1 << 8
|
|
|
|
SIDEBAR_RECENT = 1 << 9
|
|
|
|
SIDEBAR_SORTED = 1 << 10
|
|
|
|
MATURE_CONTENT = 1 << 11
|
|
|
|
SIDEBAR_PUBLISHER = 1 << 12
|
|
|
|
SIDEBAR_RATING = 1 << 13
|
|
|
|
SIDEBAR_FORMAT = 1 << 14
|
2020-01-25 23:29:17 +00:00
|
|
|
SIDEBAR_ARCHIVED = 1 << 15
|
2020-09-27 14:00:17 +00:00
|
|
|
SIDEBAR_DOWNLOAD = 1 << 16
|
|
|
|
SIDEBAR_LIST = 1 << 17
|
2019-07-13 18:45:48 +00:00
|
|
|
|
2021-02-13 12:17:02 +00:00
|
|
|
sidebar_settings = {
|
|
|
|
"detail_random": DETAIL_RANDOM,
|
|
|
|
"sidebar_language": SIDEBAR_LANGUAGE,
|
|
|
|
"sidebar_series": SIDEBAR_SERIES,
|
|
|
|
"sidebar_category": SIDEBAR_CATEGORY,
|
|
|
|
"sidebar_random": SIDEBAR_RANDOM,
|
|
|
|
"sidebar_author": SIDEBAR_AUTHOR,
|
|
|
|
"sidebar_best_rated": SIDEBAR_BEST_RATED,
|
|
|
|
"sidebar_read_and_unread": SIDEBAR_READ_AND_UNREAD,
|
|
|
|
"sidebar_recent": SIDEBAR_RECENT,
|
|
|
|
"sidebar_sorted": SIDEBAR_SORTED,
|
|
|
|
"sidebar_publisher": SIDEBAR_PUBLISHER,
|
|
|
|
"sidebar_rating": SIDEBAR_RATING,
|
|
|
|
"sidebar_format": SIDEBAR_FORMAT,
|
|
|
|
"sidebar_archived": SIDEBAR_ARCHIVED,
|
|
|
|
"sidebar_download": SIDEBAR_DOWNLOAD,
|
|
|
|
"sidebar_list": SIDEBAR_LIST,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-24 14:56:08 +00:00
|
|
|
ADMIN_USER_ROLES = sum(r for r in ALL_ROLES.values()) & ~ROLE_ANONYMOUS
|
2020-05-09 08:58:59 +00:00
|
|
|
ADMIN_USER_SIDEBAR = (SIDEBAR_LIST << 1) - 1
|
2019-07-13 18:45:48 +00:00
|
|
|
|
|
|
|
UPDATE_STABLE = 0 << 0
|
|
|
|
AUTO_UPDATE_STABLE = 1 << 0
|
|
|
|
UPDATE_NIGHTLY = 1 << 1
|
|
|
|
AUTO_UPDATE_NIGHTLY = 1 << 2
|
|
|
|
|
|
|
|
LOGIN_STANDARD = 0
|
|
|
|
LOGIN_LDAP = 1
|
2019-07-21 06:10:23 +00:00
|
|
|
LOGIN_OAUTH = 2
|
2020-04-17 16:16:21 +00:00
|
|
|
|
|
|
|
LDAP_AUTH_ANONYMOUS = 0
|
|
|
|
LDAP_AUTH_UNAUTHENTICATE = 1
|
|
|
|
LDAP_AUTH_SIMPLE = 0
|
2019-07-13 18:45:48 +00:00
|
|
|
|
2019-12-29 12:54:52 +00:00
|
|
|
DEFAULT_MAIL_SERVER = "mail.example.org"
|
2019-07-13 18:45:48 +00:00
|
|
|
|
2021-03-15 12:52:44 +00:00
|
|
|
DEFAULT_PASSWORD = "admin123" # nosec
|
2019-07-13 18:45:48 +00:00
|
|
|
DEFAULT_PORT = 8083
|
2020-04-27 10:03:54 +00:00
|
|
|
env_CALIBRE_PORT = os.environ.get("CALIBRE_PORT", DEFAULT_PORT)
|
2019-07-13 18:45:48 +00:00
|
|
|
try:
|
|
|
|
DEFAULT_PORT = int(env_CALIBRE_PORT)
|
|
|
|
except ValueError:
|
|
|
|
print('Environment variable CALIBRE_PORT has invalid value (%s), faling back to default (8083)' % env_CALIBRE_PORT)
|
|
|
|
del env_CALIBRE_PORT
|
|
|
|
|
|
|
|
|
2020-06-08 19:57:52 +00:00
|
|
|
EXTENSIONS_AUDIO = {'mp3', 'mp4', 'ogg', 'opus', 'wav', 'flac', 'm4a', 'm4b'}
|
2020-10-16 15:51:59 +00:00
|
|
|
EXTENSIONS_CONVERT_FROM = ['pdf', 'epub', 'mobi', 'azw3', 'docx', 'rtf', 'fb2', 'lit', 'lrf', 'txt', 'htmlz', 'rtf', 'odt','cbz','cbr']
|
|
|
|
EXTENSIONS_CONVERT_TO = ['pdf', 'epub', 'mobi', 'azw3', 'docx', 'rtf', 'fb2', 'lit', 'lrf', 'txt', 'htmlz', 'rtf', 'odt']
|
2020-05-17 14:22:58 +00:00
|
|
|
EXTENSIONS_UPLOAD = {'txt', 'pdf', 'epub', 'kepub', 'mobi', 'azw', 'azw3', 'cbr', 'cbz', 'cbt', 'djvu', 'prc', 'doc', 'docx',
|
2020-06-08 19:57:52 +00:00
|
|
|
'fb2', 'html', 'rtf', 'lit', 'odt', 'mp3', 'mp4', 'ogg', 'opus', 'wav', 'flac', 'm4a', 'm4b'}
|
2019-07-13 18:45:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
def has_flag(value, bit_flag):
|
|
|
|
return bit_flag == (bit_flag & (value or 0))
|
|
|
|
|
|
|
|
def selected_roles(dictionary):
|
|
|
|
return sum(v for k, v in ALL_ROLES.items() if k in dictionary)
|
|
|
|
|
|
|
|
|
|
|
|
# :rtype: BookMeta
|
|
|
|
BookMeta = namedtuple('BookMeta', 'file_path, extension, title, author, cover, description, tags, series, '
|
2021-03-17 18:06:51 +00:00
|
|
|
'series_id, languages, publisher')
|
2019-07-13 18:45:48 +00:00
|
|
|
|
2021-05-22 12:57:55 +00:00
|
|
|
STABLE_VERSION = {'version': '0.6.13 Beta'}
|
2019-07-13 18:45:48 +00:00
|
|
|
|
|
|
|
NIGHTLY_VERSION = {}
|
|
|
|
NIGHTLY_VERSION[0] = '$Format:%H$'
|
|
|
|
NIGHTLY_VERSION[1] = '$Format:%cI$'
|
|
|
|
# NIGHTLY_VERSION[0] = 'bb7d2c6273ae4560e83950d36d64533343623a57'
|
|
|
|
# NIGHTLY_VERSION[1] = '2018-09-09T10:13:08+02:00'
|
|
|
|
|
|
|
|
|
|
|
|
# clean-up the module namespace
|
|
|
|
del sys, os, namedtuple
|