Beispiel #1
0
def start(filename,
          debugLevel=2,
          suppress_motion_events=True,
          logger_comments=True):
    global _suppress_motion_events
    logutils.set_debugLevel(debugLevel)
    _suppress_motion_events = suppress_motion_events
    if logutils.recording():
        #print "gtklogger already recording."
        logutils.logfile().close()
    #else:
    #print "gtklogger recording starting."
    try:
        if logger_comments == True:
            # Open a pipe to the loggergui process for inserting
            # comments into the output stream.
            guifile = os.path.abspath(loggergui.__file__)
            # The third argument of '1' to popen indicates that the
            # stream is line buffered.  This ensures that the comments
            # appear in the right place.
            ## TODO 3.1: os.popen is deprecated.  Use subprocess.Popen.
            process = os.popen("python " + guifile + " " + filename, "w", 1)
            logutils.set_logfile(process)
        elif type(filename) is types.StringType:
            logutils.set_logfile(open(filename, "w"))
        else:  # filename is assumed to be a file
            logutils.set_logfile(filename)
    except:
        logutils.set_logfile(None)
        raise
Beispiel #2
0
def start(filename, debugLevel=2, suppress_motion_events=True,
          logger_comments=True):
    global _suppress_motion_events
    logutils.set_debugLevel(debugLevel)
    _suppress_motion_events = suppress_motion_events
    if logutils.recording():
        logutils.logfile().close()
    try:
        if logger_comments:
            # Open a pipe to the loggergui process for inserting
            # comments into the output stream.
            from GUI import loggergui
            guifile = os.path.abspath(loggergui.__file__)
            # The third argument of '1' to popen indicates that the
            # stream is line buffered.  This ensures that the comments
            # appear in the right place.
            ## TODO: os.popen is deprecated.  Use subprocess.Popen.
            process = os.popen("python " + guifile + " " + filename, "w", 1)
            logutils.set_logfile(process)
        elif type(filename) is types.StringType:
            logutils.set_logfile(open(filename, "w"))
        else:                   # filename is assumed to be a file
            logutils.set_logfile(filename)
    except:
        logutils.set_logfile(None)
        raise
Beispiel #3
0
    def __init__(self,
                 filename,
                 beginCB=None,
                 finishCB=None,
                 debugLevel=2,
                 threaded=False,
                 exceptHook=None,
                 rerecord=None,
                 checkpoints=True):
        global _threaded
        logutils.set_debugLevel(debugLevel)
        _threaded = threaded
        self.beginCB = beginCB
        self.finishCB = finishCB
        self.exceptHook = exceptHook
        self.checkpoints = checkpoints  # if False, checkpoints will be ignored
        try:
            file = open(filename, "r")
        except IOError:
            self.aborted = True
            raise
        self.linerunners = []

        if rerecord:
            core.start(rerecord)

        # More than one execution line can come from a single source
        # line, if, for example, automatic pauses are inserted.  The
        # execution line number is used to know when to run a line.
        # The source line number is useful for debugging.
        lineno = 0  # number of the line being executed
        srcline = 1  # source line number
        pausenext = False  # add a pause before the next line?
        lines = file.readlines()
        self._nfilelines = len(lines)
        tobecontinued = ""
        for line in lines:
            line = line.rstrip()
            if not line:
                self.linerunners.append(CommentLine(self, srcline, lineno, ""))
                lineno += 1
                pausenext = False
            elif line[-1] == '\\':
                # Lines ending in a backslash aren't processed
                # immediately.  They're prepended to the next line
                # instead.
                tobecontinued += line[:-1]
            else:  # line isn't continued
                line = tobecontinued + line
                tobecontinued = ""
                if line.lstrip()[0] == "#":  # line is a comment
                    self.linerunners.append(
                        CommentLine(self, srcline, lineno, line.rstrip()))
                    lineno += 1
                    pausenext = False
                else:  # not a comment
                    try:
                        words = line.split(None, 1)  # look for keyword
                    except:
                        words = None
                    if words and words[0] == 'pause':
                        self.linerunners.append(
                            PauseLine(self, srcline, lineno, eval(words[1])))
                        lineno += 1
                        pausenext = False
                    elif words and words[0] == "checkpoint":
                        if self.checkpoints:
                            self.linerunners.append(
                                CheckPointLine(self, srcline, lineno,
                                               words[1].rstrip()))
                            lineno += 1
                        pausenext = False
                    elif words and words[0] == "postpone":
                        self.linerunners.append(
                            PostponeLine(self, srcline, lineno, words[1]))
                        lineno += 1
                    elif logutils.recording(
                    ) and words and words[0] == "assert":
                        # When rerecording, don't actually run the
                        # tests that may have been inserted in the
                        # log file.
                        self.linerunners.append(
                            CommentLine(self, srcline, lineno, line.rstrip()))
                        lineno += 1
                        pausenext = False
                    else:  # not a special line
                        if pausenext and replaydelay > 0:
                            self.linerunners.append(
                                PauseLine(self, srcline, lineno, replaydelay))
                            lineno += 1
                        self.linerunners.append(
                            PerformLine(self, srcline, lineno, line.rstrip()))
                        lineno += 1
                        pausenext = True
            srcline += 1
        file.close()
        GUILogPlayer.current = self
        self.aborted = False
Beispiel #4
0
    def __init__(self, filename, beginCB=None, finishCB=None, debugLevel=2,
                 threaded=False, exceptHook=None, rerecord=None,
                 checkpoints=True):
        global _threaded
        logutils.set_debugLevel(debugLevel)
        _threaded = threaded
        self.beginCB = beginCB
        self.finishCB = finishCB
        self.exceptHook = exceptHook
        self.checkpoints = checkpoints  # if False, checkpoints will be ignored
        try:
            file = open(filename, "r")
        except IOError:
            self.aborted = True
            raise
        self.linerunners = []

        if rerecord:
            core.start(rerecord)

        # More than one execution line can come from a single source
        # line, if, for example, automatic pauses are inserted.  The
        # execution line number is used to know when to run a line.
        # The source line number is useful for debugging.
        lineno = 0                      # number of the line being executed
        srcline = 1                     # source line number
        pausenext = False               # add a pause before the next line?
        lines = file.readlines()
        self._nfilelines = len(lines)
        tobecontinued = ""
        for line in lines:
            line = line.rstrip()
            if not line:
                self.linerunners.append(CommentLine(self, srcline, lineno, ""))
                lineno += 1
                pausenext = False
            elif line[-1] == '\\':
                # Lines ending in a backslash aren't processed
                # immediately.  They're prepended to the next line
                # instead.
                tobecontinued += line[:-1]
            else:                   # line isn't continued
                line = tobecontinued + line
                tobecontinued = ""
                if line.lstrip()[0] == "#": # line is a comment 
                    self.linerunners.append(
                        CommentLine(self, srcline, lineno, line.rstrip()))
                    lineno += 1
                    pausenext = False
                else:               # not a comment 
                    try:
                        words = line.split(None, 1) # look for keyword
                    except:
                        words = None
                    if words and words[0] == 'pause':
                        self.linerunners.append(
                            PauseLine(self, srcline, lineno, eval(words[1])))
                        lineno += 1
                        pausenext = False
                    elif words and words[0] == "checkpoint":
                        if self.checkpoints:
                            self.linerunners.append(
                                CheckPointLine(self, srcline, lineno,
                                               words[1].rstrip()))
                            lineno += 1
                        pausenext = False
                    elif words and words[0] == "postpone":
                        self.linerunners.append(
                            PostponeLine(self, srcline, lineno, words[1]))
                        lineno += 1
                    elif logutils.recording() and words and words[0]=="assert":
                        # When rerecording, don't actually run the
                        # tests that may have been inserted in the
                        # log file.
                        ## TODO: When rerecording, assert statements
                        ## should be copied into the log file *after*
                        ## immediately subsequent checkpoints.  That
                        ## is, checkpoints that arise after an
                        ## assertion and before any user action should
                        ## precede the assertion in the log file.
                        self.linerunners.append(
                            CommentLine(self, srcline, lineno, line.rstrip()))
                        lineno += 1
                        pausenext = False
                    else:               # not a special line
                        if pausenext and replaydelay > 0:
                            self.linerunners.append(
                                PauseLine(self, srcline, lineno, replaydelay))
                            lineno += 1
                        self.linerunners.append(
                             PerformLine(self, srcline, lineno, line.rstrip()))
                        lineno += 1
                        pausenext = True
            srcline += 1
        file.close()
        GUILogPlayer.current = self
        self.aborted = False