mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
Simplify config loading.
These changes should make it easier to customize standard Plinth file locations for other distributions going forward. Most of the defaults have been removed from *cfg.py*: we now assume that your plinth.config file contains all the data we need. This may turn out to be a bad decision (not everybody retains a copy of the original config file). I've also reorganized *plinth.sample.config* to separate the directories from the files they're storing. This should be the file distributions patch in order to customize file locations per their preferred file organization.
This commit is contained in:
parent
49ce1b9389
commit
ae3d61bec4
50
cfg.py
50
cfg.py
@ -2,39 +2,35 @@ from menu import Menu
|
||||
import os
|
||||
|
||||
from ConfigParser import SafeConfigParser
|
||||
|
||||
def get_item(parser, section, name):
|
||||
try:
|
||||
return parser.get(section, name)
|
||||
except (SafeConfigParser.NoSectionError, SafeConfigParser.NoOptionError):
|
||||
print ("The config file {} does not contain the {}.{} option.".format(
|
||||
parser[0], section, name))
|
||||
raise
|
||||
|
||||
parser = SafeConfigParser(
|
||||
defaults={
|
||||
'root':os.path.dirname(os.path.realpath(__file__)),
|
||||
'product_name':"",
|
||||
'box_name':"",
|
||||
'file_root':"",
|
||||
'python_root':"",
|
||||
'data_dir':"",
|
||||
'store_file':"",
|
||||
'user_db':"",
|
||||
'status_log_file':"",
|
||||
'access_log_file':"",
|
||||
'users_dir':"",
|
||||
'host':"127.0.0.1",
|
||||
'pidfile':"",
|
||||
'port':"",
|
||||
})
|
||||
parser.read(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'plinth.config'))
|
||||
|
||||
product_name = parser.get('Name', 'product_name')
|
||||
box_name = parser.get('Name', 'box_name')
|
||||
root = parser.get('Path', 'root')
|
||||
file_root = parser.get('Path', 'file_root')
|
||||
python_root = parser.get('Path', 'python_root')
|
||||
data_dir = parser.get('Path', 'data_dir')
|
||||
store_file = parser.get('Path', 'store_file')
|
||||
user_db = parser.get('Path', 'user_db')
|
||||
status_log_file = parser.get('Path', 'status_log_file')
|
||||
access_log_file = parser.get('Path', 'access_log_file')
|
||||
users_dir = parser.get('Path', 'users_dir')
|
||||
pidfile = parser.get('Path', 'pidfile')
|
||||
host = parser.get('Network', 'host')
|
||||
port = int(parser.get('Network', 'port'))
|
||||
product_name = get_item(parser, 'Name', 'product_name')
|
||||
box_name = get_item(parser, 'Name', 'box_name')
|
||||
root = get_item(parser, 'Path', 'root')
|
||||
file_root = get_item(parser, 'Path', 'file_root')
|
||||
python_root = get_item(parser, 'Path', 'python_root')
|
||||
data_dir = get_item(parser, 'Path', 'data_dir')
|
||||
store_file = get_item(parser, 'Path', 'store_file')
|
||||
user_db = get_item(parser, 'Path', 'user_db')
|
||||
status_log_file = get_item(parser, 'Path', 'status_log_file')
|
||||
access_log_file = get_item(parser, 'Path', 'access_log_file')
|
||||
users_dir = get_item(parser, 'Path', 'users_dir')
|
||||
pidfile = get_item(parser, 'Path', 'pidfile')
|
||||
host = get_item(parser, 'Network', 'host')
|
||||
port = int(get_item(parser, 'Network', 'port'))
|
||||
|
||||
html_root = None
|
||||
main_menu = Menu()
|
||||
|
||||
@ -3,17 +3,22 @@ product_name = Plinth
|
||||
box_name = FreedomBox
|
||||
|
||||
[Path]
|
||||
# directory locations
|
||||
file_root = %(root)s
|
||||
python_root = %(root)s
|
||||
data_dir = %(file_root)s/data
|
||||
store_file = %(data_dir)s/store.sqlite3
|
||||
user_db = %(data_dir)s/users
|
||||
status_log_file = %(data_dir)s/status.log
|
||||
access_log_file = %(data_dir)s/access.log
|
||||
log_dir = %(data_dir)s
|
||||
pid_dir = %(data_dir)s
|
||||
python_root = %(file_root)s
|
||||
users_dir = %(data_dir)s/users
|
||||
pidfile = %(data_dir)s/pidfile.pid
|
||||
server_dir = plinth/
|
||||
|
||||
# file locations
|
||||
store_file = %(data_dir)s/store.sqlite3
|
||||
user_db = %(users_dir)s
|
||||
status_log_file = %(log_dir)s/status.log
|
||||
access_log_file = %(log_dir)s/access.log
|
||||
pidfile = %(pid_dir)s/pidfile.pid
|
||||
|
||||
[Network]
|
||||
host = 127.0.0.1
|
||||
port = 8000
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user