From 6a417f4cf2df39704aa4c869e88d14e9806894a7 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 8 Dec 2009 20:01:17 +0100 Subject: config.set_value: added more convenient set_value method to ConfigReader --- lib/git/config.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'lib') diff --git a/lib/git/config.py b/lib/git/config.py index 1739e786..e8bdfc75 100644 --- a/lib/git/config.py +++ b/lib/git/config.py @@ -387,3 +387,23 @@ class GitConfigParser(cp.RawConfigParser, LockFile): raise TypeError( "Invalid value type: only int, long, float and str are allowed", valuestr ) return valuestr + + @_needs_values + @_set_dirty_and_flush_changes + def set_value(self, section, option, value): + """Sets the given option in section to the given value. + It will create the section if required, and will not throw as opposed to the default + ConfigParser 'set' method. + + ``section`` + Name of the section in which the option resides or should reside + + ``option`` + Name of the options whose value to set + + ``value`` + Value to set the option to. It must be a string or convertible to a string + """ + if not self.has_section(section): + self.add_section(section) + self.set(section, option, str(value)) -- cgit v1.2.3