parses a given configfile
(self, config)
| 118 | |
| 119 | |
| 120 | def parseConfig(self, config): |
| 121 | """parses a given configfile""" |
| 122 | |
| 123 | f = open(config) |
| 124 | |
| 125 | config = f.read() |
| 126 | |
| 127 | config = config.splitlines()[1:] |
| 128 | |
| 129 | conf = {} |
| 130 | |
| 131 | section, option, value, typ, desc = "", "", "", "", "" |
| 132 | |
| 133 | listmode = False |
| 134 | |
| 135 | for line in config: |
| 136 | comment = line.rfind("#") |
| 137 | if line.find(":", comment) < 0 > line.find("=", comment) and comment > 0 and line[comment - 1].isspace(): |
| 138 | line = line.rpartition("#") # removes comments |
| 139 | if line[1]: |
| 140 | line = line[0] |
| 141 | else: |
| 142 | line = line[2] |
| 143 | |
| 144 | line = line.strip() |
| 145 | |
| 146 | try: |
| 147 | if line == "": |
| 148 | continue |
| 149 | elif line.endswith(":"): |
| 150 | section, none, desc = line[:-1].partition('-') |
| 151 | section = section.strip() |
| 152 | desc = desc.replace('"', "").strip() |
| 153 | conf[section] = {"desc": desc} |
| 154 | else: |
| 155 | if listmode: |
| 156 | if line.endswith("]"): |
| 157 | listmode = False |
| 158 | line = line.replace("]", "") |
| 159 | |
| 160 | value += [self.cast(typ, x.strip()) for x in line.split(",") if x] |
| 161 | |
| 162 | if not listmode: |
| 163 | conf[section][option] = {"desc": desc, |
| 164 | "type": typ, |
| 165 | "value": value} |
| 166 | |
| 167 | |
| 168 | else: |
| 169 | m = self.CONFLINE.search(line) |
| 170 | |
| 171 | typ = m.group('T') |
| 172 | option = m.group('N') |
| 173 | desc = m.group('D').strip() |
| 174 | value = m.group('V').strip() |
| 175 | |
| 176 | if value.startswith("["): |
| 177 | if value.endswith("]"): |
no test coverage detected