def __init__(self, name, unvalidated_tree, sections, config): """Fix up settings that depend on the [DXR] section or have inter-setting dependencies. (schema can't do multi-setting validation yet, and configobj can't do cross-section interpolation.) Add a ``config`` attr to trees as a shortcut back to the [DXR] section and a ``name`` attr to save cumbersome tuple unpacks in callers. """ self.config = config self.name = name schema = Schema({ Optional('build_command', default='make -j {workers}'): basestring, Optional('clean_command', default='make clean'): basestring, Optional('description', default=''): basestring, Optional('disabled_plugins', default=plugin_list('')): Plugins, Optional('enabled_plugins', default=plugin_list('*')): Plugins, Optional('es_index', default=config.es_index): basestring, Optional('es_shards', default=5): Use(int, error='"es_shards" must be an integer.'), Optional('ignore_patterns', default=['.hg', '.git', 'CVS', '.svn', '.bzr', '.deps', '.libs', '.DS_Store', '.nfs*', '*~', '._*']): WhitespaceList, Optional('object_folder', default=None): AbsPath, 'source_folder': AbsPath, Optional('source_encoding', default='utf-8'): basestring, Optional('temp_folder', default=None): AbsPath, Optional('p4web_url', default='http://p4web/'): basestring, Optional('workers', default=None): WORKERS_VALIDATOR, Optional(basestring): dict}) tree = schema.validate(unvalidated_tree) if tree['temp_folder'] is None: tree['temp_folder'] = config.temp_folder if tree['object_folder'] is None: tree['object_folder'] = tree['source_folder'] if tree['workers'] is None: tree['workers'] = config.workers # Convert enabled_plugins to a list of plugins: if tree['disabled_plugins'].is_all: # * doesn't really mean "all" in a tree. It means "everything the # [DXR] section enabled". tree['disabled_plugins'] = config.enabled_plugins else: # Add anything globally disabled to our local disabled list: tree['disabled_plugins'].extend(p for p in config.disabled_plugins if p not in tree['disabled_plugins']) if tree['enabled_plugins'].is_all: tree['enabled_plugins'] = [p for p in config.enabled_plugins if p not in tree['disabled_plugins']] tree['enabled_plugins'].insert(0, core_plugin()) # Split ignores into paths and filenames: tree['ignore_paths'] = [i for i in tree['ignore_patterns'] if i.startswith('/')] tree['ignore_filenames'] = [i for i in tree['ignore_patterns'] if not i.startswith('/')] # Delete misleading, useless, or raw values people shouldn't use: del tree['ignore_patterns'] del tree['disabled_plugins'] # Validate plugin config: enableds_with_all_optional_config = set( p for p in tree['enabled_plugins'] if all(isinstance(k, Optional) for k in p.config_schema.iterkeys())) plugin_schema = Schema(merge( dict((Optional(name) if plugin in enableds_with_all_optional_config or plugin not in tree['enabled_plugins'] else name, plugin.config_schema) for name, plugin in all_plugins_but_core().iteritems()), # And whatever isn't a plugin section, that we don't care about: {object: object})) # Insert empty missing sections for enabled plugins with entirely # optional config so their defaults get filled in. (Don't insert them # if the plugin has any required options; then we wouldn't produce the # proper error message about the section being absent.) for plugin in enableds_with_all_optional_config: tree.setdefault(plugin.name, {}) tree = plugin_schema.validate(tree) super(TreeConfig, self).__init__(tree)
def __init__(self, name, unvalidated_tree, sections, config): """Fix up settings that depend on the [DXR] section or have inter-setting dependencies. (schema can't do multi-setting validation yet, and configobj can't do cross-section interpolation.) Add a ``config`` attr to trees as a shortcut back to the [DXR] section and a ``name`` attr to save cumbersome tuple unpacks in callers. """ self.config = config self.name = name schema = Schema({ Optional('build_command', default='make -j {workers}'): basestring, Optional('clean_command', default='make clean'): basestring, Optional('description', default=''): basestring, Optional('disabled_plugins', default=plugin_list('')): Plugins, Optional('enabled_plugins', default=plugin_list('*')): Plugins, Optional('es_index', default=config.es_index): basestring, Optional('es_shards', default=5): Use(int, error='"es_shards" must be an integer.'), Optional('ignore_patterns', default=[ '.hg', '.git', 'CVS', '.svn', '.bzr', '.deps', '.libs', '.DS_Store', '.nfs*', '*~', '._*' ]): WhitespaceList, Optional('object_folder', default=None): AbsPath, 'source_folder': AbsPath, Optional('source_encoding', default='utf-8'): basestring, Optional('temp_folder', default=None): AbsPath, Optional('p4web_url', default='http://p4web/'): basestring, Optional(basestring): dict }) tree = schema.validate(unvalidated_tree) if tree['temp_folder'] is None: tree['temp_folder'] = config.temp_folder if tree['object_folder'] is None: tree['object_folder'] = tree['source_folder'] # Convert enabled_plugins to a list of plugins: if tree['disabled_plugins'].is_all: # * doesn't really mean "all" in a tree. It means "everything the # [DXR] section enabled". tree['disabled_plugins'] = config.enabled_plugins else: # Add anything globally disabled to our local disabled list: tree['disabled_plugins'].extend( p for p in config.disabled_plugins if p not in tree['disabled_plugins']) if tree['enabled_plugins'].is_all: tree['enabled_plugins'] = [ p for p in config.enabled_plugins if p not in tree['disabled_plugins'] ] tree['enabled_plugins'].insert(0, core_plugin()) # Split ignores into paths and filenames: tree['ignore_paths'] = [ i for i in tree['ignore_patterns'] if i.startswith('/') ] tree['ignore_filenames'] = [ i for i in tree['ignore_patterns'] if not i.startswith('/') ] # Delete misleading, useless, or raw values people shouldn't use: del tree['ignore_patterns'] del tree['disabled_plugins'] # Validate plugin config: enableds_with_all_optional_config = set( p for p in tree['enabled_plugins'] if all( isinstance(k, Optional) for k in p.config_schema.iterkeys())) plugin_schema = Schema( merge( dict((Optional(name ) if plugin in enableds_with_all_optional_config or plugin not in tree['enabled_plugins'] else name, plugin.config_schema) for name, plugin in all_plugins_but_core().iteritems()), # And whatever isn't a plugin section, that we don't care about: {object: object})) # Insert empty missing sections for enabled plugins with entirely # optional config so their defaults get filled in. (Don't insert them # if the plugin has any required options; then we wouldn't produce the # proper error message about the section being absent.) for plugin in enableds_with_all_optional_config: tree.setdefault(plugin.name, {}) tree = plugin_schema.validate(tree) super(TreeConfig, self).__init__(tree)