+
+ @inplaceread
+ def getMetadata(self) :
+ metadata = {}
+ self.next() # skip identification line.
+ line = self.next()
+ while line.startswith('METADATA ') :
+ line = line.split(None, 1)[1]
+ name, value = [v.strip() for v in line.split(':', 1)]
+ metadata[name] = value
+ line = self.next()
+ return metadata
+
+ def setMetadata(self, metadata) :
+ f = self.logfile
+ f.seek(0)
+ before = f.readline()
+ after = f.read()
+
+ lines = []
+ for name, value in metadata :
+ lines.append('METADATA %s : %s' % (name, value.encode('utf-8')))
+ metadata = '\n'.join(lines)
+ f.seek(0)
+ f.write(before)
+ f.write(metadata)
+ f.write(after)
+
+ def close(self) :
+ self.logfile.close()