74df1f3acdff43f2eb9c3c206d581e0db9d61521
1from configparser import ConfigParser
2from pkg_resources import Requirement, resource_filename
3
4global prefs
5prefs = None
6
7defaults = {
8 'Main': {
9 'logging': 'debug',
10 'cache': r'''C:\Windows\Temp\ppt-cache''',
11 'cache_format': 'JPG',
12 'cache_timeout': 5*60,
13 'cache_init': True,
14 'blackwhite': 'both',
15 'refresh': 2,
16 'disable_protected': False
17 },
18 'HTTP': {
19 'interface': '',
20 'port': 80
21 },
22 'WebSocket': {
23 'interface': '0.0.0.0',
24 'port': 5678
25 }
26}
27
28
29def loadconf(configpaths):
30 """
31 Initial setup for a ConfigParser object. `configpaths` should be a list of
32 configuration files to load (typically only one). To use the generated
33 ConfigParser, use `import logparse.config` and then `config.prefs.get(..)`.
34 The prefs object is returned after creation as a convenience but this method
35 should only be called once per runtime.
36 """
37 prefs = ConfigParser()
38 prefs.read_dict(defaults)
39 try:
40 success = prefs.read(configpaths)
41 print("Loaded {0} config file(s): {1}".format(
42 str(len(success)), str(success)))
43 except Exception as e:
44 print("Error processing config: " + str(e))
45 return prefs
46