openmedialibrary/oml/settings.py

103 lines
3.4 KiB
Python
Raw Normal View History

2014-05-04 17:26:43 +00:00
# -*- coding: utf-8 -*-
import json
import os
2016-01-05 16:14:57 +00:00
from oml.pdict import pdict
from oml.utils import get_user_id
2019-01-15 08:38:42 +00:00
from oml import fulltext
2014-05-04 17:26:43 +00:00
base_dir = os.path.normpath(os.path.join(os.path.abspath(os.path.dirname(__file__)), '..'))
static_path = os.path.join(base_dir, 'static')
2014-08-05 09:47:16 +00:00
updates_path = os.path.normpath(os.path.join(base_dir, '..', 'updates'))
2014-05-04 17:26:43 +00:00
2016-01-18 06:34:20 +00:00
oml_data_path = os.path.join(base_dir, 'config.json')
2014-05-04 17:26:43 +00:00
2016-01-18 06:34:20 +00:00
data_path = os.path.normpath(os.path.join(base_dir, '..', 'data'))
if not os.path.exists(data_path):
config_path = os.path.normpath(os.path.join(base_dir, '..', 'config'))
if os.path.exists(config_path):
data_path = config_path
else:
os.makedirs(data_path)
2014-05-04 17:26:43 +00:00
2016-01-18 06:34:20 +00:00
db_path = os.path.join(data_path, 'data.db')
log_path = os.path.join(data_path, 'debug.log')
2014-05-04 17:26:43 +00:00
2024-06-08 11:39:27 +00:00
ca_key_path = os.path.join(data_path, 'node.ca.key')
ca_cert_path = os.path.join(data_path, 'node.ca.crt')
ssl_cert_path = os.path.join(data_path, 'node.tls.crt')
ssl_key_path = os.path.join(data_path, 'node.tls.key')
2016-01-18 06:34:20 +00:00
if os.path.exists(oml_data_path):
with open(oml_data_path) as fd:
2014-05-04 17:26:43 +00:00
config = json.load(fd)
else:
config = {}
2016-01-18 06:34:20 +00:00
preferences = pdict(os.path.join(data_path, 'preferences.json'), config['user']['preferences'])
ui = pdict(os.path.join(data_path, 'ui.json'), config['user']['ui'])
2014-05-04 17:26:43 +00:00
2016-01-18 06:34:20 +00:00
server = pdict(os.path.join(data_path, 'server.json'))
2014-05-04 17:26:43 +00:00
server_defaults = {
'port': 9842,
'address': '127.0.0.1',
2014-05-04 17:26:43 +00:00
'node_port': 9851,
2019-01-17 10:30:22 +00:00
'public_address': '127.0.0.1',
'public_port': 9852,
2014-05-12 12:57:47 +00:00
'node_address': '',
2014-05-04 17:26:43 +00:00
'extract_text': True,
2014-05-14 23:28:49 +00:00
'localnode_discovery': True,
2019-01-20 11:16:58 +00:00
'release_url': 'https://downloads.openmedialibrary.com/release.json',
2016-02-10 14:02:32 +00:00
'pull_interval': 60000
2014-05-04 17:26:43 +00:00
}
for key in server_defaults:
if key not in server:
server[key] = server_defaults[key]
2016-01-18 06:34:20 +00:00
release = pdict(os.path.join(data_path, 'release.json'))
2014-05-04 17:26:43 +00:00
2024-06-08 11:39:27 +00:00
USER_ID = get_user_id(ssl_key_path, ssl_cert_path, ca_key_path, ca_cert_path)
2017-06-03 20:50:14 +00:00
OML_UPDATE_KEY = 'K55EZpPYbP3X+3mA66cztlw1sSaUMqGwfTDKQyP2qOU'
OML_UPDATE_CERT = '''-----BEGIN CERTIFICATE-----
MIICgzCCAeygAwIBAgIBATANBgkqhkiG9w0BAQsFADAbMRkwFwYDVQQDDBBqc2pt
Z2J4ZjJvZGN6NGNxMB4XDTE1MTEyMzIwMzY1NFoXDTE1MTEyNDIwMzY1NFowGzEZ
MBcGA1UEAwwQanNqbWdieGYyb2RjejRjcTCBnzANBgkqhkiG9w0BAQEFAAOBjQAw
gYkCgYEAuUGGJPqtGaunUSWnnW6FO9WtMZUQkhjewlvZqFE8uQVcgeXVVmarpwjc
E/xFPYtDF5083jJs0UfCcJLpvWT5Y4pW8OCMmQl2JCxBiWsPTIYFtEizPbiZtMBs
xlEBmZRyB1mO/jSZ2ECmKf6yn2CJ4lY67Jlxy5/I963GZ9ZcHdECAwEAAaOB1jCB
0zASBgNVHRMBAf8ECDAGAQH/AgEAMBQGCWCGSAGG+EIBAQEB/wQEAwICBDB7BgNV
HSUBAf8EcTBvBggrBgEFBQcDAQYIKwYBBQUHAwIGCCsGAQUFBwMEBggrBgEFBQcD
CAYKKwYBBAGCNwIBFQYKKwYBBAGCNwIBFgYKKwYBBAGCNwoDAQYKKwYBBAGCNwoD
AwYKKwYBBAGCNwoDBAYJYIZIAYb4QgQBMAsGA1UdDwQEAwIBBjAdBgNVHQ4EFgQU
TJLDBuXThizwUMavAjjcm1mPu74wDQYJKoZIhvcNAQELBQADgYEAEyn9zfdrv7w9
GV47SOE+jJFhrSHsKGf0mKC1JDOJz1l9J1IYSnM7s8BcTBPpum2CJtc6braThH46
qvg7wm/8HUkrHouawZFudwTCGQEuUpe5AEQHGiBkBWiRwR9MIkfqE3aesrhDswb6
vZVVahubX7tZ0O1zUuCpn6E0uzh1aqg=
-----END CERTIFICATE-----'''
2014-05-04 17:26:43 +00:00
if 'modules' in release and 'openmedialibrary' in release['modules']:
MINOR_VERSION = release['modules']['openmedialibrary']['version']
2014-05-04 17:26:43 +00:00
else:
MINOR_VERSION = 'git'
NODE_PROTOCOL = "0.9"
2017-06-03 20:50:14 +00:00
VERSION = "%s.%s" % (NODE_PROTOCOL, MINOR_VERSION)
2014-05-04 17:26:43 +00:00
USER_AGENT = 'OpenMediaLibrary/%s' % VERSION
DEBUG_HTTP = server.get('debug_http', False)
2017-06-14 11:08:22 +00:00
DEBUG_API = server.get('debug_api', False)
2016-01-12 15:00:51 +00:00
2019-01-15 08:38:42 +00:00
FULLTEXT_SUPPORT = fulltext.platform_supported()
if not FULLTEXT_SUPPORT:
config['itemKeys'] = [k for k in config['itemKeys'] if k['id'] != 'fulltext']
2019-02-23 11:41:50 +00:00
DB_VERSION = 20
2024-06-08 11:39:27 +00:00
ID_LENGTH = 56