def test_save_version(self): self.doc.version = '2.4' writer = xmlparser.XMLWriter(self.doc) writer.write_file("/tmp/example.odml") restored = xmlparser.load("/tmp/example.odml") self.assertEqual(self.doc.version, restored.version)
def test_save_version(self): self.doc.version = '2.4' writer = xmlparser.XMLWriter(self.doc) writer.write_file("/tmp/example.odml") restored = xmlparser.load("/tmp/example.odml") self.assertEquals(self.doc.version, restored.version)
def load(filename, backend="xml"): if backend in parsers: if backend == "xml": return xml.load(filename) elif backend == "json": return json.JSONReader().fromFile(open(filename)) else: raise ValueError("No such parser")
def test_save_version(self): tmp_file = os.path.join(tempfile.gettempdir(), "example.odml") self.doc.version = '2.4' writer = xmlparser.XMLWriter(self.doc) writer.write_file(tmp_file) restored = xmlparser.load(tmp_file) self.assertEqual(self.doc.version, restored.version)
def save_document(file_name): root = elements.Root() odml_file = load(file_name) # load input file: .xml or .odml format root.author = odml_file.author root.version = odml_file.version root.save() # save first layer of sections flat_save(odml_file, root) # for s in root.sections: # print "x\n" # root.sections.append(str(second_layer_save(s, root))) # send to database root.save()
def root_save(self, doc_path): # use python-odml driver to load document odml_root = load(doc_path) # create new dictionary wich will be changed to json by driver output = {} # fill default fields output['author'] = odml_root.author output['date'] = odml_root.date output['repository'] = odml_root.repository output['version'] = odml_root.version # save root document self.db.save(output) # save sections using section_save method for section in odml_root.sections: self.section_save(section)
def root_save(self, root_input): # print "mapping.." odml_root = load(root_input) output = {} output['author'] = odml_root.author output['date'] = odml_root.date output['repository'] = odml_root.repository output['version'] = odml_root.version r_id = ((self.client.create_vertex(output)).get_results()[0]).get_id() # print "Root ID = " + r_id for section in odml_root.sections: s_id = self.section_save(section) self.client.create_edge(r_id, "root-section", s_id) self.client.create_edge(s_id, "section-root", r_id)
def to_database(self, source_file): # create root document r = Root() # load odml file using python-odml module odml_root = load(source_file) # rewrite root fields r.author = odml_root.author r.date = odml_root.date r.repository = odml_root.repository r.version = odml_root.version r.previous = None # add sections to 'section' ccollection for section in odml_root.sections: s = self._save_section(section, None) r.sections.append(s) # save new object in database r.save()