def get_tools_directory(): """ Returns directory path where DExTer tool imports can be found. """ tools_directory = os.path.join(get_root_directory(), 'tools') assert os.path.isdir(tools_directory), tools_directory return tools_directory
def main() -> ReturnCode: context = Context() with PrettyOutput() as context.o: try: context.root_directory = get_root_directory() # Flag some strings for auto-highlighting. _set_auto_highlights(context) options, args = _get_options_and_args(context) # raises 'Error' if command line tool is invalid. tool_name = _get_tool_name(options) module = _import_tool_module(tool_name) return tool_main(context, module.Tool(context), args) except Error as e: context.o.auto('\nerror: {}\n'.format(str(e)), stream=PrettyOutput.stderr) try: if context.options.error_debug: raise except AttributeError: pass return ReturnCode._ERROR except (KeyboardInterrupt, SystemExit): raise except: # noqa _output_bug_report_message(context) raise
def run_debugger_subprocess(debugger_controller, working_dir_path): with NamedTemporaryFile( dir=working_dir_path, delete=False, mode='wb') as fp: pickle.dump(debugger_controller, fp, protocol=pickle.HIGHEST_PROTOCOL) controller_path = fp.name dexter_py = os.path.basename(sys.argv[0]) if not os.path.isfile(dexter_py): dexter_py = os.path.join(get_root_directory(), '..', dexter_py) assert os.path.isfile(dexter_py) with NamedTemporaryFile(dir=working_dir_path) as fp: args = [ sys.executable, dexter_py, 'run-debugger-internal-', controller_path, '--working-directory={}'.format(working_dir_path), '--unittest=off', '--indent-timer-level={}'.format(Timer.indent + 2) ] try: with Timer('running external debugger process'): subprocess.check_call(args) except subprocess.CalledProcessError as e: raise DebuggerException(e) with open(controller_path, 'rb') as fp: debugger_controller = pickle.load(fp) return debugger_controller
def add_tool_arguments(self, parser, defaults): parser.description = self.__doc__ add_builder_tool_arguments(parser) add_debugger_tool_arguments(parser, self.context, defaults) add_heuristic_tool_arguments(parser) parser.add_argument( 'tests_directory', type=str, metavar='<tests-directory>', nargs='?', default=os.path.abspath( os.path.join(get_root_directory(), '..', 'tests')), help='directory containing test(s)') parser.add_argument( '--results-directory', type=str, metavar='<directory>', default=os.path.abspath( os.path.join(get_root_directory(), '..', 'results', datetime.now().strftime('%Y-%m-%d-%H%M-%S'))), help='directory to save results')
def get_debugger_steps(context): step_collection = empty_debugger_steps(context) with Timer('parsing commands'): try: step_collection.commands = _get_command_infos(context) except CommandParseError as e: msg = 'parser error: <d>{}({}):</> {}\n{}\n{}\n'.format( e.filename, e.lineno, e.info, e.src, e.caret) raise DebuggerException(msg) with NamedTemporaryFile(dir=context.working_directory.path, delete=False) as fp: pickle.dump(step_collection, fp, protocol=pickle.HIGHEST_PROTOCOL) steps_path = fp.name with NamedTemporaryFile(dir=context.working_directory.path, delete=False, mode='wb') as fp: pickle.dump(context.options, fp, protocol=pickle.HIGHEST_PROTOCOL) options_path = fp.name dexter_py = sys.argv[0] if not os.path.isfile(dexter_py): dexter_py = os.path.join(get_root_directory(), '..', dexter_py) assert os.path.isfile(dexter_py) with NamedTemporaryFile(dir=context.working_directory.path) as fp: args = [ sys.executable, dexter_py, 'run-debugger-internal-', steps_path, options_path, '--working-directory', context.working_directory.path, '--unittest=off', '--indent-timer-level={}'.format(Timer.indent + 2) ] try: with Timer('running external debugger process'): subprocess.check_call(args) except subprocess.CalledProcessError as e: raise DebuggerException(e) with open(steps_path, 'rb') as fp: step_collection = pickle.load(fp) return step_collection
def add_tool_arguments(self, parser, defaults): parser.description = self.__doc__ add_builder_tool_arguments(parser) add_debugger_tool_arguments(parser, self.context, defaults) add_heuristic_tool_arguments(parser) parser.add_argument( 'test_path', type=str, metavar='<test-path>', nargs='?', default=os.path.abspath( os.path.join(get_root_directory(), '..', 'tests')), help='directory containing test(s)') parser.add_argument( '--results-directory', type=str, metavar='<directory>', default=None, help='directory to save results (default: none)')