Rev 549 | Rev 552 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 549 | Rev 550 | ||
|---|---|---|---|
| Line 184... | Line 184... | ||
| 184 | if res: |
184 | if res: |
| 185 | defaults[res.group(1)] = res.group(2) |
185 | defaults[res.group(1)] = res.group(2) |
| 186 | f.close() |
186 | f.close() |
| 187 | 187 | ||
| 188 | def check_condition(text, defaults): |
188 | def check_condition(text, defaults): |
| - | 189 | result = True |
|
| - | 190 | conds = text.split('&') |
|
| - | 191 | for cond in conds: |
|
| - | 192 | if cond.startswith('(') and cond.endswith(')'): |
|
| - | 193 | cond = cond[1:-1] |
|
| - | 194 | if not check_dnf(cond, defaults): |
|
| - | 195 | return False |
|
| - | 196 | return True |
|
| - | 197 | ||
| - | 198 | def check_dnf(text, defaults): |
|
| - | 199 | """ |
|
| 189 | "Check that the condition specified on input line is True" |
200 | Check that the condition specified on input line is True |
| - | 201 | ||
| 190 | result = False |
202 | only CNF is supported |
| - | 203 | """ |
|
| 191 | conds = text.split('|') |
204 | conds = text.split('|') |
| 192 | for cond in conds: |
205 | for cond in conds: |
| - | 206 | res = re.match(r'^(.*?)(!?=)(.*)$', cond) |
|
| - | 207 | if not res: |
|
| - | 208 | raise RuntimeError("Invalid condition: %s" % cond) |
|
| 193 | condname,condval = cond.split('=') |
209 | condname = res.group(1) |
| - | 210 | oper = res.group(2) |
|
| - | 211 | condval = res.group(3) |
|
| 194 | if not defaults.has_key(condname): |
212 | if not defaults.has_key(condname): |
| 195 | raise RuntimeError("Condition var %s does not exist: %s" % \ |
213 | raise RuntimeError("Condition var %s does not exist: %s" % \ |
| 196 | (condname,line)) |
214 | (condname,text)) |
| 197 | # None means wildcard |
- | |
| - | 215 | ||
| 198 | if defaults[condname] is None: |
216 | if oper=='=' and condval == defaults[condname]: |
| 199 | return True |
217 | return True |
| 200 | if condval == defaults[condname]: |
218 | if oper == '!=' and condval != defaults[condname]: |
| 201 | return True |
219 | return True |
| 202 | return False |
220 | return False |
| 203 | 221 | ||
| 204 | def parse_config(input, output, dlg, defaults={}): |
222 | def parse_config(input, output, dlg, defaults={}): |
| 205 | "Parse configuration file and create Makefile.config on the fly" |
223 | "Parse configuration file and create Makefile.config on the fly" |
| Line 211... | Line 229... | ||
| 211 | outf.write('#########################################\n\n') |
229 | outf.write('#########################################\n\n') |
| 212 | 230 | ||
| 213 | comment = '' |
231 | comment = '' |
| 214 | default = None |
232 | default = None |
| 215 | choices = [] |
233 | choices = [] |
| 216 | for line in f: |
234 | for line in f: |
| - | 235 | if line.startswith('%'): |
|
| - | 236 | res = re.match(r'^%\s*(?:\[(.*?)\])?\s*(.*)$', line) |
|
| - | 237 | if not res: |
|
| - | 238 | raise RuntimeError('Invalid command: %s' % line) |
|
| - | 239 | if res.group(1): |
|
| - | 240 | if not check_condition(res.group(1), defaults): |
|
| - | 241 | continue |
|
| - | 242 | args = res.group(2).strip().split(' ') |
|
| - | 243 | cmd = args[0].lower() |
|
| - | 244 | args = args[1:] |
|
| - | 245 | if cmd == 'askdefault': |
|
| - | 246 | if isinstance(dlg, DefaultDialog): |
|
| - | 247 | continue |
|
| - | 248 | res = dlg.noyes('Change kernel configuration') |
|
| - | 249 | if res == 'n': |
|
| - | 250 | dlg = DefaultDialog(dlg) |
|
| - | 251 | elif cmd == 'saveas': |
|
| - | 252 | outf.write('%s = %s\n' % (args[1],defaults[args[0]])) |
|
| - | 253 | ||
| - | 254 | continue |
|
| - | 255 | ||
| 217 | if line.startswith('!'): |
256 | if line.startswith('!'): |
| 218 | # Ask a question |
257 | # Ask a question |
| 219 | res = re.search(r'!\s*(?:\[(.*?)\])?\s*([^\s]+)\s*\((.*)\)\s*$', line) |
258 | res = re.search(r'!\s*(?:\[(.*?)\])?\s*([^\s]+)\s*\((.*)\)\s*$', line) |
| 220 | if not res: |
259 | if not res: |
| 221 | raise RuntimeError("Weird line: %s" % line) |
260 | raise RuntimeError("Weird line: %s" % line) |
| Line 226... | Line 265... | ||
| 226 | 265 | ||
| 227 | if res.group(1): |
266 | if res.group(1): |
| 228 | if not check_condition(res.group(1), defaults): |
267 | if not check_condition(res.group(1), defaults): |
| 229 | if default is not None: |
268 | if default is not None: |
| 230 | outf.write('#!# %s = %s\n' % (varname, default)) |
269 | outf.write('#!# %s = %s\n' % (varname, default)) |
| - | 270 | # Clear cumulated values |
|
| - | 271 | comment = '' |
|
| - | 272 | default = None |
|
| - | 273 | choices = [] |
|
| 231 | continue |
274 | continue |
| 232 | 275 | ||
| 233 | if vartype == 'y/n': |
276 | if vartype == 'y/n': |
| 234 | result = dlg.yesno(comment, default) |
277 | result = dlg.yesno(comment, default) |
| 235 | elif vartype == 'n/y': |
278 | elif vartype == 'n/y': |
| Line 275... | Line 318... | ||
| 275 | 318 | ||
| 276 | outf.close() |
319 | outf.close() |
| 277 | f.close() |
320 | f.close() |
| 278 | 321 | ||
| 279 | def main(): |
322 | def main(): |
| 280 | defaults = {'ARCH':None} |
323 | defaults = {} |
| 281 | try: |
324 | try: |
| 282 | dlg = Dialog() |
325 | dlg = Dialog() |
| 283 | except NotImplementedError: |
326 | except NotImplementedError: |
| 284 | dlg = NoDialog() |
327 | dlg = NoDialog() |
| 285 | 328 | ||
| 286 | # Default run will update the configuration file |
329 | # Default run will update the configuration file |
| 287 | # with newest options |
330 | # with newest options |
| 288 | if len(sys.argv) >= 2: |
- | |
| 289 | defaults['ARCH'] = sys.argv[1] |
- | |
| 290 | if len(sys.argv) == 3 and sys.argv[2]=='default': |
331 | if len(sys.argv) == 2 and sys.argv[1]=='default': |
| 291 | dlg = DefaultDialog(dlg) |
332 | dlg = DefaultDialog(dlg) |
| 292 | 333 | ||
| 293 | if os.path.exists(OUTPUT): |
334 | if os.path.exists(OUTPUT): |
| 294 | read_defaults(OUTPUT, defaults) |
335 | read_defaults(OUTPUT, defaults) |
| 295 | 336 | ||