From 8020012ed9f020790e61e840ac3cbd1b4a5317d9 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Sat, 15 Dec 2007 05:05:08 -0800 Subject: Add new utility function to get a value from a ConfigParser, with a default if the section or value does not exist. --- gitosis/configutil.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 gitosis/configutil.py diff --git a/gitosis/configutil.py b/gitosis/configutil.py new file mode 100644 index 0000000..e067352 --- /dev/null +++ b/gitosis/configutil.py @@ -0,0 +1,15 @@ +""" +Useful wrapper functions to access ConfigParser structures. +""" +from ConfigParser import NoSectionError, NoOptionError + +def getboolean_default(config, section, option, default_value): + """ + Return the given section.variable, or return the default if no specific + value is set. + """ + try: + value = config.getboolean(section, option) + except (NoSectionError, NoOptionError): + value = default_value + return value -- cgit v1.2.3