Browse Source

Fix convertdb

* The converter works to convert v0.0.8 database to
  current format
* The tags are saved in the database as encrypted strings
oz123 11 years ago
parent
commit
ea1c5352c8
3 changed files with 12 additions and 14 deletions
  1. 6 10
      pwman/data/convertdb.py
  2. 4 2
      pwman/data/drivers/sqlite.py
  3. 2 2
      pwman/data/tags.py

+ 6 - 10
pwman/data/convertdb.py

@@ -19,7 +19,6 @@
 from __future__ import print_function
 from __future__ import print_function
 import os
 import os
 import shutil
 import shutil
-import os.path
 import time
 import time
 import getpass
 import getpass
 from pwman.util.crypto import CryptoEngine
 from pwman.util.crypto import CryptoEngine
@@ -28,14 +27,13 @@ from pwman.util.callback import Callback
 from pwman.data.nodes import NewNode
 from pwman.data.nodes import NewNode
 from pwman.data.tags import Tag
 from pwman.data.tags import Tag
 import sys
 import sys
-
-_NEWVERSION = 0.4
-
+import re
 from pwman.data.database import Database, DatabaseException
 from pwman.data.database import Database, DatabaseException
 import sqlite3 as sqlite
 import sqlite3 as sqlite
 import pwman.util.config as config
 import pwman.util.config as config
 import cPickle
 import cPickle
 
 
+_NEWVERSION = 0.4
 
 
 class SQLiteDatabaseReader(Database):
 class SQLiteDatabaseReader(Database):
     """SQLite Database implementation"""
     """SQLite Database implementation"""
@@ -91,8 +89,8 @@ class SQLiteDatabaseReader(Database):
                 else:
                 else:
                     first = False
                     first = False
                 sql += ("SELECT NODE FROM LOOKUP LEFT JOIN TAGS "
                 sql += ("SELECT NODE FROM LOOKUP LEFT JOIN TAGS "
-                        + " ON TAG = TAGS.ID"
-                        + " WHERE TAGS.DATA = ? ")
+                        " ON TAG = TAGS.ID"
+                        " WHERE TAGS.DATA = ? ")
 
 
                 params.append(cPickle.dumps(t))
                 params.append(cPickle.dumps(t))
         try:
         try:
@@ -234,18 +232,16 @@ class PwmanConvertDB(object):
         for node in self.oldnodes:
         for node in self.oldnodes:
             username = node.get_username()
             username = node.get_username()
             password = node.get_password()
             password = node.get_password()
-
             url = node.get_url()
             url = node.get_url()
             notes = node.get_notes()
             notes = node.get_notes()
             tags = node.get_tags()
             tags = node.get_tags()
-            tags_strings = [tag.get_name() for tag in tags]
+            tags_strings = [ tag._name for tag in tags]
             newNode = NewNode()
             newNode = NewNode()
             newNode.username = username
             newNode.username = username
             newNode.password = password
             newNode.password = password
             newNode.url = url
             newNode.url = url
             newNode.notes = notes
             newNode.notes = notes
-            tags = tags_strings
-            newNode.tags = tags
+            newNode.tags = tags_strings
             self.NewNodes.append(newNode)
             self.NewNodes.append(newNode)
 
 
     def save_new_nodes_to_db(self):
     def save_new_nodes_to_db(self):

+ 4 - 2
pwman/data/drivers/sqlite.py

@@ -23,6 +23,7 @@
 """SQLite Database implementation."""
 """SQLite Database implementation."""
 from pwman.data.database import Database, DatabaseException
 from pwman.data.database import Database, DatabaseException
 from pwman.data.nodes import NewNode
 from pwman.data.nodes import NewNode
+from pwman.util.crypto import CryptoEngine
 import sqlite3 as sqlite
 import sqlite3 as sqlite
 import pwman.util.config as config
 import pwman.util.config as config
 import itertools
 import itertools
@@ -136,8 +137,6 @@ class SQLiteDatabaseNewForm(Database):
                 if row is not None:
                 if row is not None:
                     nodestring = str(row[0])
                     nodestring = str(row[0])
                     args, tags = self.parse_node_string(nodestring)
                     args, tags = self.parse_node_string(nodestring)
-
-                    #node = NewNode(**nodeargs)
                     node = NewNode()
                     node = NewNode()
                     node._password = args['password']
                     node._password = args['password']
                     node._username = args['username']
                     node._username = args['username']
@@ -231,6 +230,7 @@ class SQLiteDatabaseNewForm(Database):
         """add tags to db"""
         """add tags to db"""
         # sql = "INSERT OR REPLACE INTO TAGS(DATA) VALUES(?)"
         # sql = "INSERT OR REPLACE INTO TAGS(DATA) VALUES(?)"
         sql = "INSERT OR IGNORE INTO TAGS(DATA) VALUES(?)"
         sql = "INSERT OR IGNORE INTO TAGS(DATA) VALUES(?)"
+
         if isinstance(tag, str):
         if isinstance(tag, str):
             self._cur.execute(sql, [tag])
             self._cur.execute(sql, [tag])
         else:
         else:
@@ -258,6 +258,8 @@ class SQLiteDatabaseNewForm(Database):
         for tag in tags:
         for tag in tags:
             try:
             try:
                 if isinstance(tag, str):
                 if isinstance(tag, str):
+                    enc = CryptoEngine.get()
+                    tag = enc.encrypt(tag)
                     self._cur.execute(sql, [tag])
                     self._cur.execute(sql, [tag])
                 else:
                 else:
                     self._cur.execute(sql, [tag._name+'%'])
                     self._cur.execute(sql, [tag._name+'%'])

+ 2 - 2
pwman/data/tags.py

@@ -56,8 +56,8 @@ class Tag(object):  # pragma: no cover
     the methods in this class override some built-ins
     the methods in this class override some built-ins
     for strings.
     for strings.
     """
     """
-    def __init__(self, name):
-        self.set_name(name)
+    #def __init__(self, name):
+    #    self.set_name(name)
 
 
     def __eq__(self, other):
     def __eq__(self, other):
         if other._name == self._name:
         if other._name == self._name: