Use *_SETTING_SECTION in hooke.plugin/.driver/.ui for section name
authorW. Trevor King <wking@drexel.edu>
Wed, 12 May 2010 15:49:26 +0000 (11:49 -0400)
committerW. Trevor King <wking@drexel.edu>
Wed, 12 May 2010 15:49:26 +0000 (11:49 -0400)
Avoid constant duplication in code (brittle).

hooke/driver/__init__.py
hooke/plugin/__init__.py
hooke/ui/__init__.py

index 96bbc612f6f4ae2637347bcf879f573073b03b5c..beaa991da4d41296b1c2a75c3f19cf7bafb061a9 100644 (file)
@@ -25,6 +25,10 @@ DRIVER_MODULES = [
 default.  TODO: autodiscovery
 """
 
+DRIVER_SETTING_SECTION = 'drivers'
+"""Name of the config section which controls driver selection.
+"""
+
 
 class Driver(object):
     """Base class for file format drivers.
@@ -76,15 +80,15 @@ DRIVER_GRAPH = construct_graph(
 """
 
 def default_settings():
-    settings = [Setting(
-            'drivers', help='Enable/disable default drivers.')]
+    settings = [Setting(DRIVER_SETTING_SECTION,
+                        help='Enable/disable default drivers.')]
     for dnode in DRIVER_GRAPH:
         driver = dnode.data
         default_include = [di for mod_name,di in DRIVER_MODULES
                            if mod_name == driver.name][0]
         help = driver.__doc__.split('\n', 1)[0]
         settings.append(Setting(
-                section='drivers',
+                section=DRIVER_SETTING_SECTION,
                 option=driver.name,
                 value=str(default_include),
                 help=help,
index 5c4ca51572945e3b948e0c7f5b85ea5835d6ad16..c8c68fffe74b960498cf0819fd1dd9f172fbbf44 100644 (file)
@@ -45,6 +45,10 @@ BUILTIN_MODULES = [
 """List of builtin modules.  TODO: autodiscovery
 """
 
+PLUGIN_SETTING_SECTION = 'plugins'
+"""Name of the config section which controls plugin selection.
+"""
+
 
 # Plugins and settings
 
@@ -169,8 +173,8 @@ PLUGIN_GRAPH = construct_graph(
 """
 
 def default_settings():
-    settings = [Setting(
-            'plugins', help='Enable/disable default plugins.')]
+    settings = [Setting(PLUGIN_SETTING_SECTION,
+                        help='Enable/disable default plugins.')]
     for pnode in PLUGIN_GRAPH:
         if pnode.data.name in BUILTIN_MODULES:
             continue # builtin inclusion is not optional
@@ -179,7 +183,7 @@ def default_settings():
                            if mod_name == plugin.name][0]
         help = 'Commands: ' + ', '.join([c.name for c in plugin.commands()])
         settings.append(Setting(
-                section='plugins',
+                section=PLUGIN_SETTING_SECTION,
                 option=plugin.name,
                 value=str(default_include),
                 help=help,
index 3d0a65762d589efb7a1270644ef036da4ff5fda0..778eadfab8d3b6e27bd16f0d836e53b556701da9 100644 (file)
@@ -16,6 +16,10 @@ USER_INTERFACE_MODULES = [
 """List of user interface modules.  TODO: autodiscovery
 """
 
+USER_INTERFACE_SETTING_SECTION = 'user interfaces'
+"""Name of the config section which controls UI selection.
+"""
+
 class QueueMessage (object):
     def __str__(self):
         return self.__class__.__name__
@@ -38,7 +42,7 @@ class UserInterface (object):
     """
     def __init__(self, name):
         self.name = name
-        self.setting_section = '%s ui' % self.name
+        self.setting_section = '%s user interface' % self.name
         self.config = {}
     
     def default_settings(self):
@@ -102,17 +106,19 @@ instances keyed by `.name`.
 """
 
 def default_settings():
-    settings = [Setting('UIs', help='Select the user interface (only one).')]
+    settings = [Setting(USER_INTERFACE_SETTING_SECTION,
+                        help='Select the user interface (only one).')]
     for i,ui in enumerate(USER_INTERFACES.values()):
         help = ui.__doc__.split('\n', 1)[0]
-        settings.append(Setting('UIs', ui.name, str(i==0), help=help))
+        settings.append(Setting(USER_INTERFACE_SETTING_SECTION,
+                                ui.name, str(i==0), help=help))
         # i==0 to enable the first by default
     for ui in USER_INTERFACES.values():
         settings.extend(ui.default_settings())
     return settings
 
 def load_ui(config):
-    uis = [c for c,v in config.items('UIs') if v == 'True']
+    uis = [c for c,v in config.items(USER_INTERFACE_SETTING_SECTION) if v == 'True']
     assert len(uis) == 1, 'Can only select one UI, not %d: %s' % (len(uis),uis)
     ui_name = uis[0]
     ui = USER_INTERFACES[ui_name]