Merge simple config changes.

This commit is contained in:
Nick Daly 2013-11-05 22:45:05 -06:00
commit 1eb5dde1f7
2 changed files with 34 additions and 33 deletions

50
cfg.py
View File

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

View File

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