Browse Source

Fix do_print

oz123 10 năm trước cách đây
mục cha
commit
d3e8d773a3
2 tập tin đã thay đổi với 21 bổ sung8 xóa
  1. 20 1
      pwman/data/nodes.py
  2. 1 7
      pwman/ui/baseui.py

+ 20 - 1
pwman/data/nodes.py

@@ -18,8 +18,9 @@
 # ============================================================================
 # Copyright (C) 2006 Ivan Kelly <ivan@ivankelly.net>
 # ============================================================================
-
+from colorama import Fore
 from pwman.util.crypto_engine import CryptoEngine
+import pwman.ui.tools
 
 
 class Node(object):
@@ -34,6 +35,24 @@ class Node(object):
             self._tags = [enc.encrypt(t).strip() for t in kwargs.get('tags',
                                                                      '')]
 
+    def __str__(self):
+        p = "{entry_title:>{width}} {entry:<{width}}\n".format(
+            entry_title=pwman.ui.tools.typeset('Username:', Fore.RED),
+            width=10, entry=self.username)
+        p += "{entry_title:>{width}} {entry:<{width}}\n".format(
+            entry_title=pwman.ui.tools.typeset('Password:', Fore.RED),
+            width=10, entry=self.password)
+        p += "{entry_title:>{width}} {entry:<{width}}\n".format(
+            entry_title=pwman.ui.tools.typeset('URL:', Fore.RED),
+            width=10, entry=self.url)
+        p += "{entry_title:>{width}} {entry:<{width}}\n".format(
+            entry_title=pwman.ui.tools.typeset('Notes:', Fore.RED),
+            width=10, entry=self.notes)
+        p += "{entry_title:>{width}} {entry:<{width}}\n".format(
+            entry_title=pwman.ui.tools.typeset('Tags:', Fore.RED),
+            width=10, entry=self.tags)
+        return p
+
     @classmethod
     def from_encrypted_entries(cls, username, password, url, notes, tags):
         """

+ 1 - 7
pwman/ui/baseui.py

@@ -252,10 +252,4 @@ class BaseCommands(HelpUIMixin, AliasesMixin):
             return
         nodes = self._db.getnodes([args])
         node = self._db_entries_to_nodes(nodes)[0]
-
-        titles = ['Username', 'Password', 'URL', 'Notes', 'Tags']
-        entry = "Ya"
-        for title in titles:
-            print("{entry_title:>{width}} {entry:<{width}}".format(
-                  entry_title=tools.typeset(title, Fore.RED), width=10,
-                  entry=entry))
+        print(node)