Example #1
0
 def __init__(self, settings):
     self.bp_id = 0
     self.debugCtx = Debuger()
     self.settings = DebugSetting()
     self.logger = None
     self.watched_variable = []
     self.inteface_list = []
     self.telnet_monitor_list = []
     self.debug_listener = []
     
     if settings.endswith('.rdb'):
         self.settings.load_from_file(os.path.abspath(settings))
     else:
         self.add_breakpoint(settings)
     
     if self.settings.LOGGING_FILE:
         self.__init_sys_logging()
         self.logger = logging.getLogger("rdb.c")
         self.logger.info("starting robot debuger...")
         
     for e in self.settings.BPS_LIST:
         self.add_breakpoint(e)
     
     for e in self.settings.WATCHING_LIST:
         self.watch_variable(e)
         
     self.__inject_ipamml_telnet_monitor()
     self.__set_case_status()
     self._exit_code = 0
Example #2
0
class RobotDebuger(object):
    def __init__(self, settings):
        self.bp_id = 0
        self.debugCtx = Debuger()
        self.settings = DebugSetting()
        self.logger = None
        self.watched_variable = []
        self.inteface_list = []
        self.telnet_monitor_list = []
        self.debug_listener = []
        
        if settings.endswith('.rdb'):
            self.settings.load_from_file(os.path.abspath(settings))
        else:
            self.add_breakpoint(settings)
        
        if self.settings.LOGGING_FILE:
            self.__init_sys_logging()
            self.logger = logging.getLogger("rdb.c")
            self.logger.info("starting robot debuger...")
            
        for e in self.settings.BPS_LIST:
            self.add_breakpoint(e)
        
        for e in self.settings.WATCHING_LIST:
            self.watch_variable(e)
            
        self.__inject_ipamml_telnet_monitor()
        self.__set_case_status()
        self._exit_code = 0
        
            
    def add_breakpoint(self, bps):
        if not bps.strip(): return
        if isinstance(bps, types.ListType):
            self.debugCtx.add_breakpoint(CallStackBreakPoint('bp%s' % self.bp_id,
                                                             bps))
        elif ";" in bps:
            self.debugCtx.add_breakpoint(CallStackBreakPoint('bp%s' % self.bp_id,
                                                             bps.split(";")))
        else:
            self.debugCtx.add_breakpoint(KeywordBreakPoint('bp%s' % self.bp_id,
                                                           bps))
        self.bp_id += 1
        #self.debugCtx.add_breakpoint(KeywordBreakPoint('', bps))
        
    def watch_variable(self, name):
        if not name.strip(): return
        if name not in self.watched_variable:
            self.watched_variable.append(name)
    
    def remove_variable(self, name):
        if name in self.watched_variable:
            self.watched_variable.remove(name)
            
    def add_telnet_monitor(self, monitor):
        self.telnet_monitor_list.append(monitor)
    
    @property
    def watching_variable(self):return list(self.watched_variable)
    
    def run_keyword(self, name, *args):
        """, """
        import robot.output as output
        from robot.running import Keyword, NAMESPACES
        kw = Keyword(name, args)
        def get_name(handler_name, variables):
            return "RDB.%s" % handler_name
        kw._get_name = get_name
        
        if self._exit_code > 0:
            sys.exit(self._exit_code)
        
        return kw.run(output.OUTPUT, NAMESPACES.current)
        
    def run(self):
        try:
            for cls_int in self.settings.INTERFACE_LIST:
                handler = cls_int.split(".")
                module_name, handler = ".".join(handler[:-1]), handler[-1]
                module = __import__(module_name, globals(), locals(), [handler, ], -1)
                cls_int = getattr(module, handler)
                self.inteface_list.append(cls_int(self))
                DebugThread(self.inteface_list[-1], self.settings).start()
        except Exception, e:
            self.logger and self.logger.exception(e)
            raise