فهرست منبع

get rid of all get_* in new sqlite driver class

also get rid of all calles to those function and
replace with appropriate pythonic calles
oz123 11 سال پیش
والد
کامیت
42e2a5551c
4فایلهای تغییر یافته به همراه50 افزوده شده و 42 حذف شده
  1. 4 4
      pwman/data/drivers/sqlite.py
  2. 2 34
      pwman/data/nodes.py
  3. 33 2
      pwman/ui/cli.py
  4. 11 2
      pwman/ui/tools.py

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

@@ -198,7 +198,7 @@ class SQLiteDatabaseNewForm(Database):
             #    "Tried to delete foreign object from database [%s]", n)
             try:
                 sql = "DELETE FROM NODES WHERE ID = ?"
-                self._cur.execute(sql, [n.get_id()])
+                self._cur.execute(sql, [n._id])
 
             except sqlite.DatabaseError, e:
                 raise DatabaseException("SQLite: %s" % (e))
@@ -268,17 +268,17 @@ class SQLiteDatabaseNewForm(Database):
     def _deletenodetags(self, node):
         try:
             sql = "DELETE FROM LOOKUP WHERE NODE = ?"
-            self._cur.execute(sql, [node.get_id()])
+            self._cur.execute(sql, [node._id])
         except sqlite.DatabaseError, e:
             raise DatabaseException("SQLite: %s" % (e))
         self._commit()
 
     def _setnodetags(self, node):
         self._deletenodetags(node)
-        ids = self._tagids(node.get_tags())
+        ids = self._tagids(node.tags)
         for i in ids:
             sql = "INSERT OR REPLACE INTO LOOKUP VALUES(?, ?)"
-            params = [node.get_id(), i]
+            params = [node._id, i]
 
             try:
                 self._cur.execute(sql, params)

+ 2 - 34
pwman/data/nodes.py

@@ -45,6 +45,8 @@ class NewNode(object):
             return enc.decrypt(self._url).strip()
         elif name == 'notes':
             return enc.decrypt(self._notes).strip()
+        elif name == 'tags':
+            return [tag for tag in self._tags]
 
     def dump_edit_to_db(self):
         enc = CryptoEngine.get()
@@ -82,12 +84,6 @@ class NewNode(object):
         dump = [dump]
         return dump
 
-    def get_tags(self):
-        tags = []
-        for tag in self._tags:
-            tags.append(tag)
-        return tags
-
     def set_tags(self, tags):
         """
         this method expects a list of tag instances.
@@ -100,32 +96,9 @@ class NewNode(object):
         if tags:
             self._tags = [t for t in tags]
 
-    def get_id(self):
-        return self._id
-
     def set_id(self, id):
         self._id = id
 
-    def get_username(self):
-        """
-        Return the username.
-        This solution with strip is horribly assuming that
-        the username does not containg space as the last character.
-        The same is also true for the password.
-        """
-        enc = CryptoEngine.get()
-        return enc.decrypt(self._username).strip()
-
-    def set_username(self, username):
-        """Set the username."""
-        enc = CryptoEngine.get()
-        self._username = enc.encrypt(username)
-
-    def get_password(self):
-        """Return the password."""
-        enc = CryptoEngine.get()
-        return enc.decrypt(self._password).strip()
-
     def set_password(self, password):
         """Set the password."""
         enc = CryptoEngine.get()
@@ -141,11 +114,6 @@ class NewNode(object):
         enc = CryptoEngine.get()
         self._url = enc.encrypt(url)
 
-    def get_notes(self):
-        """Return the Notes."""
-        enc = CryptoEngine.get()
-        return enc.decrypt(self._notes)
-
     def set_notes(self, notes):
         """Set the Notes."""
         enc = CryptoEngine.get()

+ 33 - 2
pwman/ui/cli.py

@@ -773,6 +773,37 @@ class PwmanCliNew(PwmanCli):
 
         self.prompt = "pwman> "
 
+    def do_edit(self, arg):
+        ids = self.get_ids(arg)
+        for i in ids:
+            try:
+                i = int(i)
+                node = self._db.getnodes([i])[0]
+                menu = CliMenu()
+                print "Editing node %d." % (i)
+
+                menu.add(CliMenuItem("Username", self.get_username,
+                                     node.username,
+                                     node.set_username))
+                menu.add(CliMenuItem("Password", self.get_password,
+                                     node.password,
+                                     node.set_password))
+                menu.add(CliMenuItem("Url", self.get_url,
+                                     node.url,
+                                     node.set_url))
+                menu.add(CliMenuItem("Notes", self.get_notes,
+                                     node.notes,
+                                     node.set_notes))
+                menu.add(CliMenuItem("Tags", self.get_tags,
+                                     node.tags,
+                                     node.set_tags))
+                menu.run()
+                self._db.editnode(i, node)
+                # when done with node erase it
+                zerome(node._password)
+            except Exception, e:
+                self.error(e)
+
     def print_node(self, node):
         width = str(tools._defaultwidth)
         print "Node %d." % (node._id)
@@ -785,7 +816,7 @@ class PwmanCliNew(PwmanCli):
         print ("%"+width+"s %s") % (tools.typeset("Notes:", Fore.RED),
                                     node.notes)
         print tools.typeset("Tags: ", Fore.RED),
-        for t in node.get_tags():
+        for t in node.tags:
             print " %s " % t
         print
 
@@ -872,7 +903,7 @@ class PwmanCliNew(PwmanCli):
             cols -= 8
             i = 0
             for n in nodes:
-                tags = n.get_tags()
+                tags = n.tags
                 tags = filter(None, tags)
                 tagstring = ''
                 first = True

+ 11 - 2
pwman/ui/tools.py

@@ -214,7 +214,12 @@ class CliMenu(object):
             i = 0
             for x in self.items:
                 i = i + 1
-                current = x.getter()
+                # don't break compatability with old db
+                try:
+                    current = x.getter()
+                except TypeError:
+                    current = x.getter
+
                 currentstr = ''
                 if type(current) == list:
                     for c in current:
@@ -238,7 +243,11 @@ class CliMenu(object):
                 if selection == 1:  # for password
                     value = self.items[selection].editor(0)
                 else:
-                    edit = self.items[selection].getter()
+                    try:
+                        edit = self.items[selection].getter()
+                    except TypeError:
+                        edit = self.items[selection].getter
+
                     value = self.items[selection].editor(edit)
                 self.items[selection].setter(value)
             except (ValueError, IndexError):