summaryrefslogtreecommitdiff
path: root/git/config.py
diff options
context:
space:
mode:
Diffstat (limited to 'git/config.py')
-rw-r--r--git/config.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/git/config.py b/git/config.py
index 5ad69c6a..913b965a 100644
--- a/git/config.py
+++ b/git/config.py
@@ -17,7 +17,9 @@ from git.util import LockFile
__all__ = ('GitConfigParser', 'SectionConstraint')
+
class MetaParserBuilder(type):
+
"""Utlity class wrapping base-class methods into decorators that assure read-only properties"""
def __new__(metacls, name, bases, clsdict):
"""
@@ -45,9 +47,9 @@ class MetaParserBuilder(type):
return new_type
-
def needs_values(func):
"""Returns method assuring we read values (on demand) before we try to access them"""
+
def assure_data_present(self, *args, **kwargs):
self.read()
return func(self, *args, **kwargs)
@@ -55,10 +57,12 @@ def needs_values(func):
assure_data_present.__name__ = func.__name__
return assure_data_present
+
def set_dirty_and_flush_changes(non_const_func):
"""Return method that checks whether given non constant function may be called.
If so, the instance will be set dirty.
Additionally, we flush the changes right to disk"""
+
def flush_changes(self, *args, **kwargs):
rval = non_const_func(self, *args, **kwargs)
self.write()
@@ -69,6 +73,7 @@ def set_dirty_and_flush_changes(non_const_func):
class SectionConstraint(object):
+
"""Constrains a ConfigParser to only option commands which are constrained to
always use the section we have been initialized with.
@@ -98,6 +103,7 @@ class SectionConstraint(object):
class GitConfigParser(cp.RawConfigParser, object):
+
"""Implements specifics required to read git style configuration files.
This variation behaves much like the git.config command such that the configuration
@@ -114,7 +120,6 @@ class GitConfigParser(cp.RawConfigParser, object):
must match perfectly."""
__metaclass__ = MetaParserBuilder
-
#{ Configuration
# The lock type determines the type of lock to use in new configuration readers.
# They must be compatible to the LockFile interface.
@@ -172,7 +177,6 @@ class GitConfigParser(cp.RawConfigParser, object):
self._lock._obtain_lock()
# END read-only check
-
def __del__(self):
"""Write pending changes if required and release locks"""
# checking for the lock here makes sure we do not raise during write()
@@ -261,7 +265,6 @@ class GitConfigParser(cp.RawConfigParser, object):
if e:
raise e
-
def read(self):
"""Reads the data stored in the files we have been initialized with. It will
ignore files that cannot be read, possibly leaving an empty configuration
@@ -311,7 +314,6 @@ class GitConfigParser(cp.RawConfigParser, object):
write_section(cp.DEFAULTSECT, self._defaults)
map(lambda t: write_section(t[0],t[1]), self._sections.items())
-
@needs_values
def write(self):
"""Write changes to our file, if there are changes at all