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 27defloadconf(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) 37try: 38 success = prefs.read(configpaths) 39print("Loaded{0}config file(s):{1}".format( 40str(len(success)),str(success))) 41exceptExceptionas e: 42print("Error processing config: "+str(e)) 43return prefs 44