Пример #1
0
def stop():
    if logutils.recording():
        try:
            print "gtklogger recording stopping."
            logutils.logfile().close()
        finally:
            logutils.set_logfile(None)
Пример #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
Пример #3
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
Пример #4
0
def stop():
    if logutils.recording():
        try:
	  print "gtklogger recording stopping."
	  logutils.logfile().close()
        finally:
            logutils.set_logfile(None)
Пример #5
0
def signalLogger(obj, signal, *args):
    if logutils.recording() and not logutils.replaying():
        try:
            records = findLogger(obj).record(obj, signal, *args)
        except logutils.GtkLoggerTopFailure, exc:
            if logutils.debugLevel() >= 3:
                print >> sys.stderr, "Can't log %s (%s): %s" \
                      (obj.__class__.__name__, signal, exc)
        except logutils.GtkLoggerException, exc:
            if logutils.debugLevel() >= 1:
                print >> sys.stderr, "Can't log %s (%s): %s" % \
                      (obj.__class__.__name__, signal, exc)
Пример #6
0
def signalLogger(obj, signal, *args):
    if logutils.recording() and not logutils.replaying():
        try:
            records = findLogger(obj).record(obj, signal, *args)
        except logutils.GtkLoggerTopFailure, exc:
            if logutils.debugLevel() >= 3:
                print >> sys.stderr, "Can't log %s (%s): %s" \
                      (obj.__class__.__name__, signal, exc)
        except logutils.GtkLoggerException, exc:
            if logutils.debugLevel() >= 1:
                print >> sys.stderr, "Can't log %s (%s): %s" % \
                      (obj.__class__.__name__, signal, exc)
Пример #7
0
def checkpoint(comment):
    _checkpointlock.acquire()
    try:
        if logutils.recording():  # recording
            print >> logutils.logfile(), "checkpoint", comment
            logutils.logfile().flush()
            if logutils.debugLevel() >= 2:
                print >> sys.stderr, "////// checkpoint", comment
        if logutils.replaying():
            try:
                _checkpointdict[comment] += 1
            except KeyError:
                _checkpointdict[comment] = 1
    finally:
        _checkpointlock.release()
Пример #8
0
def checkpoint(comment):
    _checkpointlock.acquire()
    try:
        if logutils.recording():  # recording
            print >> logutils.logfile(), "checkpoint", comment
            logutils.logfile().flush()
            if logutils.debugLevel() >= 2:
                print >> sys.stderr, "////// checkpoint", comment
        if logutils.replaying():
            try:
                _checkpointdict[comment] += 1
            except KeyError:
                _checkpointdict[comment] = 1
    finally:
        _checkpointlock.release()
Пример #9
0
 def playback(self):
     if logutils.recording():
         loggers._writeline("pause" + self.delaytime)
     if _threaded and self.delaytime > 0:
         if self.status == "running":
             self.status = "repeating"
             if logutils.debugLevel() >= 4:
                 print >> sys.stderr, self.srcline, \
                       "Pausing", self.delaytime, "milliseconds"
             gobject.timeout_add(self.delaytime, self,
                                 priority=gobject.PRIORITY_LOW)
         elif self.status == "repeating":
             if logutils.debugLevel() >= 4:
                 print >> sys.stderr, "Done pausing", self.srcline
             self.status = "done"
     else:
         # not threaded, no need to wait for background tasks
         self.status = "done"
     return False
Пример #10
0
    def playback(self):
        if logutils.recording():
            ## Hack opportunity: if it's necessary to modify some
            ## lines in existing log files, check for the lines here,
            ## and call loggers._writeline with the modified version.
            ## This will allow log files to be modified by rerecording
            ## them.
            loggers._writeline(self.line)

        if logutils.debugLevel() >= 4:
            print >> sys.stderr, "Executing", self.srcline, self.line
        # Exec'ing the line with an explicitly provided dictionary
        # allows variables created on one line to be available on a
        # later line.  Otherwise, the variable's scope would just be
        # this function call, which wouldn't be very useful.
        exec(self.line, sys.modules[__name__].__dict__)
        if logutils.debugLevel() >= 4:
            print >> sys.stderr, "Finished", self.srcline, self.line
        self.status = "done"
        return False
Пример #11
0
 def playback(self):
     if logutils.recording():
         ## Hack opportunity: if it's necessary to modify some
         ## lines in existing log files, check for the lines here,
         ## and call loggers._writeline with the modified version.
         ## This will allow log files to be modified by rerecording
         ## them.
         loggers._writeline(self.line)
             
     if logutils.debugLevel() >= 4:
         print >> sys.stderr, "Executing", self.srcline, self.line
     # Exec'ing the line with an explicitly provided dictionary
     # allows variables created on one line to be available on a
     # later line.  Otherwise, the variable's scope would just be
     # this function call, which wouldn't be very useful.
     exec(self.line, sys.modules[__name__].__dict__)
     if logutils.debugLevel() >= 4:
         print >> sys.stderr, "Finished", self.srcline, self.line
     self.status = "done"
     return False
Пример #12
0
def checkpoint(comment):
    _checkpointlock.acquire()
    try:
	#print "checkpoint access attempt: %s" %comment
        if logutils.recording():        # recording
           # print "checkpoint accessed for recording: %s" %comment
            print >> logutils.logfile(), "checkpoint", comment
            if logutils.debugLevel() >= 2:
                print >> sys.stderr, "////// checkpoint", comment
        if logutils.replaying():
            try:
                _checkpointdict[comment] += 1
                #print "checkpoint accessed for replaying: %s" %comment
            except KeyError:
                _checkpointdict[comment] = 1
                #print "checkpoint fail to be played: %s" %comment
        #if not logutils.replaying() and not logutils.recording():
	  #print "checkpoint access failed: %s" %comment
    finally:
        _checkpointlock.release()
Пример #13
0
def stop():
    if logutils.recording():
        try:
            logutils.logfile().close()
        finally:
            logutils.set_logfile(None)
Пример #14
0
def stop():
    if logutils.recording():
        try:
            logutils.logfile().close()
        finally:
            logutils.set_logfile(None)
Пример #15
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
Пример #16
0
 def playback(self):
     if logutils.recording():
         loggers._writeline(self.comment)
     self.status = "done"
     return False
Пример #17
0
 def playback(self):
     if logutils.recording():
         loggers._writeline("postpone " + self.line)
     _postponed.append(PostponedLine(self))
     self.status = "done"
     return False
Пример #18
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
Пример #19
0
 def playback(self):
     if logutils.recording():
         loggers._writeline(self.comment)
     self.status = "done"
     return False
Пример #20
0
 def playback(self):
     if logutils.recording():
         loggers._writeline("postpone " + self.line)
     _postponed.append(PostponedLine(self))
     self.status = "done"
     return False