| 408 | |
| 409 | # Parse config file |
| 410 | def parseConfig(self, argv): |
| 411 | # Find config file path from parameters |
| 412 | if "--config_file" in argv: |
| 413 | self.config_file = argv[argv.index("--config_file") + 1] |
| 414 | # Load config file |
| 415 | if os.path.isfile(self.config_file): |
| 416 | config = configparser.RawConfigParser(allow_no_value=True, strict=False) |
| 417 | config.read(self.config_file) |
| 418 | for section in config.sections(): |
| 419 | for key, val in config.items(section): |
| 420 | if val == "True": |
| 421 | val = None |
| 422 | if section != "global": # If not global prefix key with section |
| 423 | key = section + "_" + key |
| 424 | |
| 425 | if key == "open_browser": # Prefer config file value over cli argument |
| 426 | while "--%s" % key in argv: |
| 427 | pos = argv.index("--open_browser") |
| 428 | del argv[pos:pos + 2] |
| 429 | |
| 430 | argv_extend = ["--%s" % key] |
| 431 | if val: |
| 432 | for line in val.strip().split("\n"): # Allow multi-line values |
| 433 | argv_extend.append(line) |
| 434 | if "\n" in val: |
| 435 | argv_extend.append("--end") |
| 436 | |
| 437 | argv = argv[:1] + argv_extend + argv[1:] |
| 438 | return argv |
| 439 | |
| 440 | # Expose arguments as class attributes |
| 441 | def setAttributes(self): |