Forráskód Böngészése

- fix EOL
- add updated factory module

oz123 11 éve
szülő
commit
eb1aa94e48
4 módosított fájl, 41 hozzáadás és 12 törlés
  1. 22 0
      pwman/data/drivers/sqlite.py
  2. 17 7
      pwman/data/factory.py
  3. 2 2
      pwman/ui/cli.py
  4. 0 3
      scripts/pwman3

+ 22 - 0
pwman/data/drivers/sqlite.py

@@ -37,6 +37,28 @@ else:
 import pwman.util.config as config
 import cPickle
 
+
+def check_db_version():
+    """
+    check the data base version query the right table
+    """
+    try:
+        filename = config.get_value('Database', 'filename')
+        con = sqlite.connect(filename)
+        cur = con.cursor()
+        cur.execute("PRAGMA TABLE_INFO(DBVERSION)")
+        row = cur.fetchone()
+        if row is None:
+            return "0.3"
+        try:
+            return row[-2]
+        except IndexError:
+            raise DatabaseException("Something seems fishy with the DB")
+
+    except sqlite.DatabaseError, e:
+        raise DatabaseException("SQLite: %s" % (e))
+        
+
 class SQLiteDatabase(Database):
     """SQLite Database implementation"""
 

+ 17 - 7
pwman/data/factory.py

@@ -34,20 +34,30 @@ from pwman.data.database import Database, DatabaseException
 
 import pwman.util.config as config
 
-def create(type):
+
+def check_db_version(type):
+    if type == "SQLite":
+        try:
+            from pwman.data.drivers import sqlite
+        except ImportError, e:
+            raise DatabaseException("python-sqlite not installed")
+        ver = sqlite.check_db_version()
+        return ver
+     # TODO: implement version checks for other supported DBs.
+     
+def create(type, version=None):
     """
     create(params) -> Database
     Create a Database instance. 
     'type' can only be 'SQLite' at the moment
     """
-
-    if type == "BerkeleyDB":
-        pass
-#        db = BerkeleyDatabase.BerkeleyDatabase(params)
-    elif (type == "SQLite"):
+    if (type == "SQLite"):
         try: 
             from pwman.data.drivers import sqlite
-            db = sqlite.SQLiteDatabase()
+            if version == 0.4:
+                db = sqlite.SQLiteDatabaseNewForm()
+            else:
+                db = sqlite.SQLiteDatabase()
         except ImportError, e:
             raise DatabaseException("python-sqlite not installed")
     elif (type == "Postgresql"):

+ 2 - 2
pwman/ui/cli.py

@@ -594,7 +594,7 @@ class PwmanCli(cmd.Cmd):
 
     def help_open(self):
         self.usage("open <ID>")
-        print "Launch default browser with 'xdg-open url',\n\"
+        print "Launch default browser with 'xdg-open url',\n" \
               + "the url must contain http:// or https://."
     def help_o(self):
         self.help_open()
@@ -782,7 +782,7 @@ class PwmanCliMac(PwmanCli):
     ##
     def help_open(self):
         self.usage("open <ID>")
-        print "Launch default browser with 'open url',\n\"
+        print "Launch default browser with 'open url',\n" \
               + "the url must contain http:// or https://."
 
     def help_o(self):

+ 0 - 3
scripts/pwman3

@@ -144,9 +144,6 @@ try:
         cli = PwmanCli(db, xselpath)
 except SystemExit, e:
     sys.exit(e)
-except Exception, e:
-    print "Error: %s" % (e)
-    sys.exit(-1)
 
 try:
     try: