e0416a498084b13889d14a38d30be86d81032bf2
   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        },
  16        'HTTP': {
  17            'interface': '',
  18            'port': 80
  19        },
  20        'WebSocket': {
  21            'interface': '0.0.0.0',
  22            'port': 5678
  23        }
  24}
  25
  26
  27def loadconf(configpaths):
  28    """
  29    Initial setup for a ConfigParser object. `configpaths` should be a list of
  30    configuration files to load (typically only one). To use the generated
  31    ConfigParser, use `import logparse.config` and then `config.prefs.get(..)`.
  32    The prefs object is returned after creation as a convenience but this method
  33    should only be called once per runtime.
  34    """
  35    prefs = ConfigParser()
  36    prefs.read_dict(defaults)
  37    try:
  38        success = prefs.read(configpaths)
  39        print("Loaded {0} config file(s): {1}".format(
  40                str(len(success)), str(success)))
  41    except Exception as e:
  42        print("Error processing config: " + str(e))
  43    return prefs
  44