فهرست منبع

fix bug opening db ...

oz123 11 سال پیش
والد
کامیت
869074c393
2فایلهای تغییر یافته به همراه18 افزوده شده و 5 حذف شده
  1. 17 4
      pwman/data/convertdb.py
  2. 1 1
      scripts/pwman3

+ 17 - 4
pwman/data/convertdb.py

@@ -22,6 +22,9 @@ import shutil
 import os.path
 import time
 
+from pwman.util.crypto import CryptoEngine
+import pwman.data.factory
+
 
 class PwmanConvertDB(object):
     """
@@ -30,13 +33,23 @@ class PwmanConvertDB(object):
     """
 
     def __init__(self, args, config):
-        db = config.get_value('Database', 'filename')
-        print "Will convert the following Database: %s " % db
-        backup = '.backup-%s'.join(os.path.splitext(db)) % \
+        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(db, backup)
+        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)
+
     def run(self):
+        self.read_old_db()
+        self.db.open()
         pass

+ 1 - 1
scripts/pwman3

@@ -137,7 +137,7 @@ try:
         dbver = pwman.data.factory.check_db_version(dbtype)
         dbver = float(dbver.strip("\'"))
     else:
-        dbver = 0.3
+        dbver = 0.4
     # the method create could create an old instance that
     # accepts cPickle object or new style instance that
     # accepts only strings.