exporter.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #============================================================================
  2. # This file is part of Pwman3.
  3. #
  4. # Pwman3 is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License, version 2
  6. # as published by the Free Software Foundation;
  7. #
  8. # Pwman3 is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with Pwman3; if not, write to the Free Software
  15. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. #============================================================================
  17. # Copyright (C) 2006 Ivan Kelly <ivan@ivankelly.net>
  18. #============================================================================
  19. from cElementTree import Element, SubElement, dump, ElementTree
  20. from pwman.data.nodes import Node
  21. from pwman.data.tags import Tag
  22. class Exporter:
  23. def types(self):
  24. return ["pwman3"]
  25. types = classmethod(types)
  26. def get(self, type):
  27. if type == "pwman3":
  28. return Pwman3Exporter()
  29. get = classmethod(get)
  30. def export_data(self, db, file, nodeids):
  31. pass
  32. class Pwman3Exporter(Exporter):
  33. def export_data(self, db, file, nodeids):
  34. nodeids = db.listnodes()
  35. nodes = db.getnodes(nodeids)
  36. root = Element("PwmanXmlList", version="3.0")
  37. for n in nodes:
  38. sub = SubElement(root, "Node")
  39. SubElement(sub, "username").text = n.get_username()
  40. SubElement(sub, "password").text = n.get_password()
  41. SubElement(sub, "url").text = n.get_url()
  42. SubElement(sub, "notes").text = n.get_notes()
  43. tagelement = SubElement(sub, "tags")
  44. for t in n.get_tags():
  45. SubElement(tagelement, "name").text = t.get_name()
  46. ElementTree(root).write(file)