def read_file_xml(self): ''' Read content file xml , generated by this software! ''' try : parser = XML_Parser() parser.set_debug(self.debug) parser.set_log(self.log) parser.read_xml(self.fileChecksum) self.xml = parser.get_dict_xml() except: self.log.warning('WG : You have a problem to read XML file: %s!' % self.fileChecksum) return False
def save_file(self, filename): ''' Save informations on file system ''' try: if self.out == 'txt': f = open(filename, 'w') print self.files if 'shortpath' in self.files and self.files['shortpath']: for key, value in self.files['shortpath'].items(): f.write(self.files['checksum'][key] + ' ' + value + '\n') elif 'base' in self.files and self.files['base']: for key, value in self.files['base'].items(): f.write(self.files['checksum'][key] + ' ' + value + '\n') f.close() elif self.out == 'xml': array = { 'algorithm': self.algo, 'generator': self.generator, 'files': self.files, 'id': os.path.basename(filename), 'version': self.version, } parser = XML_Parser() parser.set_debug(self.debug) parser.set_dict(array) parser.set_log(self.log) parser.build_xml() parser.save_xml(filename) except IOError as ioe: self.log.exception('Error to create document: %s' % ioe) return False