mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-27 10:44:33 +00:00
Refactor global code in configuration module
This commit is contained in:
parent
d9bebe67f5
commit
f4fe85ae28
88
cfg.py
88
cfg.py
@ -4,39 +4,65 @@ import os
|
|||||||
import ConfigParser
|
import ConfigParser
|
||||||
from ConfigParser import SafeConfigParser
|
from ConfigParser import SafeConfigParser
|
||||||
|
|
||||||
def get_item(parser, section, name):
|
product_name = None
|
||||||
try:
|
box_name = None
|
||||||
return parser.get(section, name)
|
root = None
|
||||||
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
|
file_root = None
|
||||||
print ("Configuration does not contain the {}.{} option.".format(
|
python_root = None
|
||||||
section, name))
|
data_dir = None
|
||||||
raise
|
store_file = None
|
||||||
|
user_db = None
|
||||||
parser = SafeConfigParser(
|
status_log_file = None
|
||||||
defaults={
|
access_log_file = None
|
||||||
'root':os.path.dirname(os.path.realpath(__file__)),
|
pidfile = None
|
||||||
})
|
host = None
|
||||||
parser.read(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'plinth.config'))
|
port = None
|
||||||
|
|
||||||
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')
|
|
||||||
pidfile = get_item(parser, 'Path', 'pidfile')
|
|
||||||
host = get_item(parser, 'Network', 'host')
|
|
||||||
port = int(get_item(parser, 'Network', 'port'))
|
|
||||||
debug = False
|
debug = False
|
||||||
no_daemon = False
|
no_daemon = False
|
||||||
|
session_key = '_username'
|
||||||
|
|
||||||
main_menu = Menu()
|
main_menu = Menu()
|
||||||
|
|
||||||
if store_file.endswith(".sqlite3"):
|
|
||||||
store_file = os.path.splitext(store_file)[0]
|
def read():
|
||||||
if user_db.endswith(".sqlite3"):
|
"""Read configuration"""
|
||||||
user_db = os.path.splitext(user_db)[0]
|
directory = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
parser = SafeConfigParser(
|
||||||
|
defaults={
|
||||||
|
'root': directory,
|
||||||
|
})
|
||||||
|
parser.read(os.path.join(directory, 'plinth.config'))
|
||||||
|
|
||||||
|
config_items = {('Name', 'product_name'),
|
||||||
|
('Name', 'box_name'),
|
||||||
|
('Path', 'root'),
|
||||||
|
('Path', 'file_root'),
|
||||||
|
('Path', 'python_root'),
|
||||||
|
('Path', 'data_dir'),
|
||||||
|
('Path', 'store_file'),
|
||||||
|
('Path', 'user_db'),
|
||||||
|
('Path', 'status_log_file'),
|
||||||
|
('Path', 'access_log_file'),
|
||||||
|
('Path', 'pidfile'),
|
||||||
|
('Network', 'host'),
|
||||||
|
('Network', 'port')}
|
||||||
|
|
||||||
|
for section, name in config_items:
|
||||||
|
try:
|
||||||
|
value = parser.get(section, name)
|
||||||
|
globals()[name] = value
|
||||||
|
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
|
||||||
|
print ('Configuration does not contain the {}.{} option.'
|
||||||
|
.format(section, name))
|
||||||
|
raise
|
||||||
|
|
||||||
|
global port # pylint: disable-msg=W0603
|
||||||
|
port = int(port)
|
||||||
|
|
||||||
|
global store_file # pylint: disable-msg=W0603
|
||||||
|
if store_file.endswith(".sqlite3"):
|
||||||
|
store_file = os.path.splitext(store_file)[0]
|
||||||
|
|
||||||
|
global user_db # pylint: disable-msg=W0603
|
||||||
|
if user_db.endswith(".sqlite3"):
|
||||||
|
user_db = os.path.splitext(user_db)[0]
|
||||||
|
|||||||
@ -6,8 +6,6 @@ from passlib.exc import PasswordSizeError
|
|||||||
import cfg
|
import cfg
|
||||||
from model import User
|
from model import User
|
||||||
|
|
||||||
cfg.session_key = '_username'
|
|
||||||
|
|
||||||
|
|
||||||
def add_user(username, passphrase, name='', email='', expert=False):
|
def add_user(username, passphrase, name='', email='', expert=False):
|
||||||
"""Add a new user with specified username and passphrase.
|
"""Add a new user with specified username and passphrase.
|
||||||
|
|||||||
@ -3,7 +3,6 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import cfg
|
|
||||||
import django.conf
|
import django.conf
|
||||||
import django.core.wsgi
|
import django.core.wsgi
|
||||||
|
|
||||||
@ -11,6 +10,7 @@ import cherrypy
|
|||||||
from cherrypy import _cpserver
|
from cherrypy import _cpserver
|
||||||
from cherrypy.process.plugins import Daemonizer
|
from cherrypy.process.plugins import Daemonizer
|
||||||
|
|
||||||
|
import cfg
|
||||||
import module_loader
|
import module_loader
|
||||||
import plugin_mount
|
import plugin_mount
|
||||||
import service
|
import service
|
||||||
@ -148,6 +148,8 @@ def main():
|
|||||||
"""Intialize and start the application"""
|
"""Intialize and start the application"""
|
||||||
parse_arguments()
|
parse_arguments()
|
||||||
|
|
||||||
|
cfg.read()
|
||||||
|
|
||||||
setup_logging()
|
setup_logging()
|
||||||
|
|
||||||
service.init()
|
service.init()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user