database.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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) 2012 Oz Nahum <nahumoz@gmail.com>
  18. #============================================================================
  19. # Copyright (C) 2006 Ivan Kelly <ivan@ivankelly.net>
  20. #============================================================================
  21. from pwman.data.nodes import Node
  22. from pwman.util.crypto import CryptoEngine
  23. class DatabaseException(Exception):
  24. pass
  25. class Database:
  26. def __init__(self):
  27. self._filtertags = []
  28. def open(self):
  29. """Open the database."""
  30. self._open()
  31. enc = CryptoEngine.get()
  32. key = self.loadkey()
  33. if (key != None):
  34. enc.set_cryptedkey(key)
  35. else:
  36. self.changepassword()
  37. def close(self):
  38. pass
  39. def changepassword(self):
  40. """Change the databases password."""
  41. enc = CryptoEngine.get()
  42. newkey = enc.changepassword()
  43. return self.savekey(newkey)
  44. def listtags(self, all=False):
  45. pass
  46. def currenttags(self):
  47. return self._filtertags
  48. def filter(self, tags):
  49. for tag in tags:
  50. if not (tag in self._filtertags):
  51. self._filtertags.append(tag)
  52. def clearfilter(self):
  53. self._filtertags = []
  54. def getnodes(self, ids):
  55. pass
  56. def addnodes(self, nodes):
  57. pass
  58. def editnode(self, id, node):
  59. pass
  60. def removenodes(self, nodes):
  61. pass
  62. def listnodes(self):
  63. pass
  64. def savekey(self, key):
  65. pass
  66. def loadkey(self):
  67. pass