Esempio n. 1
0
    def replaceCbpFileAbsoluteTimestamps(cls, filename, first_timestamp=None, outFile=None):
        """
        Given a cbp valid file, replace all absolute timestamps with a relative ones,
        putting results in a new file.
        
        @filename: absolute or relative path to the .cbp file to use.
        @first_timestamp: if used, start to replace only after found this absolute timestamp (that is keeped).
        @outFile: where save the modified cbp file. If omitted a file named "newXXXX" will be created in the working directory.
        """
        try:
            pp = PresentationParser(filename, presentation_dir='')
            pp.load()
        except IOError:
            # try adding the current cwd
            pp = PresentationParser(os.path.join(os.getcwd(),filename), presentation_dir='')
            pp.load()
        
        if not outFile:
            newFname = "new-" + os.path.basename(filename)
            outFile = os.path.join(os.getcwd(),newFname)
        
        out = ""
        cnt = 0
        timevalue = None
        for line in pp.text.split("\n"):
            cnt+=1
            if not first_timestamp and re_timeStampAbsoluteCheck.match(line) and timevalue is not None:
                old_ts = re_timeStampAbsoluteCheck.findall(line)[0][1][1:13]
                old_ts_value = timestampStringToValue(old_ts)
                new_timevalue = old_ts_value-timevalue
                new_ts = "+"+timestampValueToString(new_timevalue)
                timevalue+= new_timevalue
                print "replacing at line %s: timestamp %s with %s" % (cnt, old_ts, new_ts)
                out+=line.replace(old_ts, new_ts)
            else:
                out+=line
            if (timevalue is None and re_timeStampAbsoluteCheck.match(line)) or \
               (first_timestamp and re_timeStampAbsoluteCheck.match(line)):
                # This is executed only once, or until found first_timestamp
                old_ts = re_timeStampAbsoluteCheck.findall(line)[0][1][1:13]
                print "keeping absolute timestamp at line %s: %s" % (cnt, old_ts)
                timevalue = timestampStringToValue(old_ts)
                if old_ts==first_timestamp:
                    # stop from entering there
                    first_timestamp = None
            out+="\n"

        fh = open(outFile, 'w')
        fh.write(out)
        fh.close()
        
        print "\nDone"
Esempio n. 2
0
 def _replaceRelativeTimeStamps(self, operations):
     """Looking all timestamps, if a relative ones if found, it is replaced with
     the absolute value calculated on the last absolute timestamps found.
     
     Be aware that this method must be called before the sort of the data structure,
     or all [+xxx...] timestamps will be putted at the end.
     """
     collected_time = 0
     for op in operations:
         timestamp = op['timestamp']
         if timestamp.startswith("+"):
             # relative
             value = timestamp[1:]  # skip the '+' char
             collected_time += timestampStringToValue(value)
             ts = timestampValueToString(collected_time)
             op['timestamp'] = ts
         else:
             collected_time = timestampStringToValue(timestamp)
Esempio n. 3
0
 def update(self, time_passed):
     """Update presentation run timer, and run commands if needed"""
     self._time_collected += time_passed
     try:
         next_ops = self.data["operations"][0]
     except IndexError:
         # Presentation is finished
         self.disablePresentationMode()
         return None
     next_op_timestamp_value = timestampStringToValue(next_ops["timestamp"])
     if self._time_collected * 1000.0 >= next_op_timestamp_value:
         # I'm late, I must run next operations!
         toExecList = []
         while next_ops["commands"]:
             next_op = next_ops["commands"].pop(0)
             toExecList.append(next_op)
             logging.info("Presentation: running command: %s" % next_op)
         # No more commands for this timestamp
         self.data["operations"].pop(0)
         return toExecList
     return ""