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