Package epyunit :: Package debug :: Module checkRDbg
[hide private]
[frames] | no frames]

Source Code for Module epyunit.debug.checkRDbg

  1  # -*- coding: utf -*- 
  2  """Provides a slim interface for the initialization and extraction of command line parameters for pydevrdc. 
  3   
  4  Extracts rdbg-options and provides values for the main module 'epyunit.debug.pydevrdc'. 
  5  """ 
  6  from __future__ import absolute_import 
  7   
  8  __author__ = 'Arno-Can Uestuensoez' 
  9  __license__ = "Artistic-License-2.0 + Forced-Fairplay-Constraints" 
 10  __copyright__ = "Copyright (C) 2010-2016 Arno-Can Uestuensoez @Ingenieurbuero Arno-Can Uestuensoez" 
 11  __version__ = '0.2.1' 
 12  __uuid__='9de52399-7752-4633-9fdc-66c87a9200b8' 
 13   
 14  __docformat__ = "restructuredtext en" 
 15   
 16  import sys,os,re 
 17  from types import NoneType 
 18   
 19  version = '{0}.{1}'.format(*sys.version_info[:2]) 
 20  if not version in ('2.6', '2.7',): # pragma: no cover 
 21      raise Exception("Requires Python-2.6.* or higher") 
 22   
 23   
 24  _pderd_inTestMode_suppress_init = False 
 25  """Forces test mode, enables the setting of partially erroneous parameters.""" 
 26   
 27  _testflags = None 
 28  """Testflags""" 
 29   
 30  _testflags_valid = ['ignorePydevd','ignorePydevdSysPath','ignorePydevdCallParam',] 
 31  """Valid values for testflags""" 
 32   
 33   
 34  _dbg_self = False 
 35  """Debugs the debugging.""" 
 36   
 37  _dbg_unit = False 
 38  """Debugs units.""" 
 39   
 40  _rdbgroot_default = '' 
 41  """Platform specific Default root for eclipse.""" 
 42  # 
 43  # Initialize for current platform 
 44  # 
 45  if sys.platform.startswith('linux'): # Linux 
 46      _rdbgroot_default = os.environ['HOME']+os.sep+'eclipse' 
 47  elif 'win32' in sys.platform : # Windows 
 48      _rdbgroot_default = "C:\eclipse" 
 49  elif sys.platform in ('cygwin',): # Cygwin 
 50      _rdbgroot_default = "/cygdrive/c/eclipse" 
 51  elif sys.platform in ('darwin'): # Mac-OS 
 52      _rdbgroot_default = os.environ['HOME']+os.sep+'eclipse' 
 53  else: # Else: Unix, BSD 
 54      _rdbgroot_default = os.environ['HOME']+os.sep+'eclipse' 
 55   
 56  _rdbgsub_default = "org.python.pydev_[0-9]*.[0-9]*.[0-9]*/pysrc/pydevd.py" 
 57  """Default eclipse sub path.""" 
 58   
 59  _rdbgfwd_default = 0 
 60  """Control of forwarding the debugging enabled state. 
 61  Possible values are: 
 62   
 63      hopcnt: The nested subprocesses to be debugged. 
 64   
 65          hopcnt >=0 : The number of nested subprocess 
 66              hops to be debugged. 
 67   
 68          hopcnt <0 : The number of nested subprocess 
 69              hops NOT to be debugged. 
 70   
 71      'all': Debug all nested levels of subprocesses. 
 72   
 73      label: Activate remote debug for the process with the previously 
 74          assigned label only. 
 75   
 76      label = [label-lst]: List of labels. 
 77   
 78  """ 
 79   
 80  _rdbg_default = "localhost:5678" 
 81  """The default values for the peer RemoteDebugServer as defined by PyDev.""" 
 82   
 83  rdbgoptions = None 
 84  """The cached options from sys.argv by checkAndRemoveRDbgOptions.""" 
 85   
 86  # 
 87  # The current values for external module access 
 88  # 
 89  _rdbgthis = False 
 90  _rdbgsrv = _rdbg_default 
 91  _rdbgfwd  = _rdbgfwd_default 
 92  _rdbgroot = _rdbgroot_default 
 93  _rdbgsub  = _rdbgsub_default 
 94  _rdbgoptions = (_rdbgthis,_rdbgsrv,_rdbgfwd,_rdbgroot,_rdbgsub,) 
 95   
 96  _verbose = False 
 97  # 
 98  # static re 
 99  # 
100  _reRDSAddr = re.compile(ur"([^:]*):([^:]*)") 
101  # 
102  # RemoteDebugServer address 
103  if "win32" in sys.platform: 
104      _reHostOnly  = re.compile(ur"""^[^:\\\\]+$""") 
105  else: 
106      _reHostOnly  = re.compile(ur"""^[^:"""+os.sep+"""]+$""") 
107  _rePortOnly  = re.compile(ur"""^:[0-9]+$""") 
108  _reHostPort  = re.compile(ur"""^([^:]+):([0-9]+)$""") 
109   
110  _rdbgenv = False 
111  """Force or prohibit the read of environment variables, by default used in priority order when present.""" 
112   
113  # 
114  # buffer for options evaluation 
115  _clibuf = [] 
116   
117 -class checkAndRemoveRDbgOptionsException(Exception):
118 pass
119
120 -def checkAndRemoveRDbgOptions(argv=None,**kargs):
121 """Checks input options from sys.argv and returns the tuple of resulting 122 debug parameters. The options are removed from sys.argv by default. 123 124 The options are kept as provided, or when missing filled with default values. 125 The final resolution of the values like file system globs is performed within 126 the PyDevRDC class. 127 128 The following options are checked and removed from sys.argv, thus by default 129 has to be added by the caller application again when required for following 130 nested calls: 131 132 --rdbg [[host]:[port]]: 133 134 Enables debugging of subprocesses via RemoteDebugServer. By default 135 for local instance 'localhost:5679', provides optionally altered 136 connection parameters: 137 138 host: Host address, DNS or IP. 139 140 port: Port number. 141 142 --rdbg-env: 143 144 Forces or disables the use of specific environment variables. 145 :: 146 147 RDBGROOT, RDBGSUB 148 149 * True: Forces the use of present variables 150 151 * False: disables use 152 153 * default: Applied in normal order when scanning the filesystem 154 155 --rdbg-forward [<depth>]: 156 157 Defines forwarding of debugging state, either by passing 158 the current instance, or by additionally debugging the next level(s) 159 of nested subprocesses. The value of <depth> is one of: 160 161 #hopcnt: Number of levels for nested subprocesses. 162 163 'all': All nested levels. 164 165 label: The subprocesses with matching label only. 166 167 The design of passing options into nested calls is considered as 168 insertion of the forwarded options before the first option of the next 169 level caller: 170 :: 171 172 epyu --rdbg --rdbg-froward=2 nextlevel -a --bxy .... 173 174 This results in: 175 :: 176 177 nextlevel --rdbg --rdbg-froward=2 -a --bxy .... 178 179 In case of optional sub-parameters the temination option '--' 180 could be applied: 181 :: 182 183 epyu --rdbg --rdbg-froward=2 nextlevel -- arguments 184 185 results in: 186 :: 187 188 nextlevel --rdbg --rdbg-froward=2 -- arguments 189 190 The current version requiresthis to be proceeded by the application, 191 refer to 'epyu..py'. 192 193 --rdbg-root (<rootforscan>|<FQDN>|<path-glob>): 194 195 Defines the initial root path for scan, the following defaults 196 are scanned initially when this parameter is provided without 197 a value. 198 199 Linux, BSD, and Unix: 200 :: 201 202 $HOME/eclipse 203 204 Mac-OS: 205 :: 206 207 $HOME/eclipse 208 209 Windows: 210 :: 211 212 C:\eclipse 213 214 Cygwin: 215 :: 216 217 /cygdrive/c/eclipse 218 219 When the value is not found, the additional defaults 220 are scanned as provided by 'PyDevRDC.scanEclipseForPydevd'. 221 222 Each root is searched by the the following order of 223 sub-pattern matching. 224 :: 225 226 0. plugins/<rdbgsub> 227 228 1. dropins/<rdbgsub> 229 230 2. dropins/*/plugins/<rdbgsub> 231 232 For details refer to 'pydevrdc.scanEclipseForPydevd' 233 `[see] <pydeverdbg.html#scaneclipseforpydevd>`_. 234 235 --rdbg-sub (<literal>|<path-glob>): 236 237 Defines the initial subpath within the Eclipse installation. 238 When not present, the extended defaults are scanned, for 239 further details refer to 'PyDevRDC.scanEclipseForPydevd': 240 :: 241 242 pydevd_subpath = "org.python.pydev_[0-9]*.[0-9]*.[0-9]*/pysrc/pydevd.py" 243 244 Test options and flags: 245 246 --pderd_inTestMode_suppress_init: 247 248 Control initialization of the preconfigured debug stub. 249 It is foreseen to be the only instance under normal 250 circumstances. 251 252 --pderd_debug_self: 253 254 Enabled debugging messages for debug, this also includes 255 the pre-debug initialization of the remote debug server. 256 257 --pderd_unit_self: 258 259 Enabled log messages for unittests. 260 261 --pderd_testflags: 262 263 Sets specific testflags, valid values for testflags are: 264 265 ignorePydevd: ignores loaded pydevd.py, for search test only 266 267 ignorePydevdSysPath: ignores sys.path, for search test only 268 269 ignorePydevdCallParam: ignores call parameters 270 271 Environment variables: 272 273 The provided environment variables are read out, when no related 274 option is available. In case both are not provided, the hard-coded 275 defaults are applied. The read of environment variables could be 276 supressed in general by the option 'noenv'/'--no-env'. 277 278 RDBGROOT => --rdbg-root 279 280 RDBGSUB => --rdbg-sub 281 282 Args: 283 284 argv: Alternative argv, default:=sys.argv 285 286 **kargs: 287 288 debug: 289 290 Same as '--debug', developer output. 291 292 fpname: 293 294 The file path name of the main file for the current 295 process, default:=callname. 296 297 label: 298 299 The label identifying the current process, default:=callname. 300 301 noargv: 302 303 Suppresses argv processing completely for the previous 304 arguments. The testflags are still processed. 305 306 rdbg: 307 308 Same as '--rdbg', for additional processing see 'noargv'. 309 310 rdbgsrv: 311 312 Same as '--rdbg'srv, for additional processing see 'noargv'. 313 314 rdbgforward: 315 316 Same as '--rdbg-forward', for additional processing see 'noargv'. 317 318 rdbgroot: 319 320 Same as '--rdbg-root', for additional processing see 'noargv'. 321 322 rdbgsub: 323 324 Same as '--rdbg-sub', for additional processing see 'noargv'. 325 326 verbose: 327 328 Same as '--verbose', user output. 329 330 Returns: 331 When successful returns tuple of the following debug parameters. The 332 options are removed from 'sys.argv'. 333 334 return/value := ( rdbgthis, rdbg, rdbgfwd, rdbgroot, rdbgsub, ) 335 336 rdbgthis = (True|False): Debugging of current process/thread is enabled. 337 338 rdbg = [host][:port]: Connection parameter of peer RemoteDebugServer 339 340 rdbgfwd = <partialprocessed>: Forward debug parameters 341 342 partialprocessed: One of: 343 344 hop = hopcnt - 1 345 346 'all' 347 348 label 349 350 rdbgroot = <rootforscan>: Base for search, when None the defaults apply. 351 352 rdbgsub = <eclipse-subpath>: Subpath within Eclipse. 353 354 Raises: 355 356 """ 357 358 # print "4TEST:A:"+str(argv) 359 # print "4TEST:K:"+str(kargs) 360 361 362 global _pderd_inTestMode_suppress_init 363 global _dbg_self 364 global _dbg_unit 365 global _verbose 366 367 global _rdbgoptions 368 global _rdbgenv 369 global _rdbgthis 370 global _rdbgsrv 371 global _rdbgfwd 372 global _rdbgroot 373 global _rdbgsub 374 375 global _testflags 376 377 _noarg = False 378 _rdbg = False 379 380 _verbose = False 381 382 _argv = False 383 _argvclr = False 384 385 _lbl = None 386 _fpname = None 387 388 for k,v in kargs.items(): 389 if k == 'label': 390 _lbl = v 391 392 elif k == 'fpname': 393 _fpname = v 394 395 elif k == 'rdbg': 396 _rdbg = True 397 _rdbgthis = True 398 _rdbgsrv = v 399 400 elif k == 'rdbgsrv': 401 _rdbg = True 402 _rdbgsrv = v 403 404 elif k == 'rdbgforward': 405 _rdbg = True 406 _rdbgfwd = v 407 _rdbgthis = True 408 409 elif k == 'rdbgroot': 410 _rdbgroot = v 411 412 elif k == 'rdbgsub': 413 _rdbgsub = v 414 415 elif k == 'rdbgenv': 416 _rdbgenv = v 417 418 elif k == 'noargv': 419 _noarg = v 420 421 elif k == 'argv': 422 _argv = v 423 424 elif k == 'argvclear': 425 _argv = v 426 _argvclr = v 427 428 elif k == 'verbose': 429 _verbose = v 430 431 elif k == 'debug': 432 _dbg_self = v 433 434 else: 435 raise Exception("Unknown option:"+str(k)) 436 437 # prep argv for extraction of rdbg options 438 if argv and type(argv) in (str,unicode,): 439 _ty = argv.split() 440 elif argv == None: 441 _ty = sys.argv 442 else: 443 _ty = argv 444 445 # label of current process 446 if not _lbl: 447 _lbl = os.path.basename(_ty[0]) 448 if not _fpname: 449 _fpname = os.path.abspath(_ty[0]) 450 451 # prevents init, for test only 452 if '--pderd_inTestMode_suppress_init' in _ty: 453 _pderd_inTestMode_suppress_init = True 454 for px in _ty: 455 _ty.pop(_ty.index(px)) 456 else: 457 _pderd_inTestMode_suppress_init = False 458 459 # activates self debug 460 if '--pderd_debug_self' in _ty: 461 _dbg_self = True 462 _ty.pop(_ty.index('--pderd_debug_self')) 463 else: 464 _dbg_self = False 465 466 # activates self unittests 467 if '--pderd_unit_self' in _ty: 468 _dbg_unit = True 469 _ty.pop(_ty.index('--pderd_unit_self')) 470 else: 471 _dbg_unit = False 472 473 global _clibuf 474 import argparse 475 class RDBGSaction(argparse.Action): 476 """Connection parameters for the RemoteDebugServer - --rdbg 477 """ 478 def __init__(self, option_strings, dest, nargs=None, **kwargs): 479 super(RDBGSaction, self).__init__(option_strings, dest, nargs, **kwargs)
480 481 def __call__(self, parser, namespace, values, option_string=None): 482 _ix=-1 483 _eq = False 484 try: 485 _ix = namespace._argv.index(option_string) 486 except: 487 try: 488 _ix = namespace._argv.index(option_string+"="+values) 489 _eq = True 490 except: 491 pass 492 if _ix>0: 493 _ai = namespace._argv.pop(_ix) 494 if not values: 495 #print '%r %r %r' % (namespace, _rdbg_default, option_string) 496 setattr(namespace, self.dest, _rdbg_default) 497 return 498 elif _reHostOnly.match(values): 499 #print '%r %r %r' % (namespace, values+":5678", option_string) 500 setattr(namespace, self.dest, values+":5678") 501 elif _rePortOnly.match(values): 502 #print '%r %r %r' % (namespace, "localhost"+values, option_string) 503 setattr(namespace, self.dest, "localhost"+values) 504 elif _reHostPort.match(values): 505 #print '%r %r %r' % (namespace, values, option_string) 506 setattr(namespace, self.dest, values) 507 else: # no valid argument 508 #print '%r %r %r' % (namespace, _rdbg_default, option_string) 509 setattr(namespace, self.dest, _rdbg_default) 510 return 511 if not _eq: 512 _ix = namespace._argv.index(values) 513 _ai = namespace._argv.pop(_ix) 514 515 class FWDaction(argparse.Action): 516 """Enabling nested subprocesses by forwarding - --rdbg-forward 517 """ 518 def __call__(self, parser, namespace, values, option_string=None): 519 _ix=-1 520 _eq = False 521 try: 522 _ix = namespace._argv.index(option_string) 523 except: 524 try: 525 _ix = namespace._argv.index(option_string+"="+values) 526 _eq = True 527 except: 528 pass 529 if _ix>0: 530 _ai = namespace._argv.pop(_ix) 531 532 if not values: # default 533 #print '%r %r %r' % (namespace, _rdbgfwd_default, option_string) 534 setattr(namespace, self.dest, _rdbgfwd_default) 535 return 536 537 elif type(values) is int and values > 0: # integer 538 #print '%r %r %r' % (namespace, values-1, option_string) 539 setattr(namespace, self.dest, (values)) 540 541 elif values.isdigit() and int(values) > 0: # integer 542 #print '%r %r %r' % (namespace, values-1, option_string) 543 setattr(namespace, self.dest, int(values)) 544 545 elif values == 'all': # all levels 546 #print '%r %r %r' % (namespace, values, option_string) 547 setattr(namespace, self.dest, values) 548 549 if not _eq: 550 _ix = namespace._argv.index(values) 551 _ai = namespace._argv.pop(_ix) 552 553 class ROOTaction(argparse.Action): 554 """Set the root for scan - --rdbg-root 555 """ 556 def __call__(self, parser, namespace, values, option_string=None): 557 _ix=-1 558 _eq = False 559 try: 560 _ix = namespace._argv.index(option_string) 561 except: 562 try: 563 _ix = namespace._argv.index(option_string+"="+values) 564 _eq = True 565 except: 566 pass 567 if _ix>0: 568 _ai = namespace._argv.pop(_ix) 569 570 if not values: 571 #print '%r %r %r' % (namespace, _rdbgroot_default, option_string) 572 setattr(namespace, self.dest, _rdbgroot_default) 573 return 574 575 else: 576 #print '%r %r %r' % (namespace, values, option_string) 577 setattr(namespace, self.dest, values) 578 579 if not _eq: 580 _ix = namespace._argv.index(values) 581 _ai = namespace._argv.pop(_ix) 582 583 class SUBaction(argparse.Action): 584 """Set the subdirectory in 'plugins' for scan - --rdbg-sub 585 """ 586 def __call__(self, parser, namespace, values, option_string=None): 587 _ix=-1 588 _eq = False 589 try: 590 _ix = namespace._argv.index(option_string) 591 except: 592 try: 593 _ix = namespace._argv.index(option_string+"="+values) 594 _eq = True 595 except: 596 pass 597 if _ix>0: 598 _ai = namespace._argv.pop(_ix) 599 600 if not values: 601 #print '%r %r %r' % (namespace, _rdbgsub_default, option_string) 602 setattr(namespace, self.dest, _rdbgsub_default) 603 else: 604 #print '%r %r %r' % (namespace, values, option_string) 605 setattr(namespace, self.dest, values) 606 607 if not _eq: 608 _ix = namespace._argv.index(values) 609 _ai = namespace._argv.pop(_ix) 610 611 class ENVaction(argparse.Action): 612 """Enable/Disable the environment variables RDBGROOT and RDBGSUB - --rdbg-env 613 """ 614 def __call__(self, parser, namespace, values, option_string=None): 615 _ix=-1 616 _eq = False 617 try: 618 _ix = namespace._argv.index(option_string) 619 except: 620 try: 621 _ix = namespace._argv.index(option_string+"="+values) 622 _eq = True 623 except: 624 pass 625 if _ix>0: 626 _ai = namespace._argv.pop(_ix) 627 628 if type(values) is NoneType: 629 #print '%r %r %r' % (namespace, _rdbgsub_default, option_string) 630 setattr(namespace, self.dest, True) 631 else: 632 #print '%r %r %r' % (namespace, values, option_string) 633 if values.lower() in ('on','true','1',True,1,): 634 setattr(namespace, self.dest, True) 635 elif values.lower() in ('off','false','0',False,0,): 636 setattr(namespace, self.dest, False) 637 else: 638 raise checkAndRemoveRDbgOptionsException("Unknown value:"+str(values)) 639 if not _eq and values: 640 _ix = namespace._argv.index(values) 641 _ai = namespace._argv.pop(_ix) 642 643 class DBGaction(argparse.Action): 644 """Set the debugging of RDBG itself for scan - --rdbg-self 645 """ 646 def __call__(self, parser, namespace, values, option_string=None): 647 _ix=-1 648 _eq = False 649 try: 650 _ix = namespace._argv.index(option_string) 651 except: 652 try: 653 _ix = namespace._argv.index(option_string+"="+values) 654 _eq = True 655 except: 656 pass 657 if _ix>0: 658 _ai = namespace._argv.pop(_ix) 659 660 if type(values) is NoneType: 661 #print '%r %r %r' % (namespace, _rdbgsub_default, option_string) 662 setattr(namespace, self.dest, True) 663 else: 664 #print '%r %r %r' % (namespace, values, option_string) 665 setattr(namespace, self.dest, values) 666 667 if not _eq: 668 if values: 669 _ix = namespace._argv.index(values) 670 _ai = namespace._argv.pop(_ix) 671 672 class TFLAGaction(argparse.Action): 673 """Set for the debugging of RDBG itself some testflags --pderd_testflags 674 For valid values see '_testflags_valid' 675 """ 676 def __call__(self, parser, namespace, values, option_string=None): 677 _ix=-1 678 _eq = False 679 try: 680 _ix = namespace._argv.index(option_string) 681 except: 682 try: 683 _ix = namespace._argv.index(option_string+"="+values) 684 _eq = True 685 except: 686 pass 687 if _ix>0: 688 _ai = namespace._argv.pop(_ix) 689 690 if type(values) is NoneType: 691 #print '%r %r %r' % (namespace, _rdbgsub_default, option_string) 692 setattr(namespace, self.dest, [_testflags_valid[0]]) 693 else: 694 #print '%r %r %r' % (namespace, values, option_string) 695 _tfv = [] 696 for tf in values.split(','): 697 if tf in _testflags_valid: 698 _tfv.append(tf) 699 pass 700 else: 701 raise checkAndRemoveRDbgOptionsException("Unknown value "+str(option_string)+"="+str(values)) 702 _testflags = _tfv 703 setattr(namespace, self.dest, _testflags) 704 705 if not _eq: 706 if values: 707 _ix = namespace._argv.index(values) 708 _ai = namespace._argv.pop(_ix) 709 710 class Sx(object): 711 def __init__(self): 712 self._argv = _ty 713 self.rdbgenv = _rdbgenv 714 715 _myspace = Sx() 716 parser = argparse.ArgumentParser() 717 parser.add_argument('--rdbg',nargs='?',action=RDBGSaction,default=None) 718 parser.add_argument('--rdbg-forward',nargs='?',action=FWDaction,default=None) 719 parser.add_argument('--rdbg-root',nargs='?',action=ROOTaction,default=None) 720 parser.add_argument('--rdbg-sub',nargs='?',action=SUBaction,default=None) 721 parser.add_argument('--rdbg-env',nargs='?',action=ENVaction,default=None) 722 parser.add_argument('--rdbg-self',nargs='?',action=DBGaction,default=None) 723 724 parser.add_argument('--pderd_testflags',nargs='?',action=TFLAGaction,default=None) 725 726 _clibuf = parser.parse_known_args(_ty,namespace=_myspace) 727 if type(_clibuf[0].rdbg_env) is NoneType: 728 _rdbgenv = _clibuf[0].rdbg_env 729 730 if _clibuf[0].rdbg or _clibuf[0].rdbg_forward: 731 _rdbg = True 732 else: 733 if _clibuf[0].rdbg_root: 734 raise checkAndRemoveRDbgOptionsException("Missing activation option '--rdbg', provided:'--rdbg-root'") 735 if _clibuf[0].rdbg_sub: 736 raise checkAndRemoveRDbgOptionsException("Missing activation option '--rdbg', provided:'--rdbg-sub'") 737 738 739 _rdbgenv = _clibuf[0].rdbg_env 740 741 if _clibuf[0].rdbg: 742 _rdbg = True 743 _rdbgsrv = _clibuf[0].rdbg 744 745 import socket 746 hn = socket.gethostbyaddr(socket.gethostname()) 747 748 if _clibuf[0].rdbg.startswith('localhost') or _clibuf[0].rdbg.startswith('127.0.0.1'): 749 _rdbgthis = True 750 751 elif _clibuf[0].rdbg == hn[0] or _clibuf[0].rdbg in hn[1] or _clibuf[0].rdbg in hn[2]: 752 _rdbgthis = True 753 754 if _rdbg: # modify only valid options 755 if type(_clibuf[0].rdbg_forward) != NoneType: 756 _rdbgfwd = _clibuf[0].rdbg_forward 757 if type(_clibuf[0].rdbg_root) != NoneType: 758 _rdbgroot = _clibuf[0].rdbg_root 759 if type(_clibuf[0].rdbg_sub) != NoneType: 760 _rdbgsub = _clibuf[0].rdbg_sub 761 if type(_clibuf[0].rdbg_self) != NoneType: 762 _dbg_self = _clibuf[0].rdbg_self 763 764 if type(_clibuf[0].pderd_testflags) != NoneType: 765 _testflags = _clibuf[0].pderd_testflags 766 767 if _dbg_self: 768 print >>sys.stderr, "RDBG:"+__name__+":_rdbgenv="+str(_rdbgenv) 769 print >>sys.stderr, "RDBG:"+__name__+":_rdbgthis="+str(_rdbgthis) 770 print >>sys.stderr, "RDBG:"+__name__+":_rdbgsrv="+str(_rdbgsrv) 771 print >>sys.stderr, "RDBG:"+__name__+":_rdbgfwd="+str(_rdbgfwd) 772 print >>sys.stderr, "RDBG:"+__name__+":_rdbgroot="+str(_rdbgroot) 773 print >>sys.stderr, "RDBG:"+__name__+":_rdbgsub="+str(_rdbgsub) 774 775 print >>sys.stderr, "RDBG:"+__name__+":_testflags="+str(_testflags) 776 777 _ty = _clibuf[1] 778 779 # forwards debugging state to nested subprocesses 780 if _rdbgfwd and not _rdbgthis: 781 if _rdbgfwd.lower() == 'all': # all 782 _rdbgthis = True 783 784 elif type(_rdbgfwd) == int and _rdbgfwd: # hopcount 785 if _rdbgfwd >= 0: # debug the first: [0:hopcnt] 786 _rdbgfwd -= 1 787 if _rdbgfwd >= 0: 788 _rdbgthis = True 789 else: 790 _rdbgthis = False 791 792 else: # debug from hopcnt on: [hopcnt:] 793 _rdbgfwd += 1 794 if _rdbgfwd < 0: 795 _rdbgthis = False 796 else: 797 _rdbgthis = True 798 799 elif type(_fpname) is str and os.path.exists(_fpname): # fpname 800 if os.path.abspath(_fpname) == os.path.abspath(_ty[0]): 801 _rdbgthis = True 802 else: 803 _rdbgthis = False 804 805 elif type(_rdbgfwd) is str: # label 806 if _rdbgfwd == _lbl: 807 _rdbgthis = True 808 809 # 810 # set now missing as defaults 811 # 812 if _rdbgthis and not _rdbgsrv: 813 _rdbgsrv = _rdbg_default 814 815 if _rdbgenv: # if set, force when present 816 if os.environ.get('RDBGROOT'): 817 _rdbgroot = os.environ['RDBGROOT'] 818 if os.environ.get('RDBGSUB'): 819 _rdbgsub = os.environ['RDBGSUB'] 820 821 _rdbgoptions = (_rdbgthis,_rdbgsrv,_rdbgfwd,_rdbgroot,_rdbgsub,) 822 823 if _verbose or _dbg_self: 824 print >>sys.stderr, "RDBG:"+__name__+":_rdbgoptions="+str(_rdbgoptions) 825 826 return _rdbgoptions 827
828 -def checkRDbg(argv=None):
829 """Checks presence of '--rdbg' option. 830 831 Args: 832 argv: 833 834 Alternative argv, default:=sys.argv. 835 836 Returns: 837 838 When present True, else False. 839 840 Raises: 841 842 """ 843 if argv == NoneType: 844 return '--rdbg' in sys.argv 845 return '--rdbg' in argv
846
847 -def getDefaults(res=None):
848 """Returns the current defaults. 849 850 Args: 851 res: 852 853 Result, the type of 'res' defines the return type. 854 The default when 'None' is tuple. 855 856 Returns: 857 858 Returns the collection of default. The following options are 859 available: 860 861 res == None: (default) 862 863 result is a new created tuple: 864 865 res := ( 866 ) 867 868 res in (tuple, list,): 869 870 see default, container type as provided. 871 872 res == dict: 873 874 res := { 875 876 } 877 878 res is epyunit.Namespace 879 880 Similar to argparse.Namespace, foreseen to be used also 881 as predefined default input for 'epyunit.debug.checkRDbg'. 882 883 """ 884 pass
885 # if argv == NoneType: 886 # return '--rdbg' in sys.argv 887 # return '--rdbg' in argv 888 889
890 -def setDefaults(res=None):
891 """Sets defaults. 892 893 """ 894 global _rdbgthis 895 global _rdbgsrv 896 global _rdbgfwd 897 global _rdbgroot 898 global _rdbgsub 899 global _rdbgoptions 900 901 global _rdbgthis_default 902 global _rdbgsrv_default 903 global _rdbgfwd_default 904 global _rdbgroot_default 905 global _rdbgsub_default 906 907 _rdbgthis = False 908 _rdbgsrv = _rdbg_default 909 _rdbgfwd = _rdbgfwd_default 910 _rdbgroot = _rdbgroot_default 911 _rdbgsub = _rdbgsub_default 912 _rdbgoptions = (_rdbgthis,_rdbgsrv,_rdbgfwd,_rdbgroot,_rdbgsub,) 913 914 return True
915