database.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. """
  30. Open the database, by calling the _open method of the
  31. class inherited for the specific database.
  32. When done validation that the file is OK, check if it has
  33. encryption key, by calling
  34. enc = CryptoEngine.get()
  35. key = self.loadkey()
  36. """
  37. self._open()
  38. enc = CryptoEngine.get()
  39. key = self.loadkey()
  40. if (key != None):
  41. enc.set_cryptedkey(key)
  42. else:
  43. self.changepassword()
  44. def close(self):
  45. pass
  46. def changepassword(self):
  47. """
  48. Change the databases password.
  49. """
  50. enc = CryptoEngine.get()
  51. newkey = enc.changepassword()
  52. return self.savekey(newkey)
  53. def listtags(self, all=False):
  54. pass
  55. def currenttags(self):
  56. return self._filtertags
  57. def filter(self, tags):
  58. for tag in tags:
  59. if not (tag in self._filtertags):
  60. self._filtertags.append(tag)
  61. def clearfilter(self):
  62. self._filtertags = []
  63. def getnodes(self, ids):
  64. pass
  65. def addnodes(self, nodes):
  66. pass
  67. def editnode(self, id, node):
  68. pass
  69. def removenodes(self, nodes):
  70. pass
  71. def listnodes(self):
  72. pass
  73. def savekey(self, key):
  74. pass
  75. def loadkey(self):
  76. pass