Mercurial > hg > truffle
comparison mxtool/mx.py @ 12491:11f217e8476a
mxtool: fix command-specific option parsing regression
author | Mick Jordan <mick.jordan@oracle.com> |
---|---|
date | Fri, 18 Oct 2013 15:58:07 -0700 |
parents | 28d7a11ba008 |
children | 1d68b3962a10 |
comparison
equal
deleted
inserted
replaced
12488:1a4dc163cd0a | 12491:11f217e8476a |
---|---|
554 pairs = spec.split(',') | 554 pairs = spec.split(',') |
555 for pair in pairs: | 555 for pair in pairs: |
556 mappair = pair.split('=') | 556 mappair = pair.split('=') |
557 self.suitenamemap[mappair[0]] = mappair[1] | 557 self.suitenamemap[mappair[0]] = mappair[1] |
558 | 558 |
559 @staticmethod | |
560 def _set_suitemodel(option, suitemap): | |
561 if option.startswith('sibling'): | |
562 return SiblingSuiteModel(os.getcwd(), option, suitemap) | |
563 elif option.startswith('nested'): | |
564 return NestedImportsSuiteModel(os.getcwd(), option, suitemap) | |
565 elif option.startswith('path'): | |
566 return PathSuiteModel(option[len('path:'):]) | |
567 else: | |
568 abort('unknown suitemodel type: ' + option) | |
569 | |
570 @staticmethod | |
571 def _parse_options(): | |
572 # suite-specific args may match the known args so there is no way at this early stage | |
573 # to use ArgParser to handle the suite model global arguments, so we just do it manually. | |
574 def _get_argvalue(arg, args, i): | |
575 if i < len(args): | |
576 return args[i] | |
577 else: | |
578 abort('value expected with ' + arg) | |
579 | |
580 args = sys.argv[1:] | |
581 src_suitemodel_arg = dst_suitemodel_arg = 'sibling' | |
582 suitemap_arg = None | |
583 | |
584 i = 0 | |
585 while i < len(args): | |
586 arg = args[i] | |
587 if arg == '--src-suitemodel': | |
588 src_suitemodel_arg = _get_argvalue(arg, args, i + 1) | |
589 elif arg == '--dst-suitemodel': | |
590 dst_suitemodel_arg = _get_argvalue(arg, args, i + 1) | |
591 elif arg == '--suitemap': | |
592 suitemap_arg = _get_argvalue(arg, args, i + 1) | |
593 i = i + 1 | |
594 | |
595 global _src_suitemodel | |
596 _src_suitemodel = SuiteModel._set_suitemodel(src_suitemodel_arg, suitemap_arg) | |
597 global _dst_suitemodel | |
598 _dst_suitemodel = SuiteModel._set_suitemodel(dst_suitemodel_arg, suitemap_arg) | |
599 | |
600 | |
559 class SiblingSuiteModel(SuiteModel): | 601 class SiblingSuiteModel(SuiteModel): |
560 """All suites are siblings in the same parent directory, recorded as _suiteRootDir""" | 602 """All suites are siblings in the same parent directory, recorded as _suiteRootDir""" |
561 def __init__(self, suiteRootDir, option, suitemap): | 603 def __init__(self, suiteRootDir, option, suitemap): |
562 SuiteModel.__init__(self) | 604 SuiteModel.__init__(self) |
563 self._suiteRootDir = suiteRootDir | 605 self._suiteRootDir = suiteRootDir |
1288 commandAndArgs = opts.__dict__.pop('commandAndArgs') | 1330 commandAndArgs = opts.__dict__.pop('commandAndArgs') |
1289 return opts, commandAndArgs | 1331 return opts, commandAndArgs |
1290 | 1332 |
1291 def _handle_conflict_resolve(self, action, conflicting_actions): | 1333 def _handle_conflict_resolve(self, action, conflicting_actions): |
1292 self._handle_conflict_error(action, conflicting_actions) | 1334 self._handle_conflict_error(action, conflicting_actions) |
1293 | |
1294 class SMArgParser(ArgParser): | |
1295 """Parser that just looks for suitemodel options, which must happen before suites are loaded""" | |
1296 def __init__(self): | |
1297 ArgParser.__init__(self) | |
1298 | |
1299 def _suitemodel(self, option, suitemap): | |
1300 if option.startswith('sibling'): | |
1301 return SiblingSuiteModel(os.getcwd(), option, suitemap) | |
1302 elif option.startswith('nested'): | |
1303 return NestedImportsSuiteModel(os.getcwd(), option, suitemap) | |
1304 elif option.startswith('path'): | |
1305 return PathSuiteModel(option[len('path:'):]) | |
1306 else: | |
1307 abort('unknown suitemodel type: ' + option) | |
1308 | |
1309 def _parse_suitemodel_options(self): | |
1310 # the command line may contains args added by suites, so we only parse the currently known args | |
1311 opts = self.parse_known_args()[0] | |
1312 # set this early | |
1313 global _warn | |
1314 _warn = opts.warn | |
1315 | |
1316 global _src_suitemodel | |
1317 _src_suitemodel = self._suitemodel(opts.src_suitemodel, opts.suitemap) | |
1318 global _dst_suitemodel | |
1319 _dst_suitemodel = self._suitemodel(opts.dst_suitemodel, opts.suitemap) | |
1320 | 1335 |
1321 def _format_commands(): | 1336 def _format_commands(): |
1322 msg = '\navailable commands:\n\n' | 1337 msg = '\navailable commands:\n\n' |
1323 for cmd in sorted(_commands.iterkeys()): | 1338 for cmd in sorted(_commands.iterkeys()): |
1324 c, _ = _commands[cmd][:2] | 1339 c, _ = _commands[cmd][:2] |
4343 curdir = parent | 4358 curdir = parent |
4344 | 4359 |
4345 return None | 4360 return None |
4346 | 4361 |
4347 def main(): | 4362 def main(): |
4348 SMArgParser()._parse_suitemodel_options() | 4363 SuiteModel._parse_options() |
4349 | 4364 |
4350 primarySuiteMxDir = _findPrimarySuiteMxDir() | 4365 primarySuiteMxDir = _findPrimarySuiteMxDir() |
4351 if primarySuiteMxDir: | 4366 if primarySuiteMxDir: |
4352 _src_suitemodel._set_primary_dir(dirname(primarySuiteMxDir)) | 4367 _src_suitemodel._set_primary_dir(dirname(primarySuiteMxDir)) |
4353 global _mainSuite | 4368 global _mainSuite |