def main(argv): logLevel = logging.WARN configureLogging(log, logLevel) _fixencoding() try: optlist, args = getopt.getopt(argv[1:], 'hVd:e:k:l:f:m:inpr', [ 'help', 'version', 'debug_port', 'key', 'log_level', 'log_file', 'preload', 'modules', 'interactive', 'nodebug', 'nostdin' ]) except getopt.GetoptError: msg = sys.exec_info()[0] sys.stderr.write("pydbgp: error: %s\n" % str(msg)) sys.stderr.write("See 'pydbgp --help'.\n") return 1 import locale codeset = locale.getdefaultlocale()[1] idekey = getenv('USER', getenv('USERNAME', '')) if is_v2: try: if codeset: idekey = idekey.decode(codeset) else: idekey = idekey.decode() except (UnicodeDecodeError, LookupError): log.warn("unable to decode idekey %r" % idekey) pass # nothing we can do if defaultlocale is wrong host = '127.0.0.1' port = 9000 preloadScript = None ignoreModules = [] profiling = 0 interactive = 0 nodebug = 0 redirect = 1 logFile = None for opt, optarg in optlist: if optarg and is_v2: try: if codeset: optarg = optarg.decode(codeset) else: optarg = optarg.decode() except (UnicodeDecodeError, LookupError): log.warn("unable to decode argument %s = %r" % (opt, optarg)) pass # nothing we can do if defaultlocale is wrong if opt in ('-h', '--help'): sys.stdout.write(__doc__) return 0 elif opt in ('-V', '--version'): import re kw = re.findall('\$(\w+):\s(.*?)\s\$', __revision__) sys.stderr.write("pydbgp Version %s %s %s %s %s\n"\ % ('.'.join([str(i) for i in __version__]), kw[0][0], kw[0][1], kw[1][0], kw[1][1])) return 0 elif opt in ('-d', '--debug_port'): if optarg.find(':') >= 0: host, port = optarg.split(':') port = int(port) else: host = '127.0.0.1' port = int(optarg) elif opt in ('-k', '--key'): idekey = optarg elif opt in ('-n', '--nodebug'): nodebug = 1 elif opt in ('-l', '--log_level'): level_names = dict([ (logging.getLevelName(lvl), lvl) for lvl in range(logging.NOTSET, logging.CRITICAL + 1, 10) ]) # Add the levels that have multiple names. level_names['WARN'] = logging.WARNING level_names['FATAL'] = logging.FATAL try: logLevel = level_names[optarg] except KeyError: sys.stderr.write("pydbgp: error: Invalid log level\n") sys.stderr.write("See 'pydbgp --help'.\n") return 1 elif opt in ('-f', '--log_file'): logFile = optarg elif opt in ('-e', '--preload'): preloadScript = optarg elif opt in ('-m', '--modules'): ignoreModules = optarg.split(',') elif opt in ('-p', '--profile', '--profiling'): profiling = 1 elif opt in ('-i', '--interactive'): interactive = 1 elif opt in ('-r', '--nostdin'): redirect = 0 if not port: sys.stderr.write("pydbgp: error: IDE Port not provided\n") sys.stderr.write("See 'pydbgp --help'.\n") return 1 if interactive: if not args: args = ['interactive'] if sys.path[0] != '' and os.getcwd() not in sys.path: sys.path.insert(0, os.getcwd()) if not args: sys.stderr.write("pydbgp: error: scriptname not provided\n") sys.stderr.write("See 'pydbgp --help'.\n") return 1 # handle ~ paths if not interactive: args[0] = os.path.expanduser(args[0]) args[0] = os.path.realpath(args[0]) if not os.path.exists(args[0]): sys.stderr.write("pydbgp: error: scriptname %s does not exist\n" % (args[0], )) sys.stderr.write("See 'pydbgp --help'.\n") return 1 if nodebug: dbgp.client.runWithoutDebug(args, interactive, host, port, idekey, logLevel) elif profiling: dbgp.client.runWithProfiling(args, host, port, idekey, logLevel) else: if logFile: log.addHandler(logging.FileHandler(logFile)) # Does not remove the existing default stderr handler. log.setLevel(logLevel) dbgp.client.set_thread_support(dbgp.client.backendCmd.debug_threads) client = dbgp.client.backendCmd(idekey, preloadScript, ignoreModules, module=h_main()) client.stdin_enabled = redirect try: client.connect(host, port, '__main__', args) except socket.error: return 1 if interactive and args[0] == 'interactive': cprt = 'Type "copyright", "credits" or "license" for more information.' sys.stdout.write("Python %s on %s\n%s\n" % (sys.version, sys.platform, cprt)) # wait until exit client.runInteractive() else: client.runMain(args, interactive) return 0
def main(argv): logLevel = logging.WARN configureLogging(log, logLevel) _fixencoding() try: optlist, args = getopt.getopt(argv[1:], 'hVd:e:k:l:f:m:inpr', ['help', 'version', 'debug_port', 'key', 'log_level', 'log_file', 'preload', 'modules', 'interactive', 'nodebug', 'nostdin']) except getopt.GetoptError: msg = sys.exec_info()[0] sys.stderr.write("pydbgp: error: %s\n" % str(msg)) sys.stderr.write("See 'pydbgp --help'.\n") return 1 import locale codeset = locale.getdefaultlocale()[1] idekey = getenv('USER', getenv('USERNAME', '')) if is_v2: try: if codeset: idekey = idekey.decode(codeset) else: idekey = idekey.decode() except (UnicodeDecodeError, LookupError): log.warn("unable to decode idekey %r"%idekey) pass # nothing we can do if defaultlocale is wrong host = '127.0.0.1' port = 9000 preloadScript = None ignoreModules = [] profiling = 0 interactive = 0 nodebug = 0 redirect = 1 logFile = None for opt, optarg in optlist: if optarg and is_v2: try: if codeset: optarg = optarg.decode(codeset) else: optarg = optarg.decode() except (UnicodeDecodeError, LookupError): log.warn("unable to decode argument %s = %r"%(opt,optarg)) pass # nothing we can do if defaultlocale is wrong if opt in ('-h', '--help'): sys.stdout.write(__doc__) return 0 elif opt in ('-V', '--version'): import re kw = re.findall('\$(\w+):\s(.*?)\s\$', __revision__) sys.stderr.write("pydbgp Version %s %s %s %s %s\n"\ % ('.'.join([str(i) for i in __version__]), kw[0][0], kw[0][1], kw[1][0], kw[1][1])) return 0 elif opt in ('-d', '--debug_port'): if optarg.find(':') >= 0: host, port = optarg.split(':') port = int(port) else: host = '127.0.0.1' port = int(optarg) elif opt in ('-k', '--key'): idekey = optarg elif opt in ('-n', '--nodebug'): nodebug = 1 elif opt in ('-l', '--log_level'): level_names = dict([ (logging.getLevelName(lvl), lvl) for lvl in range(logging.NOTSET, logging.CRITICAL+1, 10) ]) # Add the levels that have multiple names. level_names['WARN'] = logging.WARNING level_names['FATAL'] = logging.FATAL try: logLevel = level_names[optarg] except KeyError: sys.stderr.write("pydbgp: error: Invalid log level\n") sys.stderr.write("See 'pydbgp --help'.\n") return 1 elif opt in ('-f', '--log_file'): logFile = optarg elif opt in ('-e', '--preload'): preloadScript = optarg elif opt in ('-m', '--modules'): ignoreModules = optarg.split(',') elif opt in ('-p', '--profile', '--profiling'): profiling = 1 elif opt in ('-i', '--interactive'): interactive = 1 elif opt in ('-r', '--nostdin'): redirect = 0 if not port: sys.stderr.write("pydbgp: error: IDE Port not provided\n") sys.stderr.write("See 'pydbgp --help'.\n") return 1 if interactive: if not args: args = ['interactive'] if sys.path[0] != '' and os.getcwd() not in sys.path: sys.path.insert(0, os.getcwd()) if not args: sys.stderr.write("pydbgp: error: scriptname not provided\n") sys.stderr.write("See 'pydbgp --help'.\n") return 1 # handle ~ paths if not interactive: args[0] = os.path.expanduser(args[0]) args[0] = os.path.realpath(args[0]) if not os.path.exists(args[0]): sys.stderr.write("pydbgp: error: scriptname %s does not exist\n" % (args[0],)) sys.stderr.write("See 'pydbgp --help'.\n") return 1 if nodebug: dbgp.client.runWithoutDebug(args, interactive, host, port, idekey, logLevel) elif profiling: dbgp.client.runWithProfiling(args, host, port, idekey, logLevel) else: if logFile: log.addHandler(logging.FileHandler(logFile)) # Does not remove the existing default stderr handler. log.setLevel(logLevel) dbgp.client.set_thread_support(dbgp.client.backendCmd.debug_threads) client = dbgp.client.backendCmd(idekey, preloadScript, ignoreModules, module=h_main()) client.stdin_enabled = redirect try: client.connect(host, port, '__main__', args) except socket.error: return 1 if interactive and args[0] == 'interactive': cprt = 'Type "copyright", "credits" or "license" for more information.' sys.stdout.write("Python %s on %s\n%s\n" % (sys.version, sys.platform, cprt)) # wait until exit client.runInteractive() else: client.runMain(args, interactive) return 0
]) except getopt.GetoptError, msg: sys.stderr.write("pydbgp: error: %s\n" % str(msg)) sys.stderr.write("See 'pydbgp --help'.\n") return 1 import locale codeset = locale.getdefaultlocale()[1] idekey = getenv('USER', getenv('USERNAME', '')) try: if codeset: idekey = idekey.decode(codeset) else: idekey = idekey.decode() except (UnicodeDecodeError, LookupError), e: log.warn("unable to decode idekey %r" % idekey) pass # nothing we can do if defaultlocale is wrong host = '127.0.0.1' port = 9000 preloadScript = None ignoreModules = [] interactive = 0 nodebug = 0 redirect = 1 for opt, optarg in optlist: if optarg: try: if codeset: optarg = optarg.decode(codeset) else: optarg = optarg.decode()
'interactive', 'nodebug', 'nostdin']) except getopt.GetoptError, msg: sys.stderr.write("pydbgp: error: %s\n" % str(msg)) sys.stderr.write("See 'pydbgp --help'.\n") return 1 import locale codeset = locale.getdefaultlocale()[1] idekey = getenv('USER', getenv('USERNAME', '')) try: if codeset: idekey = idekey.decode(codeset) else: idekey = idekey.decode() except (UnicodeDecodeError, LookupError), e: log.warn("unable to decode idekey %r"%idekey) pass # nothing we can do if defaultlocale is wrong host = '127.0.0.1' port = 9000 preloadScript = None ignoreModules = [] interactive = 0 nodebug = 0 redirect = 1 for opt, optarg in optlist: if optarg: try: if codeset: optarg = optarg.decode(codeset) else: optarg = optarg.decode()