Browse Source

Overhaul mac and win ui modules

oz123 10 years ago
parent
commit
1f0f04ed95
3 changed files with 34 additions and 33 deletions
  1. 2 1
      pwman/tests/test_pwman.py
  2. 13 13
      pwman/ui/mac.py
  3. 19 19
      pwman/ui/win.py

+ 2 - 1
pwman/tests/test_pwman.py

@@ -51,4 +51,5 @@ def suite():
     return suite
 
 if __name__ == '__main__':
-    unittest.TextTestRunner(verbosity=2).run(suite())
+    unittest.main()
+    #unittest.TextTestRunner(verbosity=2).run(suite())

+ 13 - 13
pwman/ui/mac.py

@@ -1,4 +1,4 @@
-#============================================================================
+# ============================================================================
 # This file is part of Pwman3.
 #
 # Pwman3 is free software; you can redistribute it and/or modify
@@ -13,13 +13,13 @@
 # You should have received a copy of the GNU General Public License
 # along with Pwman3; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-#============================================================================
+# ============================================================================
 # Copyright (C) 2012 Oz Nahum <nahumoz@gmail.com>
-#============================================================================
+# ============================================================================
 # Copyright (C) 2006 Ivan Kelly <ivan@ivankelly.net>
-#============================================================================
+# ============================================================================
 # pylint: disable=I0011
-
+from __future__ import print_function
 "all mac os  related classes"
 
 from pwman.ui.cli import PwmanCliNew
@@ -36,13 +36,13 @@ class PwmanCliMac(PwmanCliNew):
     def do_copy(self, args):
         ids = self.get_ids(args)
         if len(ids) > 1:
-            print "Can only 1 password at a time..."
+            print("Can only 1 password at a time...")
         try:
             node = self._db.getnodes(ids)
             node[0].get_password()
             tools.text_to_mcclipboard(node[0].get_password())
-            print "copied password for {}@{} clipboard".format(
-                node[0].get_username(), node[0].get_url())
+            print("copied password for {}@{} clipboard".format(
+                  node[0].get_username(), node[0].get_url()))
             time.sleep(10)
             tools.text_to_clipboards("")
         except Exception as e:
@@ -57,7 +57,7 @@ class PwmanCliMac(PwmanCliNew):
             self.help_open()
             return
         if len(ids) > 1:
-            print "Can open only 1 link at a time ..."
+            print("Can open only 1 link at a time ...")
             return None
         try:
             node = self._db.getnodes(ids)
@@ -70,19 +70,19 @@ class PwmanCliMac(PwmanCliNew):
         self.do_open(args)
 
     ##
-    ## Help functions
+    # Help functions
     ##
     def help_open(self):
         self.usage("open <ID>")
-        print "Launch default browser with 'open url',\n" \
-              + "the url must contain http:// or https://."
+        print("Launch default browser with 'open url',\n"
+              "the url must contain http:// or https://.")
 
     def help_o(self):
         self.help_open()
 
     def help_copy(self):
         self.usage("copy <ID>")
-        print "Copy password to Cocoa clipboard using pbcopy"
+        print("Copy password to Cocoa clipboard using pbcopy")
 
     def help_cp(self):
         self.help_copy()

+ 19 - 19
pwman/ui/win.py

@@ -1,5 +1,5 @@
 """"
-#============================================================================
+# ============================================================================
 # This file is part of Pwman3.
 #
 # Pwman3 is free software; you can redistribute it and/or modify
@@ -14,12 +14,13 @@
 # You should have received a copy of the GNU General Public License
 # along with Pwman3; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-#============================================================================
+# ============================================================================
 # Copyright (C) 2012 Oz Nahum <nahumoz@gmail.com>
-#============================================================================
+# ============================================================================
 # Copyright (C) 2006 Ivan Kelly <ivan@ivankelly.net>
-#============================================================================
+# ============================================================================
 """
+from __future__ import print_function
 from pwman.ui.cli import PwmanCliNew
 from pwman.data.nodes import NewNode
 from pwman.ui import tools
@@ -35,6 +36,7 @@ try:
 except ImportError:
     pass
 
+
 class PwmanCliWinNew(PwmanCliNew):
     """
     windows ui class
@@ -77,7 +79,7 @@ class PwmanCliWinNew(PwmanCliNew):
             tags = self.get_tags()
             node.tags = tags
             self._db.addnodes([node])
-            print "Password ID: %d" % (node._id)
+            print("Password ID: %d" % (node._id))
             # when done with node erase it
             zerome(password)
         except Exception as e:
@@ -85,18 +87,16 @@ class PwmanCliWinNew(PwmanCliNew):
 
     def print_node(self, node):
         width = str(tools._defaultwidth)
-        print "Node %d." % (node.get_id())
-        print ("%" + width+"s %s") % (tools.typeset("Username:", Fore.RED),
-                                    node.get_username())
-        print ("%"+width+"s %s") % (tools.typeset("Password:", Fore.RED),
-                                    node.get_password())
-        print ("%"+width+"s %s") % (tools.typeset("Url:", Fore.RED),
-                                    node.get_url())
-        print ("%"+width+"s %s") % (tools.typeset("Notes:", Fore.RED),
-                                    node.get_notes())
-        print tools.typeset("Tags: ", Fore.RED),
-        for t in node.get_tags():
-            print " %s \n" % t.get_name(),
+        print("Node {}.".format(node._id))
+        print("{} {}".format(tools.typeset("Username:", Fore.RED).ljust(width),
+                             node.username))
+        print ("{} {}".format(tools.typeset("Password:", Fore.RED).ljust(width),
+                              node.password))
+        print("{} {}".format(tools.typeset("Url:", Fore.RED).ljust(width), node.url))
+        print("{} {}".format(tools.typeset("Notes:", Fore.RED).ljust(width), node.notes))
+        print("{}".format(tools.typeset("Tags: ", Fore.RED)), end=" ")
+        for t in node.tags:
+            print(t.name)
 
         def heardEnterWin():
             c = msvcrt.kbhit()
@@ -117,6 +117,6 @@ class PwmanCliWinNew(PwmanCliNew):
 
         flushtimeout = int(config.get_value("Global", "cls_timeout"))
         if flushtimeout > 0:
-            print "Press any key to flush screen (autoflash "\
-                + "in %d sec.)" % flushtimeout
+            print("Press any key to flush screen (autoflash "
+                  "in %d sec.)" % flushtimeout)
             waituntil_enter(heardEnterWin, flushtimeout)