diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2010-11-15 11:37:14 +0100 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2010-11-15 11:37:14 +0100 |
commit | a1e2f63e64875a29e8c01a7ae17f5744680167a5 (patch) | |
tree | 8feb612ac5df79ec31300359b2bd28c40424bec0 /lib/git/config.py | |
parent | a1d1d2cb421f16bd277d7c4ce88398ff0f5afb29 (diff) | |
download | gitpython-a1e2f63e64875a29e8c01a7ae17f5744680167a5.tar.gz |
submodule: Fleshed out interface, and a partial test which is not yet usable. It showed that the ConfigParser needs some work. If the root is set, it also needs to refer to the root_commit instead of to the root-tree, as it will have to decide whether it works on the working tree's version of the .gitmodules file or the one in the repository
Diffstat (limited to 'lib/git/config.py')
-rw-r--r-- | lib/git/config.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/lib/git/config.py b/lib/git/config.py index 09bad0b6..e919838b 100644 --- a/lib/git/config.py +++ b/lib/git/config.py @@ -15,7 +15,7 @@ import cStringIO from git.odict import OrderedDict from git.util import LockFile -__all__ = ('GitConfigParser', ) +__all__ = ('GitConfigParser', 'SectionConstraint') class MetaParserBuilder(type): """Utlity class wrapping base-class methods into decorators that assure read-only properties""" @@ -63,7 +63,29 @@ def set_dirty_and_flush_changes(non_const_func): flush_changes.__name__ = non_const_func.__name__ return flush_changes + +class SectionConstraint(object): + """Constrains a ConfigParser to only option commands which are constrained to + always use the section we have been initialized with. + + It supports all ConfigParser methods that operate on an option""" + __slots__ = ("_config", "_section_name") + _valid_attrs_ = ("get_value", "set_value", "get", "set", "getint", "getfloat", "getboolean", "has_option") + def __init__(self, config, section): + self._config = config + self._section_name = section + + def __getattr__(self, attr): + if attr in self._valid_attrs_: + return lambda *args, **kwargs: self._call_config(attr, *args, **kwargs) + return super(SectionConstraint,self).__getattribute__(attr) + + def _call_config(self, method, *args, **kwargs): + """Call the configuration at the given method which must take a section name + as first argument""" + return getattr(self._config, method)(self._section_name, *args, **kwargs) + class GitConfigParser(cp.RawConfigParser, object): """Implements specifics required to read git style configuration files. |