Package platformids :: Module optionparser_platformids

Source Code for Module platformids.optionparser_platformids

   1  # -*- coding: utf-8 -*- 
   2  """Provides the command  line options for *platformids*. 
   3  """ 
   4  from __future__ import absolute_import 
   5   
   6  import sys 
   7  import os 
   8  import argparse 
   9  import platform 
  10   
  11  from sourceinfo.fileinfo import getcaller_linenumber 
  12   
  13  from pythonids import PYV35Plus, ISSTR 
  14  from platformids import _debug, _verbose 
  15  from platformids import RTE , RTE_WIN32, PlatformIDsError 
  16  import platformids.dist 
  17  import platformids.platforms 
  18   
  19   
  20  if PYV35Plus: 
  21      unicode = str  # @ReservedAssignment 
  22   
  23  __author__ = 'Arno-Can Uestuensoez' 
  24  __license__ = "Artistic-License-2.0 + Forced-Fairplay-Constraints" 
  25  __copyright__ = "Copyright (C) 2017 Arno-Can Uestuensoez" \ 
  26                  " @Ingenieurbuero Arno-Can Uestuensoez" 
  27  __version__ = '0.1.35' 
  28  __uuid__ = "7add5ded-c39b-4b6e-8c87-1b3a1c150ee9" 
  29   
  30  __docformat__ = "restructuredtext en" 
  31   
  32  # cached defaults 
  33  _verbose = platformids._verbose 
  34  _debug = platformids._debug 
  35  _header = '' 
  36   
  37  # pre-fetch debugging 
  38  if '--debug' in sys.argv: 
  39      sys.tracebacklimit = 1000 
  40  else: 
  41      sys.tracebacklimit = 0 
  42   
  43   
  44  _appname = "rtplatformids" 
  45   
46 -class FetchOptionsError(PlatformIDsError):
47 - def __init__(self, *args, **kargs):
48 super(FetchOptionsError, self).__init__(*args, **kargs)
49 50 51 # 52 # buffer for options evaluation 53 _clibuf = [] 54 55 # 56 # early fetch for the parameter of the ArgumentParser constructor 57 # 58 if '--fromfile' in sys.argv: 59 _fromfile='@' 60 else: 61 _fromfile = None 62 63
64 -class FormatTextRaw(argparse.HelpFormatter):
65 """Formatter for help.""" 66
67 - def _split_lines(self, text, width):
68 """Customize help format.""" 69 if text.startswith('@R:'): 70 return text[3:].splitlines() 71 return argparse.HelpFormatter._split_lines(self, text, width)
72 73
74 -class ActionExt(argparse.Action):
75 """Extends the 'argparse.Action' 76 """
77 - def __init__(self, *args, **kwargs):
78 super(ActionExt, self).__init__(*args, **kwargs)
79
80 - def __call__(self, parser, namespace, values, option_string=None):
81 """Adds context help on each option. 82 """ 83 if _debug > 2: 84 if values: 85 sys.stderr.write( 86 "RDBG:%d:CLI:option: %s=%s\n" %( 87 getcaller_linenumber(), 88 str(option_string), 89 str(values) 90 ) 91 ) 92 else: 93 sys.stderr.write( 94 "RDBG:%d:CLI:option: %s\n" %( 95 getcaller_linenumber(), 96 str(option_string) 97 ) 98 ) 99 100 if values and (values in ("help", "?") or type(values) is list and values[0] in ("help", "?")): 101 form = FormatTextRaw('rdbg') 102 # print('\n' + str(sys.argv[-2])) 103 if self.__doc__: 104 print('\n ' + 105 '\n '.join(FormatTextRaw._split_lines( 106 form, "@R:" + self.__doc__, 80)) + '\n') 107 else: 108 print('\n ' + 109 '\n '.join(FormatTextRaw._split_lines( 110 form, "No help.", 80)) + '\n') 111 sys.exit(0) 112 113 self.call(parser, namespace, values, option_string)
114
115 - def get_help_text(self):
116 form = FormatTextRaw('rdbg') 117 #print('\n' + str(sys.argv[-2])) 118 if self.__doc__: 119 return '\n ' + '\n '.join(FormatTextRaw._split_lines( 120 form, "@R:" + self.__doc__, 80)) + '\n' 121 else: 122 return '\n ' + '\n '.join(FormatTextRaw._split_lines( 123 form, "No help.", 80)) + '\n'
124
125 - def help_option(self):
126 print(self.get_help_text()) 127 sys.exit(0)
128 129
130 -class OptActionDebug(ActionExt):
131 """Activates debug output including stacktrace, repetition raise level.""" 132
133 - def __init__(self, option_strings, dest, nargs=None, **kwargs):
134 super(OptActionDebug, self).__init__( 135 option_strings, dest, nargs, **kwargs)
136
137 - def call(self, parser, namespace, values, option_string=None):
138 global _debug 139 if values == '0': 140 platformids._debug = 0 141 _debug = platformids._debug 142 namespace.debug = _debug 143 sys.tracebacklimit = 0 144 elif not values: 145 platformids._debug += 1 146 _debug = platformids._debug 147 namespace.debug = _debug 148 if _debug > 2: 149 sys.tracebacklimit = 1000 # the original default 150 else: 151 sys.tracebacklimit += 4 152 else: 153 try: 154 platformids._debug = int(values) 155 _debug = platformids._debug 156 namespace.debug = _debug 157 sys.tracebacklimit = 1000 # the original default 158 except ValueError: 159 raise PlatformIDsError("'--debug' requires 'int', got: " + str(values))
160 161
162 -class OptActionDebugOptions(ActionExt):
163 """Displays the internal commandline options data with optional output format.""" 164
165 - def __init__(self, option_strings, dest, nargs=None, **kwargs):
166 super(OptActionDebugOptions, self).__init__( 167 option_strings, dest, nargs, **kwargs)
168
169 - def call(self, parser, namespace, values, option_string=None):
170 namespace.debug_options = [] 171 if values in ('', None, [],): 172 namespace.debug_options.append('json') 173 elif values[0].lower() in ('json', 'repr', 'str'): 174 namespace.debug_options.append(values[0]) 175 if values[-1].lower() == 'cont': 176 namespace.debug_options.append(values[1]) 177 elif len(values) >1: 178 raise PlatformIDsError("invalid value: --debug-options=" + str(values)) 179 else: 180 raise PlatformIDsError("invalid value: --debug-options=" + str(values))
181
182 -class OptActionEnumerate(ActionExt):
183 """Enumerates the known platform entries.""" 184
185 - def __init__(self, option_strings, dest, nargs=None, **kwargs):
186 super(OptActionEnumerate, self).__init__( 187 option_strings, dest, nargs, **kwargs)
188
189 - def call(self, parser, namespace, values, option_string=None):
190 if not values: 191 namespace.enumerate = {'type': 'all',} 192 else: 193 namespace.enumerate = {'type': values.pop(0)} 194 if namespace.enumerate['type'] not in ('all', 'category', 'ostype', 'dist', 'distrel'): 195 raise PlatformIDsError("Invalid value for enumerate: '" + str(values) + "'") 196 197 for x in values: 198 if x.startswith('num='): 199 namespace.enumerate['num'] = x[4:] 200 if namespace.enumerate['num'] not in ('int', 'hex', 'bit', 'sym',): 201 raise PlatformIDsError("Invalid value for num='" + str(namespace.enumerate['num']) + "'") 202 elif x.startswith('scope='): 203 namespace.enumerate['scope'] = x[6:] 204 if namespace.enumerate['scope'] not in ('all', 'numkey', 'strkey',): 205 raise PlatformIDsError("Invalid value for scope='" + str(namespace.enumerate['scope']) + "'") 206 elif x.startswith('pad='): 207 namespace.enumerate['pad'] = x[4:] 208 if namespace.enumerate['pad'] not in ('on', '1', 'true', 'off', '0', 'false',): 209 raise PlatformIDsError("Invalid value for pad='" + str(namespace.enumerate['pad']) + "'") 210 elif x.startswith('reverse='): 211 namespace.enumerate['reverse'] = x[8:] 212 if namespace.enumerate['reverse'] not in ('on', '1', 'true', 'off', '0', 'false',): 213 raise PlatformIDsError("Invalid value for reverse='" + str(namespace.enumerate['reverse']) + "'") 214 else: 215 raise PlatformIDsError("Invalid option: '" + str(x) + "'")
216
217 -class OptActionEnvironDetails(ActionExt):
218 """Details of runtime environment.""" 219
220 - def __init__(self, option_strings, dest, nargs=None, **kwargs):
221 super(OptActionEnvironDetails, self).__init__( 222 option_strings, dest, nargs, **kwargs)
223
224 - def call(self, parser, namespace, values, option_string=None):
225 226 print("") 227 print("app: " + str(_appname)) 228 print("") 229 print("python running rtplatformids:") 230 print(" running version: " + str(platform.python_version())) 231 print(" compiler: " + str(platform.python_compiler())) 232 print(" build: " + str(platform.python_build())) 233 print("") 234 sys.exit()
235 236
237 -class OptActionFromfile(ActionExt):
238 """Enables the read of options from an options file.""" 239
240 - def __init__(self, option_strings, dest, nargs=None, **kwargs):
241 super(OptActionFromfile, self).__init__( 242 option_strings, dest, nargs, **kwargs)
243
244 - def call(self, parser, namespace, values, option_string=None):
245 namespace.fromfile = True
246 247
248 -class OptActionH(ActionExt):
249 """Usage.""" 250
251 - def __init__(self, option_strings, dest, nargs=None, **kwargs):
252 super(OptActionH, self).__init__( 253 option_strings, dest, nargs, **kwargs)
254
255 - def call(self, parser, namespace, values, option_string=None):
256 parser.print_usage() 257 sys.exit(0)
258 259
260 -class OptActionHelp(ActionExt):
261 """This help.""" 262
263 - def __init__(self, option_strings, dest, nargs=None, **kwargs):
264 super(OptActionHelp, self).__init__( 265 option_strings, dest, nargs, **kwargs)
266
267 - def call(self, parser, namespace, values, option_string=None):
268 parser.print_help() 269 sys.exit(0)
270 271
272 -class OptActionPrintOutFormat(ActionExt):
273 """Defines the processed output format. 274 275 --out-format=<format> 276 format := ( 277 'json' | 'raw' | 'repr' | 'str' | 'bashvars' 278 ) 279 280 """ 281
282 - def __init__(self, option_strings, dest, nargs=None, **kwargs):
283 super(OptActionPrintOutFormat, self).__init__( 284 option_strings, dest, nargs, **kwargs)
285
286 - def call(self, parser, namespace, values, option_string=None):
287 if not values[0]: 288 raise PlatformIDsError("Requires value for'--out-format'") 289 elif values[0] in ('json', 'raw', 'repr', 'str', 'basharray' ,'bashvars'): 290 namespace.out_format = values[0] 291 else: 292 raise PlatformIDsError("Unknown output format:" + str(values))
293
294 -class OptActionCategory(ActionExt):
295 """Display category.""" 296
297 - def __init__(self, option_strings, dest, nargs=None, **kwargs):
298 super(OptActionCategory, self).__init__( 299 option_strings, dest, nargs, **kwargs)
300
301 - def call(self, parser, namespace, values, option_string=None):
302 namespace.category= True 303 namespace.selected = True
304 305
306 -class OptActionOstype(ActionExt):
307 """Display ostype.""" 308
309 - def __init__(self, option_strings, dest, nargs=None, **kwargs):
310 super(OptActionOstype, self).__init__( 311 option_strings, dest, nargs, **kwargs)
312
313 - def call(self, parser, namespace, values, option_string=None):
314 namespace.ostype = True 315 namespace.selected = True
316 317
318 -class OptActionPlatform(ActionExt):
319 """Display parameters from standard library 'platform'.""" 320
321 - def __init__(self, option_strings, dest, nargs=None, **kwargs):
322 super(OptActionPlatform, self).__init__( 323 option_strings, dest, nargs, **kwargs)
324
325 - def call(self, parser, namespace, values, option_string=None):
326 namespace.platform = True 327 namespace.selected = True
328 329
330 -class OptActionDist(ActionExt):
331 """Display distribution.""" 332
333 - def __init__(self, option_strings, dest, nargs=None, **kwargs):
334 super(OptActionDist, self).__init__( 335 option_strings, dest, nargs, **kwargs)
336
337 - def call(self, parser, namespace, values, option_string=None):
338 namespace.dist = True 339 namespace.selected = True
340 341
342 -class OptActionDistRel(ActionExt):
343 """Display release of the distribution.""" 344
345 - def __init__(self, option_strings, dest, nargs=None, **kwargs):
346 super(OptActionDistRel, self).__init__( 347 option_strings, dest, nargs, **kwargs)
348
349 - def call(self, parser, namespace, values, option_string=None):
350 namespace.distrel = True 351 namespace.selected = True
352 353
354 -class OptActionDistRelName(ActionExt):
355 """Display name of the distribution release.""" 356
357 - def __init__(self, option_strings, dest, nargs=None, **kwargs):
358 super(OptActionDistRelName, self).__init__( 359 option_strings, dest, nargs, **kwargs)
360
361 - def call(self, parser, namespace, values, option_string=None):
362 namespace.distrel = True 363 namespace.selected = True
364 365
366 -class OptActionDistRelKey(ActionExt):
367 """Display name of the selection key of the distribution release. 368 Used for internal mapping-tables to be used as debugging support. 369 """ 370
371 - def __init__(self, option_strings, dest, nargs=None, **kwargs):
372 super(OptActionDistRelKey, self).__init__( 373 option_strings, dest, nargs, **kwargs)
374
375 - def call(self, parser, namespace, values, option_string=None):
376 namespace.distrel_key = True 377 namespace.selected = True
378 379
380 -class OptActionDistVers(ActionExt):
381 """Display the version array the distribution release.""" 382
383 - def __init__(self, option_strings, dest, nargs=None, **kwargs):
384 super(OptActionDistVers, self).__init__( 385 option_strings, dest, nargs, **kwargs)
386
387 - def call(self, parser, namespace, values, option_string=None):
388 namespace.distrel_version = True 389 namespace.selected = True
390 391
392 -class OptActionLoad(ActionExt):
393 """Loads additional platform source modules.""" 394
395 - def __init__(self, option_strings, dest, nargs=None, **kwargs):
396 super(OptActionLoad, self).__init__( 397 option_strings, dest, nargs, **kwargs)
398
399 - def call(self, parser, namespace, values, option_string=None):
400 if not values: 401 raise PlatformIDsError("Requires value: '--load'") 402 else: 403 if type(values) is list: 404 values = values[0] 405 if not os.path.exists(values): 406 raise PlatformIDsError("Missing filepathname: --load='" + str(values) + "'") 407 if not os.path.isfile(values): 408 raise PlatformIDsError("Requires a file: --load='" + str(values) + "'") 409 namespace.load.append(values)
410 411
412 -class OptActionOstypeId(ActionExt):
413 """Display the ID of the OS release.""" 414
415 - def __init__(self, option_strings, dest, nargs=None, **kwargs):
416 super(OptActionOstypeId, self).__init__( 417 option_strings, dest, nargs, **kwargs)
418
419 - def call(self, parser, namespace, values, option_string=None):
420 namespace.ostype_id = True 421 namespace.selected = True
422 423
424 -class OptActionOstypeVers(ActionExt):
425 """Display the version array the OS release.""" 426
427 - def __init__(self, option_strings, dest, nargs=None, **kwargs):
428 super(OptActionOstypeVers, self).__init__( 429 option_strings, dest, nargs, **kwargs)
430
431 - def call(self, parser, namespace, values, option_string=None):
432 namespace.ostype_version = True 433 namespace.selected = True
434 435
436 -class OptActionDistRelHexversion(ActionExt):
437 """Display the release of the distribution including the canonical version as hex-bit-array.""" 438
439 - def __init__(self, option_strings, dest, nargs=None, **kwargs):
440 super(OptActionDistRelHexversion, self).__init__( 441 option_strings, dest, nargs, **kwargs)
442
443 - def call(self, parser, namespace, values, option_string=None):
444 namespace.distrel_hexversion = True 445 namespace.selected = True
446 447
448 -class OptActionQuiet(ActionExt):
449 """Suppress output""" 450
451 - def __init__(self, option_strings, dest, nargs=None, **kwargs):
452 super(OptActionQuiet, self).__init__( 453 option_strings, dest, nargs, **kwargs)
454
455 - def call(self, parser, namespace, values, option_string=None):
456 namespace.quiet = True
457 458
459 -class OptActionRaw(ActionExt):
460 """Prints the values as raw type, else symbolic names where suitable.""" 461
462 - def __init__(self, option_strings, dest, nargs=None, **kwargs):
463 super(OptActionRaw, self).__init__( 464 option_strings, dest, nargs, **kwargs)
465
466 - def call(self, parser, namespace, values, option_string=None):
467 namespace.raw = True
468 469
470 -class OptActionTerse(ActionExt):
471 """Terse, values only.""" 472
473 - def __init__(self, option_strings, dest, nargs=None, **kwargs):
474 super(OptActionTerse, self).__init__( 475 option_strings, dest, nargs, **kwargs)
476
477 - def call(self, parser, namespace, values, option_string=None):
478 namespace.terse = True
479 480
481 -class OptActionVerbose(ActionExt):
482 """Verbose, repetition raises the level.""" 483
484 - def __init__(self, option_strings, dest, nargs=None, **kwargs):
485 super(OptActionVerbose, self).__init__( 486 option_strings, dest, nargs, **kwargs)
487
488 - def call(self, parser, namespace, values, option_string=None):
489 global _verbose 490 if values == '0': 491 namespace.verbose = _verbose = platformids._verbose = 0 492 elif not values: 493 platformids._verbose += 1 494 _verbose = platformids._verbose 495 namespace.verbose = _verbose 496 else: 497 try: 498 platformids._verbose = int(values) 499 _verbose = platformids._verbose 500 namespace.verbose = _verbose 501 except ValueError: 502 raise PlatformIDsError("'--verbose' requires 'int', got: " + str(values))
503 504
505 -class OptActionVersion(ActionExt):
506 """Current version of 'rtplatformids' - terse.""" 507
508 - def __init__(self, option_strings, dest, nargs=None, **kwargs):
509 super(OptActionVersion, self).__init__( 510 option_strings, dest, nargs, **kwargs)
511
512 - def call(self, parser, namespace, values, option_string=None):
513 sys.stdout.write(str(__version__)) 514 sys.exit()
515 516
517 -class OptActionVersionDetails(ActionExt):
518 """Current versions - detailed.""" 519
520 - def __init__(self, option_strings, dest, nargs=None, **kwargs):
521 super(OptActionVersionDetails, self).__init__( 522 option_strings, dest, nargs, **kwargs)
523
524 - def call(self, parser, namespace, values, option_string=None):
525 print("") 526 print("app: " + str(_appname)) 527 print("id: " + str(__uuid__)) 528 print("platformids: " + str(platformids.__version__)) 529 print("platforms: " + str(platformids.platforms.__version__)) 530 # print("dist: " + str(platformids.dist.__version__)) 531 print("rtplatformids: " + str(__version__)) 532 print("") 533 print("Project: " + 'https://multiconf.sourceforge.net/') 534 print("SCM: " + 'https://github.com/ArnoCan/multiconf/') 535 print("package: " + 'https://pypi.python.org/pypi/multiconf/') 536 print("docs: " + 'https://pythonhosted.org/multiconf/') 537 print("") 538 print("author: " + str(platformids.__author__)) 539 print("author-www: " + 'https://arnocan.wordpress.com') 540 print("") 541 print("copyright: " + str(platformids.__copyright__)) 542 print("license: " + str(platformids.__license__)) 543 print("") 544 sys.exit()
545
546 -class OptionsNamespace(object):
547 """Namespace object for parameter passing. 548 """
549 - def __init__(self, argv, optargs, env=None):
550 self._argv = argv #: The original argv 551 self.optargs = optargs #: the result formatted as JSON compatible 552 self.rdbgenv = env #: FIXME: 553 self.selected = False
554
555 - def get_optvalues(self):
556 """Gets the resulting command line parameters.""" 557 return self.optargs
558 559 # 560 # option parser/scanner 561 #
562 -class OptionsParser(object):
563
564 - def __init__(self, argv=None, *args, **kargs):
565 """ 566 Args: 567 argv: 568 call options 569 570 Returns: 571 (opts, unknown, args) 572 573 Raises: 574 pass-through 575 """ 576 # prep argv 577 if argv and type(argv) in ISSTR: 578 self.argv = argv.split() 579 elif argv and type(argv) in (list,): 580 self.argv = argv[:] 581 elif argv is None: 582 self.argv = sys.argv[:] 583 else: 584 self.argv = argv 585 586 self.optargs = {} #: resulting options and arguments'--
587
588 - def get_options(self):
589 590 _myspace = OptionsNamespace(self.argv, self.optargs) 591 592 # set and call parser 593 self.parser = argparse.ArgumentParser( 594 prog='rtplatformids', 595 add_help=False, 596 description=""" 597 The 'rtplatformids' command line interface provides basic 598 dialogue access to the library modules of 'platformids'. 599 600 """, 601 formatter_class=FormatTextRaw, 602 fromfile_prefix_chars=_fromfile # from early fetch 603 ) 604 605 group_options = self.parser.add_argument_group( 606 'Parameter:', 607 'When at least one is active the selected are displayed only, else all.' 608 ) 609 group_options.add_argument( 610 '--category', 611 '-category', 612 nargs=0, 613 default=False, 614 action=OptActionCategory, 615 help="@R:" + OptActionCategory.__doc__ 616 ) 617 group_options.add_argument( 618 '--ostype', 619 '-ostype', 620 nargs=0, 621 default=False, 622 action=OptActionOstype, 623 help="@R:" + OptActionOstype.__doc__ 624 ) 625 group_options.add_argument( 626 '--dist', 627 '-dist', 628 nargs=0, 629 default=False, 630 action=OptActionDist, 631 help="@R:" + OptActionDist.__doc__ 632 ) 633 group_options.add_argument( 634 '--distrel', 635 '-distrel', 636 nargs=0, 637 default=False, 638 action=OptActionDistRel, 639 help="@R:" + OptActionDistRel.__doc__ 640 ) 641 group_options.add_argument( 642 '--distrel-name', 643 '-distrel-name', 644 nargs=0, 645 default=False, 646 action=OptActionDistRelName, 647 help="@R:" + OptActionDistRelName.__doc__ 648 ) 649 group_options.add_argument( 650 '--distrel-key', 651 '-distrel-key', 652 nargs=0, 653 default=False, 654 action=OptActionDistRelKey, 655 help="@R:" + OptActionDistRelKey.__doc__ 656 ) 657 group_options.add_argument( 658 '--distrel-version', 659 '-distrel-version', 660 '--dist-vers', 661 '-dist-vers', 662 nargs=0, 663 default=False, 664 action=OptActionDistVers, 665 help="@R:" + OptActionDistVers.__doc__ 666 ) 667 group_options.add_argument( 668 '--distrel-hexversion', 669 '-distrel-hexversion', 670 nargs=0, 671 default=False, 672 action=OptActionDistRelHexversion, 673 help="@R:" + OptActionDistRelHexversion.__doc__ 674 ) 675 group_options.add_argument( 676 '--ostype-id', 677 '-ostype-id', 678 nargs=0, 679 default=False, 680 action=OptActionOstypeId, 681 help="@R:" + OptActionOstypeId.__doc__ 682 ) 683 group_options.add_argument( 684 '--ostype-version', 685 '-ostype-version', 686 nargs=0, 687 default=False, 688 action=OptActionOstypeVers, 689 help="@R:" + OptActionOstypeVers.__doc__ 690 ) 691 group_options.add_argument( 692 '--platform', 693 '-platform', 694 nargs=0, 695 default=False, 696 action=OptActionPlatform, 697 help="@R:" + OptActionPlatform.__doc__ 698 ) 699 group_options.add_argument( 700 '--raw', 701 '-raw', 702 nargs=0, 703 default=False, 704 action=OptActionRaw, 705 help="@R:" + OptActionRaw.__doc__ 706 ) 707 708 group_options = self.parser.add_argument_group( 709 'Developer Options:', 710 'For details refer to the manual.' 711 ) 712 group_options.add_argument( 713 '--debug', 714 '-debug', 715 '-d', 716 nargs='?', 717 type=int, 718 default=0, 719 const=None, 720 action=OptActionDebug, 721 help="@R:" + OptActionDebug.__doc__ 722 ) 723 group_options.add_argument( 724 '--debug-options', 725 '-debug-options', 726 nargs='*', 727 #type=str, 728 default=[], 729 #const=[ 'json', 'break',], 730 action=OptActionDebugOptions, 731 help="@R:" + OptActionDebugOptions.__doc__ 732 ) 733 group_options.add_argument( 734 '--enumerate', 735 '-enumerate', 736 nargs='*', 737 type=str, 738 default={}, 739 const={'all', 'num=int', 'scope=strkey', 'pad=on', 'reverse=false'}, 740 action=OptActionEnumerate, 741 help="@R:" + OptActionEnumerate.__doc__ 742 ) 743 group_options.add_argument( 744 '--environ', 745 '-environ', 746 '--env', 747 '-env', 748 nargs=0, 749 action=OptActionEnvironDetails, 750 default=None, 751 const=None, 752 help="@R:" + OptActionEnvironDetails.__doc__ 753 ) 754 group_options.add_argument( 755 '--fromfile', 756 '-fromfile', 757 nargs=0, 758 action=OptActionFromfile, 759 help="@R:" + OptActionFromfile.__doc__ 760 ) 761 group_options.add_argument( 762 '--load', 763 '-load', 764 nargs=1, 765 type=str, 766 default=[], 767 const=[], 768 action=OptActionLoad, 769 help="@R:" + OptActionLoad.__doc__ 770 ) 771 772 773 group_options = self.parser.add_argument_group( 774 'Generic Support Options:', 775 '' 776 ) 777 group_options.add_argument( 778 '--out-format', 779 '-out-format', 780 nargs=1, 781 type=str, 782 default='str', 783 const='json', 784 action=OptActionPrintOutFormat, 785 help="@R:" + OptActionPrintOutFormat.__doc__ 786 ) 787 group_options.add_argument( 788 '--quiet', 789 '-quiet', 790 '-q', 791 nargs=0, 792 default=False, 793 action=OptActionQuiet, 794 help="@R:" + OptActionQuiet.__doc__ 795 ) 796 group_options.add_argument( 797 '--terse', 798 '-terse', 799 '-X', 800 nargs=0, 801 default=False, 802 action=OptActionTerse, 803 help="@R:" + OptActionTerse.__doc__ 804 ) 805 group_options.add_argument( 806 '--verbose', 807 '-verbose', 808 '-v', 809 nargs='?', 810 type=int, 811 action=OptActionVerbose, 812 default=0, 813 const=0, 814 help="@R:" + OptActionVerbose.__doc__ 815 ) 816 group_options.add_argument( 817 '--version', 818 '-version', 819 nargs=0, 820 action=OptActionVersion, 821 default=None, 822 help="@R:" + OptActionVersion.__doc__ 823 ) 824 group_options.add_argument( 825 '--Version', 826 '-Version', 827 nargs=0, 828 action=OptActionVersionDetails, 829 default=None, 830 help="@R:" + OptActionVersionDetails.__doc__ 831 ) 832 group_options.add_argument( 833 '--help', 834 '-help', 835 nargs=0, 836 action=OptActionHelp, 837 default=None, 838 help="@R:" + OptActionHelp.__doc__ 839 ) 840 group_options.add_argument( 841 '-h', 842 nargs=0, 843 action=OptActionH, 844 default=None, 845 help="@R:" + OptActionH.__doc__ 846 ) 847 848 849 # defined args 850 # a little extra 851 if self.argv == sys.argv: 852 argv = self.argv[1:] 853 else: 854 argv = self.argv 855 856 # group_result = self.parser.add_argument_group( # @UnusedVariable 857 # 'RESULT:', 858 # """ 859 # Success: '0', 860 # else: != '0'. 861 # """ 862 # ) 863 864 group_see = self.parser.add_argument_group( # @UnusedVariable 865 'SEE ALSO:', 866 """ 867 https://pypi.org/project/platformids/ 868 https://platformids.sourceforge.io/ 869 """ 870 ) 871 872 group_copyright = self.parser.add_argument_group( # @UnusedVariable 873 'COPYRIGHT:', 874 """Arno-Can Uestuensoez (C)2008-2018 @Ingenieurbuero Arno-Can Uestuensoez""", 875 ) 876 877 # defined args 878 if "--" in argv: 879 idx = argv.index('--') 880 opts, unknown = self.parser.parse_known_args(argv, namespace=_myspace) 881 args = argv[idx + 1:] 882 else: 883 opts, unknown = self.parser.parse_known_args(argv, namespace=_myspace) 884 args = [] 885 # args = opts.ARGS 886 887 # for later post-processing 888 self.opts = _myspace 889 self.args = args 890 self.unknown = unknown 891 892 if unknown: 893 raise PlatformIDsError("Unknown options:" + str(unknown)) 894 895 if platformids._debug: 896 if RTE & RTE_WIN32: 897 sys.stderr.write("DBG:PLATFORMIDS:CLI:PID=%d\n" % (os.getpid(),)) 898 else: 899 sys.stderr.write( 900 "DBG:PLATFORMIDS:CLI:PID=%d, PPID=%d\n" % ( 901 os.getpid(), os.getppid(),) # @UndefinedVariable 902 ) 903 904 if _myspace.debug_options: 905 if self.opts.debug_options[0] == 'str': 906 for k,v, in self.get_items(): 907 print("%-20s: %s" % (k, v,)) 908 elif self.opts.debug_options[0] == 'repr': 909 print(repr(self.get_JSON_bin())) 910 elif self.opts.debug_options[0] == 'json': 911 import jsondata.jsondata 912 print(str(jsondata.jsondata.JSONData(self.get_JSON_bin()))) 913 else: 914 raise PlatformIDsError("Output format not supported for options print:" + str(self.opts.out_format)) 915 916 if len(self.opts.debug_options) == 1: 917 sys.exit(0) 918 919 return opts, unknown, args
920
921 - def get_JSON_bin(self):
922 """Provides structured data of the compile task in-memory in 923 JSON format. :: 924 925 result := { 926 'params': { 927 'category': '', 928 'dist': '', 929 'distrel_version': '', 930 'distrel': '', 931 'distrel_key': '', 932 'distrel_name': '', 933 'distrel_hexversion': '', 934 'ostype_hexversion': '', 935 'ostype': '' 936 }, 937 'selected': '', 938 'load': '' 939 'enumerate': '' 940 'platform': '' 941 'raw': '' 942 943 'debug': '', 944 'debug_options': '', 945 'outform': { 946 'out_format': '', 947 }, 948 'quiet': '', 949 'terse': '' 950 'verbose': '', 951 952 'args': [], 953 } 954 """ 955 j = {} 956 j['params'] = {} 957 j['params']['category'] = self.opts.category 958 j['params']['dist'] = self.opts.dist 959 j['params']['distrel_version'] = self.opts.distrel_version 960 j['params']['distrel'] = self.opts.distrel 961 j['params']['distrel_hexversion'] = self.opts.distrel_hexversion 962 j['params']['distrel_key'] = self.opts.distrel_key 963 j['params']['distrel_name'] = self.opts.distrel_name 964 j['params']['ostype_version'] = self.opts.ostype_version 965 j['params']['ostype'] = self.opts.ostype 966 j['selected'] = self.opts.selected 967 968 j['load'] = self.opts.load 969 j['enumerate'] = self.opts.enumerate 970 j['platform'] = self.opts.platform 971 j['raw'] = self.opts.platform 972 973 j['debug'] = self.opts.debug 974 j['debug_options'] = self.opts.debug_options 975 j['outform'] = {} 976 j['outform']['out_format'] = self.opts.out_format 977 j['quiet'] = self.opts.quiet 978 j['terse'] = self.opts.terse 979 j['verbose'] = self.opts.verbose 980 981 j['args'] = self.args 982 983 return j
984
985 - def get_items(self):
986 """Provides a list of flat str-value tuples :: 987 988 result := [ 989 ('category', ''), 990 ('dist', ''), 991 ('distrel_version', ''), 992 ('distrel', ''), 993 ('distrel_key', ''), 994 ('distrel_name', ''), 995 ('hexversion', ''), 996 ('ostype_version', ''), 997 ('ostype', ''), 998 ('selected', ''), 999 1000 ('load', ''), 1001 ('enumerate', ''), 1002 ('platform', ''), 1003 ('raw', ''), 1004 1005 ('debug', ''), 1006 ('debug_options', ''), 1007 ('out_format', ''), 1008 ('quiet', ''), 1009 ('terse', ''), 1010 ('verbose', ''), 1011 ] 1012 """ 1013 return [ 1014 ('category', self.opts.category), 1015 ('dist', self.opts.dist), 1016 ('distrel_version', self.opts.distrel_version), 1017 ('distrel', self.opts.distrel), 1018 ('distrel_key', self.opts.distrel_key), 1019 ('distrel_name', self.opts.distrel_name), 1020 ('hexversion', self.opts.hexversion), 1021 ('ostype_version', self.opts.ostype_version), 1022 ('ostype', self.opts.ostype), 1023 ('selected', self.opts.selected), 1024 1025 ('load', self.opts.load), 1026 ('enumerate', self.opts.enumerate), 1027 ('platform', self.opts.platform), 1028 ('raw', self.opts.raw), 1029 1030 ('debug', self.opts.debug), 1031 ('debug_options', self.opts.debug_options), 1032 ('out_format', self.opts.out_format), 1033 ('quiet', self.opts.quiet), 1034 ('terse', self.opts.terse), 1035 ('verbose', self.opts.verbose), 1036 ]
1037
1038 - def print_usage(self, *args):
1039 self.parser.print_usage(*args)
1040
1041 - def print_help(self, *args):
1042 self.parser.print_help(*args)
1043