Browse Source

Continue work on do_edit

 * code clean up in pwman.ui.tools
oz123 10 years ago
parent
commit
971380f625
3 changed files with 17 additions and 33 deletions
  1. 10 6
      pwman/data/nodes.py
  2. 3 4
      pwman/ui/baseui.py
  3. 4 23
      pwman/ui/tools.py

+ 10 - 6
pwman/data/nodes.py

@@ -77,13 +77,15 @@ class Node(object):
     def password(self):
         """Get the current password."""
         enc = CryptoEngine.get()
-        return enc.decrypt(self._password).strip()
+        p = enc.decrypt(self._password).strip()
+        return p.decode()
 
     @property
     def username(self):
         """Get the current username."""
         enc = CryptoEngine.get()
-        return enc.decrypt(self._username).strip()
+        u = enc.decrypt(self._username).strip()
+        return u.decode()
 
     @username.setter
     def username(self, value):
@@ -101,10 +103,10 @@ class Node(object):
     def tags(self):
         enc = CryptoEngine.get()
         try:
-            return [enc.decrypt(tag) for tag in
+            return [enc.decrypt(tag).decode() for tag in
                     filter(None, self._tags)]
         except Exception:
-            return [tag for tag in filter(None, self._tags)]
+            return [tag.decode() for tag in filter(None, self._tags)]
 
     @tags.setter
     def tags(self, value):
@@ -114,7 +116,8 @@ class Node(object):
     def url(self):
         """Get the current url."""
         enc = CryptoEngine.get()
-        return enc.decrypt(self._url).strip()
+        u = enc.decrypt(self._url).strip()
+        return u.decode()
 
     @url.setter
     def url(self, value):
@@ -126,7 +129,8 @@ class Node(object):
     def notes(self):
         """Get the current notes."""
         enc = CryptoEngine.get()
-        return enc.decrypt(self._notes).strip()
+        n = enc.decrypt(self._notes).strip()
+        return n.decode()
 
     @notes.setter
     def notes(self, value):

+ 3 - 4
pwman/ui/baseui.py

@@ -157,8 +157,7 @@ class BaseCommands(HelpUIMixin, AliasesMixin):
                                                 node[5:])
                 tags = n.tags
                 tags = ','.join(t.strip().decode() for t in tags)
-                r = list(map(bytes.decode, [n.username, n.url, n.password,
-                                            n.notes]))
+                r = list([n.username, n.url, n.password, n.notes])
                 writer.writerow(r + [tags])
 
         print("Successfuly exported database to {}".format(
@@ -252,7 +251,6 @@ class BaseCommands(HelpUIMixin, AliasesMixin):
         for i in ids:
             try:
                 i = int(i)
-                import ipdb; ipdb.set_trace()
                 node = self._db.getnodes([i])[0]
                 node = node[1:5] + [node[5:]]
                 node = Node.from_encrypted_entries(*node)
@@ -275,8 +273,9 @@ class BaseCommands(HelpUIMixin, AliasesMixin):
                                             node.notes,
                                             node.notes)
                     menu.add(menunotes)
+                    tgetter = lambda: ', '.join(t for t in node.tags)
                     menu.add(CliMenuItem("Tags", self._get_input,
-                                         node.tags,
+                                         tgetter(),
                                          node.tags))
                 menu.run(node)
                 self._db.editnode(i, node)

+ 4 - 23
pwman/ui/tools.py

@@ -239,29 +239,10 @@ class CMDLoop(object):  # pragma: no cover
 
     def run(self, new_node=None, reader=raw_input):
         while True:
-            i = 0
-            for x in self.items:
-                i = i + 1
-                try:
-                    current = x.getter
-                except AttributeError:
-                    current = x
-
-                # when printing tags, we have list ...
-                currentstr = b''
-                if type(current) == list:
-                    for c in current:
-                        print(c, type(c))
-                        try:
-                            currentstr += b' ' + c
-                        except TypeError:
-                            currentstr += b' ' + c.name
-                # for the case we are not dealing with
-                # a list of tags
-                else:
-                    currentstr = current
-
-                print ("%s - %s: %s" % (i, x.name, currentstr))
+            for i, x in enumerate(self.items):
+                current = x.getter
+                print ("%s - %s: %s" % (i + 1, x.name, current))
+
             print("X - Finish editing")
             option = reader("Enter your choice:")[0]
             try: