add config file comments, minor JS refactoring
[ppt-control.git] / ppt_control / config.py
old mode 100644 (file)
new mode 100755 (executable)
index e0416a4..61ff70f
@@ -1,44 +1,52 @@
-from configparser import ConfigParser
-from pkg_resources import Requirement, resource_filename
-
-global prefs
-prefs = None
-
-defaults = {
-        'Main': {
-            'logging': 'debug',
-            'cache': r'''C:\Windows\Temp\ppt-cache''',
-            'cache_format': 'JPG',
-            'cache_timeout': 5*60,
-            'cache_init': True,
-            'blackwhite': 'both'
-        },
-        'HTTP': {
-            'interface': '',
-            'port': 80
-        },
-        'WebSocket': {
-            'interface': '0.0.0.0',
-            'port': 5678
-        }
-}
-
-
-def loadconf(configpaths):
-    """
-    Initial setup for a ConfigParser object. `configpaths` should be a list of
-    configuration files to load (typically only one). To use the generated
-    ConfigParser, use `import logparse.config` and then `config.prefs.get(..)`.
-    The prefs object is returned after creation as a convenience but this method
-    should only be called once per runtime.
-    """
-    prefs = ConfigParser()
-    prefs.read_dict(defaults)
-    try:
-        success = prefs.read(configpaths)
-        print("Loaded {0} config file(s): {1}".format(
-                str(len(success)), str(success)))
-    except Exception as e:
-        print("Error processing config: " + str(e))
-    return prefs
-
+from configparser import ConfigParser\r
+\r
+prefs = None\r
+\r
+defaults = {\r
+        'Main': {\r
+            'logging': 'info',\r
+            'cache': r'''C:\Windows\Temp\ppt-cache''',\r
+            'cache_format': 'JPG',\r
+            'cache_timeout': 5*60,\r
+            'cache_init': True,\r
+            'blackwhite': 'both',\r
+            'refresh': 2,\r
+            'disable_protected': True\r
+        },\r
+        'HTTP': {\r
+            'interface': '',\r
+            'port': 80\r
+        },\r
+        'WebSocket': {\r
+            'interface': '0.0.0.0',\r
+            'port': 5678\r
+        }\r
+}\r
+\r
+\r
+def loadconf(configpaths):\r
+    """\r
+    Initial setup for a ConfigParser object. `configpaths` should be a list of\r
+    configuration files to load (typically only one). To use the generated\r
+    ConfigParser, use `import logparse.config` and then `config.prefs.get(..)`.\r
+    The prefs object is returned after creation as a convenience but this method\r
+    should only be called once per runtime.\r
+    """\r
+    prefs = ConfigParser()\r
+    prefs.read_dict(defaults)\r
+    try:\r
+        success = prefs.read(configpaths)\r
+        print("Loaded {0} config file(s): {1}".format(\r
+                str(len(success)), str(success)))\r
+    except Exception as e:\r
+        print("Error processing config: " + str(e))\r
+    return prefs\r
+\r
+def export_defaults(file):\r
+    """\r
+    Write the default settings to a file object, including comments and with spaces around \r
+    delimeters. This function is intended to be used to populate the config file with defaults\r
+    after installation.\r
+    """\r
+    prefs = loadconf([])\r
+    prefs.write(file, space_around_delimiters=True)\r