123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- import os
- import shutil
- import os.path
- import time
- import getpass
- from pwman.util.crypto import CryptoEngine
- import pwman.data.factory
- from pwman.util.callback import Callback
- class CLICallback(Callback):
- def getinput(self, question):
- return raw_input(question)
- def getsecret(self, question):
- return getpass.getpass(question + ":")
- class PwmanConvertDB(object):
- """
- Class to migrate from DB in version 0.3 to
- DB used in later versions.
- """
- def __init__(self, args, config):
- self.db = config.get_value('Database', 'filename')
- self.dbtype = config.get_value("Database", "type")
- print "Will convert the following Database: %s " % self.db
- if os.path.exists(config.get_value("Database", "filename")):
- dbver = pwman.data.factory.check_db_version(self.dbtype)
- self.dbver = float(dbver.strip("\'"))
- backup = '.backup-%s'.join(os.path.splitext(self.db)) % \
- time.strftime(
- '%Y-%m-%d-%H:%m')
- shutil.copy(self.db, backup)
- print "backup created in ", backup
- def read_old_db(self):
- "read the old db and get all nodes"
- self.db = pwman.data.factory.create(self.dbtype, self.dbver)
- enc = CryptoEngine.get()
- enc.set_callback(CLICallback())
- self.db.open()
- self.oldnodes = self.db.listnodes()
- self.oldnodes = self.db.getnodes(self.oldnodes)
- def run(self):
- self.read_old_db()
|