示例#1
0
 def write_log(self, outfname=None, outftype=None):
     """TODO: Update docstring."""
     if outfname is None:
         outfname = self.config['LOG_FNAME_OUT']
         outftype = self.config['LOG_FTYPE_OUT']
     if outftype == FTYPE_PICKLE:
         import pickle
         with open(outfname, 'wb') as outfile:
             for wtime in self.wslots:
                 pickle.dump(wtime, outfile)
     elif outftype == FTYPE_XML:
         from backend.xml import XmlBackend
         # XXX This assumes that `write_log' was called soon after
         # `write_tasks'.
         mode = 'r+b' if self._xml_header_written else 'wb'
         with open_backed_up(outfname, mode,
                             suffix=self.config['BACKUP_SUFFIX']) \
                 as outfile:
             if self._xml_header_written:
                 # Skip before the last line (assumed to read
                 # "</wyrdinData>").
                 outfile.seek(-len(b'</wyrdinData>\n'), 2)
             XmlBackend.write_workslots(self.wslots, outfile,
                                        not self._xml_header_written)
             if self._xml_header_written:
                 outfile.write(b'</wyrdinData>\n')
             self._xml_header_written = True
     else:
         raise NotImplementedError("Session.write_log() is not "
                                   "implemented for this type of files.")