convertdb.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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) 2013 Oz Nahum <nahumoz@gmail.com>
  18. #============================================================================
  19. import os
  20. import shutil
  21. import os.path
  22. import time
  23. from pwman.util.crypto import CryptoEngine
  24. import pwman.data.factory
  25. class PwmanConvertDB(object):
  26. """
  27. Class to migrate from DB in version 0.3 to
  28. DB used in later versions.
  29. """
  30. def __init__(self, args, config):
  31. self.db = config.get_value('Database', 'filename')
  32. self.dbtype = config.get_value("Database", "type")
  33. print "Will convert the following Database: %s " % self.db
  34. if os.path.exists(config.get_value("Database", "filename")):
  35. dbver = pwman.data.factory.check_db_version(self.dbtype)
  36. self.dbver = float(dbver.strip("\'"))
  37. backup = '.backup-%s'.join(os.path.splitext(self.db)) % \
  38. time.strftime(
  39. '%Y-%m-%d-%H:%m')
  40. shutil.copy(self.db, backup)
  41. print "backup created in ", backup
  42. def read_old_db(self):
  43. "read the old db and get all nodes"
  44. self.db = pwman.data.factory.create(self.dbtype, self.dbver)
  45. def run(self):
  46. self.read_old_db()
  47. self.db.open()
  48. pass