database.py 3.0 KB

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