Sunil Mohan Adapa 42d05bfe1f Use Django models to store variables
- Remove dependency on withsqlite and use Django models.
  This avoids depending on a module that is not available in PyPi.
  Withsqlite does not have Python3 support. It does not work when
  we choose a different database backend. Atleast partly duplicates
  what Django models are meant for.

- Check and update database schema on every run so that
  newly added modules can add tables and old ones can update.
2014-09-10 12:35:35 +05:30

73 lines
1.9 KiB
Python

from plinth.menu import Menu
import os
import ConfigParser
from ConfigParser import SafeConfigParser
product_name = None
box_name = None
root = None
file_root = None
data_dir = None
store_file = None
actions_dir = None
doc_dir = None
status_log_file = None
access_log_file = None
pidfile = None
host = None
port = None
debug = False
no_daemon = False
server_dir = '/'
main_menu = Menu()
CONFIG_FILE = None
DEFAULT_CONFIG_FILE = '/etc/plinth/plinth.config'
DEFAULT_ROOT = '/'
def read():
"""Read configuration"""
global CONFIG_FILE # pylint: disable-msg=W0603
if os.path.isfile(DEFAULT_CONFIG_FILE):
CONFIG_FILE = DEFAULT_CONFIG_FILE
directory = DEFAULT_ROOT
else:
directory = os.path.dirname(os.path.realpath(__file__))
directory = os.path.join(directory, '..')
CONFIG_FILE = os.path.join(directory, 'plinth.config')
parser = SafeConfigParser(
defaults={
'root': os.path.realpath(directory),
})
parser.read(CONFIG_FILE)
config_items = {('Name', 'product_name'),
('Name', 'box_name'),
('Path', 'root'),
('Path', 'file_root'),
('Path', 'data_dir'),
('Path', 'store_file'),
('Path', 'actions_dir'),
('Path', 'doc_dir'),
('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)