4 from TkAlExceptions
import AllInOneError
9 Dictionary which handles updates of values for already existing keys
11 Instead of replacing the old value, the new value is appended to the
12 value string separated by `self.getSep()`.
13 This dictionary is used in the class `BetterConfigParser` instead of the
14 default `dict_type` of the `ConfigParser` class.
19 This method returns the separator used to separate the values for
20 duplicate options in a config.
24 def __setitem__(self, key, value, dict_setitem=dict.__setitem__):
26 od.__setitem__(i, y) <==> od[i]=y
27 Updating an existing key appends the new value to the old value
28 separated by `self.getSep()` instead of replacing it.
31 - `key`: key part of the key-value pair
32 - `value`: value part of the key-value pair
33 - `dict_item`: method which is used for finally setting the item
36 if "__name__" in self
and self[
"__name__"]==
"validation" and key
in self:
37 the_value = self[key]+self.
getSep()+value
40 dict_setitem(self, key, the_value)
45 ConfigParser.ConfigParser.__init__(self,dict_type=AdaptedDict)
47 self.
_sep = dummyDict.getSep()
58 items = self.items(section)
59 except ConfigParser.NoSectionError:
69 for option
in self.options( section ):
70 result[option] = self.get( section, option )
71 if "local"+section.title()
in self.sections():
72 for option
in self.options(
"local"+section.title() ):
73 result[option] = self.get(
"local"+section.title(),
75 except ConfigParser.NoSectionError, section:
76 msg = (
"%s in configuration files. This section is mandatory."
77 %(str(section).
replace(
":",
"", 1)))
82 result = copy.deepcopy(defaultDict)
83 for option
in demandPars:
85 result[option] = self.get( section, option )
86 except ConfigParser.NoOptionError, globalSectionError:
87 globalSection = str( globalSectionError ).
split(
"'" )[-2]
88 splittedSectionName = section.split(
":" )
89 if len( splittedSectionName ) > 1:
90 localSection = (
"local"+section.split(
":" )[0].
title()+
":"
91 +section.split(
":")[1])
93 localSection = (
"local"+section.split(
":" )[0].
title())
94 if self.has_section( localSection ):
96 result[option] = self.get( localSection, option )
97 except ConfigParser.NoOptionError, option:
98 msg = (
"%s. This option is mandatory."
101 "section '"+globalSection+
"' or", 1)))
104 msg = (
"%s. This option is mandatory."
105 %(str(globalSectionError).
replace(
":",
"", 1)))
112 for section
in self.sections():
113 if "alignment:" in section:
114 alignments.append( Alignment( section.split(
"alignment:" )[1],
120 for section
in self.sections():
121 if "compare:" in section:
123 knownSimpleOptions = [
"levels",
"dbOutput",
125 levels = self.get( section,
"levels" )
126 dbOutput = self.get( section,
"dbOutput" )
127 compares[section.split(
":")[1]] = ( levels, dbOutput )
132 "jobmode":
"interactive",
133 "datadir":os.getcwd(),
134 "logdir":os.getcwd(),
138 self.
checkInput(
"general", knownSimpleOptions = defaults.keys())
140 internal_section =
"internals"
141 if not self.has_section(internal_section):
142 self.add_section(internal_section)
143 if not self.has_option(internal_section,
"workdir"):
144 self.set(internal_section,
"workdir",
"/tmp/$USER")
145 general[
"workdir"] = self.get(internal_section,
"workdir")
148 def checkInput(self, section, knownSimpleOptions=[], knownKeywords=[],
151 Method which checks, if the given options in `section` are in the
152 list of `knownSimpleOptions` or match an item of `knownKeywords`.
153 This is basically a check for typos and wrong parameters.
156 - `section`: Section of a configuration file
157 - `knownSimpleOptions`: List of allowed simple options in `section`.
158 - `knownKeywords`: List of allowed keywords in `section`.
161 for option
in self.options( section ):
162 if option
in knownSimpleOptions:
164 elif option.split()[0]
in knownKeywords:
166 elif option
in ignoreOptions:
167 print (
"Ignoring option '%s' in section '[%s]'."
170 msg = (
"Invalid or unknown parameter '%s' in section '%s'!"