123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- try:
- from xml.etree.cElementTree import Element, SubElement, dump, ElementTree
- except ImportError:
- from cElementTree import Element, SubElement, dump, ElementTree
- from pwman.data.nodes import Node
- from pwman.data.tags import Tag
- class Exporter:
- def types(self):
- return ["pwman3"]
- types = classmethod(types)
- def get(self, type):
- if type == "pwman3":
- return Pwman3Exporter()
- get = classmethod(get)
- def export_data(self, db, file, nodeids):
- pass
- class Pwman3Exporter(Exporter):
- def export_data(self, db, file, nodeids):
- nodeids = db.listnodes()
- nodes = db.getnodes(nodeids)
- root = Element("PwmanXmlList", version="3.0")
- for n in nodes:
- sub = SubElement(root, "Node")
- SubElement(sub, "username").text = n.get_username()
- SubElement(sub, "password").text = n.get_password()
- SubElement(sub, "url").text = n.get_url()
- SubElement(sub, "notes").text = n.get_notes()
- tagelement = SubElement(sub, "tags")
- for t in n.get_tags():
- SubElement(tagelement, "name").text = t.get_name()
- ElementTree(root).write(file)
|