Prechádzať zdrojové kódy

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 rokov pred
rodič
commit
ea1c5352c8
3 zmenil súbory, kde vykonal 12 pridanie a 14 odobranie
  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
 import os
 import shutil
-import os.path
 import time
 import getpass
 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.tags import Tag
 import sys
-
-_NEWVERSION = 0.4
-
+import re
 from pwman.data.database import Database, DatabaseException
 import sqlite3 as sqlite
 import pwman.util.config as config
 import cPickle
 
+_NEWVERSION = 0.4
 
 class SQLiteDatabaseReader(Database):
     """SQLite Database implementation"""
@@ -91,8 +89,8 @@ class SQLiteDatabaseReader(Database):
                 else:
                     first = False
                 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))
         try:
@@ -234,18 +232,16 @@ class PwmanConvertDB(object):
         for node in self.oldnodes:
             username = node.get_username()
             password = node.get_password()
-
             url = node.get_url()
             notes = node.get_notes()
             tags = node.get_tags()
-            tags_strings = [tag.get_name() for tag in tags]
+            tags_strings = [ tag._name for tag in tags]
             newNode = NewNode()
             newNode.username = username
             newNode.password = password
             newNode.url = url
             newNode.notes = notes
-            tags = tags_strings
-            newNode.tags = tags
+            newNode.tags = tags_strings
             self.NewNodes.append(newNode)
 
     def save_new_nodes_to_db(self):

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

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