database.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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.util.crypto import CryptoEngine
  22. __DB_FORMAT__ = 0.5
  23. class DatabaseException(Exception):
  24. pass # prage: no cover
  25. class Database(object):
  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 is not None:
  41. enc.set_cryptedkey(key)
  42. else:
  43. self.get_user_password()
  44. def close(self):
  45. pass # pragma: no cover
  46. def get_user_password(self):
  47. """
  48. get the databases password from the user
  49. """
  50. enc = CryptoEngine.get()
  51. newkey = enc.changepassword()
  52. return self.savekey(newkey)
  53. def changepassword(self):
  54. """
  55. Change the databases password.
  56. """
  57. enc = CryptoEngine.get()
  58. newkey = enc.changepassword()
  59. return newkey
  60. # self.savekey(newkey)
  61. def listtags(self, all=False):
  62. pass # pragma: no cover
  63. def currenttags(self):
  64. return self._filtertags
  65. def filter(self, tags):
  66. for tag in tags:
  67. if not (tag in self._filtertags):
  68. self._filtertags.append(tag)
  69. def clearfilter(self):
  70. self._filtertags = []
  71. def getnodes(self, ids):
  72. pass # pragma: no cover
  73. def addnodes(self, nodes):
  74. pass # pragma: no cover
  75. def editnode(self, id, node):
  76. pass # pragma: no cover
  77. def removenodes(self, nodes):
  78. pass # pragma: no cover
  79. def listnodes(self):
  80. pass # pragma: no cover
  81. def savekey(self, key):
  82. pass # pragma: no cover
  83. def loadkey(self):
  84. pass # pragma: no cover