database.py 2.4 KB

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