1717
1818__all__ = ('GitConfigParser' ,'SectionConstraint' )
1919
20+
2021class MetaParserBuilder (type ):
22+
2123"""Utlity class wrapping base-class methods into decorators that assure read-only properties"""
2224def __new__ (metacls ,name ,bases ,clsdict ):
2325"""
@@ -45,20 +47,22 @@ def __new__(metacls, name, bases, clsdict):
4547return new_type
4648
4749
48-
4950def needs_values (func ):
5051"""Returns method assuring we read values (on demand) before we try to access them"""
52+
5153def assure_data_present (self ,* args ,** kwargs ):
5254self .read ()
5355return func (self ,* args ,** kwargs )
5456# END wrapper method
5557assure_data_present .__name__ = func .__name__
5658return assure_data_present
5759
60+
5861def set_dirty_and_flush_changes (non_const_func ):
5962"""Return method that checks whether given non constant function may be called.
6063 If so, the instance will be set dirty.
6164 Additionally, we flush the changes right to disk"""
65+
6266def flush_changes (self ,* args ,** kwargs ):
6367rval = non_const_func (self ,* args ,** kwargs )
6468self .write ()
@@ -69,6 +73,7 @@ def flush_changes(self, *args, **kwargs):
6973
7074
7175class SectionConstraint (object ):
76+
7277"""Constrains a ConfigParser to only option commands which are constrained to
7378 always use the section we have been initialized with.
7479
@@ -98,6 +103,7 @@ def config(self):
98103
99104
100105class GitConfigParser (cp .RawConfigParser ,object ):
106+
101107"""Implements specifics required to read git style configuration files.
102108
103109 This variation behaves much like the git.config command such that the configuration
@@ -114,7 +120,6 @@ class GitConfigParser(cp.RawConfigParser, object):
114120 must match perfectly."""
115121__metaclass__ = MetaParserBuilder
116122
117-
118123#{ Configuration
119124# The lock type determines the type of lock to use in new configuration readers.
120125# They must be compatible to the LockFile interface.
@@ -172,7 +177,6 @@ def __init__(self, file_or_files, read_only=True):
172177self ._lock ._obtain_lock ()
173178# END read-only check
174179
175-
176180def __del__ (self ):
177181"""Write pending changes if required and release locks"""
178182# checking for the lock here makes sure we do not raise during write()
@@ -261,7 +265,6 @@ def _read(self, fp, fpname):
261265if e :
262266raise e
263267
264-
265268def read (self ):
266269"""Reads the data stored in the files we have been initialized with. It will
267270 ignore files that cannot be read, possibly leaving an empty configuration
@@ -311,7 +314,6 @@ def write_section(name, section_dict):
311314write_section (cp .DEFAULTSECT ,self ._defaults )
312315map (lambda t :write_section (t [0 ],t [1 ]),self ._sections .items ())
313316
314-
315317@needs_values
316318def write (self ):
317319"""Write changes to our file, if there are changes at all