/usr/share/pyshared/trytond/config.py is in tryton-server 2.2.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | #This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
import ConfigParser, os, sys
def get_hostname(netloc):
if '[' in netloc and ']' in netloc:
return netloc.split(']')[0][1:]
elif ':' in netloc:
return netloc.split(':')[0]
else:
return netloc
def get_port(netloc, protocol):
netloc = netloc.split(']')[-1]
if ':' in netloc:
return int(netloc.split(':')[1])
else:
return {
'jsonrpc': 8000,
'xmlrpc': 8069,
'webdav': 8080,
}.get(protocol)
class ConfigManager(object):
def __init__(self, fname=None):
self.options = {
'hostname': None,
'jsonrpc': [('localhost', 8000)],
'ssl_jsonrpc': False,
'xmlrpc': [],
'ssl_xmlrpc': False,
'jsondata_path': '/var/www/localhost/tryton',
'webdav': [],
'ssl_webdav': False,
'db_type': 'postgresql',
'db_host': False,
'db_port': False,
'db_name': False,
'db_user': False,
'db_password': False,
'db_minconn': 1,
'db_maxconn': 64,
'pg_path': None,
'admin_passwd': 'admin',
'verbose': False,
'debug_mode': False,
'pidfile': None,
'logfile': None,
'privatekey': '/etc/ssl/trytond/server.key',
'certificate': '/etc/ssl/trytond/server.pem',
'smtp_server': 'localhost',
'smtp_port': 25,
'smtp_ssl': False,
'smtp_tls': False,
'smtp_user': False,
'smtp_password': False,
'data_path': '/var/lib/trytond',
'multi_server': False,
'session_timeout': 600,
'psyco': False,
'auto_reload': True,
'prevent_dblist': False,
'init': {},
'update': {},
'cron': True,
'unoconv': 'pipe,name=trytond;urp;StarOffice.ComponentContext',
'retry': 5,
}
self.configfile = None
def update_cmdline(self, cmdline_options):
self.options.update(cmdline_options)
# Verify that we want to log or not, if not the output will go to stdout
if self.options['logfile'] in ('None', 'False'):
self.options['logfile'] = False
# the same for the pidfile
if self.options['pidfile'] in ('None', 'False'):
self.options['pidfile'] = False
if self.options['data_path'] in ('None', 'False'):
self.options['data_path'] = False
def update_etc(self, configfile=None):
if configfile is None:
prefixdir = os.path.abspath(os.path.normpath(os.path.join(
os.path.dirname(sys.prefix), '..')))
configfile = os.path.join(prefixdir, 'etc', 'trytond.conf')
if not os.path.isfile(configfile):
configdir = os.path.abspath(os.path.normpath(os.path.join(
os.path.dirname(__file__), '..')))
configfile = os.path.join(configdir, 'etc', 'trytond.conf')
if not os.path.isfile(configfile):
configfile = None
self.configfile = configfile
if not self.configfile:
return
parser = ConfigParser.ConfigParser()
with open(self.configfile) as fp:
parser.readfp(fp)
for (name, value) in parser.items('options'):
if value == 'True' or value == 'true':
value = True
if value == 'False' or value == 'false':
value = False
if name in ('xmlrpc', 'jsonrpc', 'webdav'):
value = [(get_hostname(netloc).replace('*', ''),
get_port(netloc, name)) for netloc in value.split(',')]
self.options[name] = value
def get(self, key, default=None):
return self.options.get(key, default)
def __setitem__(self, key, value):
self.options[key] = value
def __getitem__(self, key):
return self.options[key]
CONFIG = ConfigManager()
|