From 856eda3d709682ec4bea3aa4e5588423065e2dd6 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 12 May 2010 11:49:26 -0400 Subject: [PATCH] Use *_SETTING_SECTION in hooke.plugin/.driver/.ui for section name Avoid constant duplication in code (brittle). --- hooke/driver/__init__.py | 10 +++++++--- hooke/plugin/__init__.py | 10 +++++++--- hooke/ui/__init__.py | 14 ++++++++++---- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/hooke/driver/__init__.py b/hooke/driver/__init__.py index 96bbc61..beaa991 100644 --- a/hooke/driver/__init__.py +++ b/hooke/driver/__init__.py @@ -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, diff --git a/hooke/plugin/__init__.py b/hooke/plugin/__init__.py index 5c4ca51..c8c68ff 100644 --- a/hooke/plugin/__init__.py +++ b/hooke/plugin/__init__.py @@ -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, diff --git a/hooke/ui/__init__.py b/hooke/ui/__init__.py index 3d0a657..778eadf 100644 --- a/hooke/ui/__init__.py +++ b/hooke/ui/__init__.py @@ -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] -- 2.26.2