Parcourir la source

More simplification of edit menu

oz123 il y a 10 ans
Parent
commit
f9c5d262b0
3 fichiers modifiés avec 18 ajouts et 31 suppressions
  1. 7 17
      pwman/ui/baseui.py
  2. 9 12
      pwman/ui/tools.py
  3. 2 2
      pwman/util/config.py

+ 7 - 17
pwman/ui/baseui.py

@@ -143,7 +143,7 @@ class AliasesMixin(object):  # pragma: no cover
     def do_cp(self, args):
         self.do_copy(args)
 
-    def do_EOF(self, args):
+    def do_EOF(self, args):  # pragma: no cover
         self.do_exit(args)
 
     def do_ls(self, args):
@@ -378,23 +378,13 @@ class BaseCommands(HelpUIMixin, AliasesMixin):
                 menu = CMDLoop(self.config)
                 print ("Editing node %d." % (i))
 
-                menu.add(CliMenuItem("Username",
-                                     self._get_input,
-                                     node.username,
-                                     ))
-                menu.add(CliMenuItem("Password", self._get_secret,
-                                     node.password,
-                                     ))
-                menu.add(CliMenuItem("Url", self._get_input,
-                                     node.url,
-                                     ))
-                menunotes = CliMenuItem("Notes", self._get_input,
-                                        node.notes,
-                                        )
+                menu.add(CliMenuItem("Username", node.username))
+                menu.add(CliMenuItem("Password",  node.password))
+                menu.add(CliMenuItem("Url", node.url))
+                menunotes = CliMenuItem("Notes", node.notes)
                 menu.add(menunotes)
                 tgetter = lambda: ', '.join(t for t in node.tags)
-                menu.add(CliMenuItem("Tags", self._get_input,
-                                     tgetter()))
+                menu.add(CliMenuItem("Tags", tgetter()))
             menu.run(node)
             self._db.editnode(i, **node.to_encdict())
             # when done with node erase it
@@ -449,7 +439,7 @@ class BaseCommands(HelpUIMixin, AliasesMixin):
             print("print accepts only a single ID ...")
             return
         nodes = self._db.getnodes([args])
-        if not nodes:
+        if not nodes:  # pragma: no cover
             print("Node not found ...")
             return
 

+ 9 - 12
pwman/ui/tools.py

@@ -128,7 +128,7 @@ def open_url(link, macosx=False):  # pragma: no cover
         print("Executing open_url failed with:\n", e)
 
 
-def get_terminal_size():
+def get_terminal_size():  # pragma: no cover
     """ getTerminalSize()
      - get width and height of console
      - works on linux,os x,windows,cygwin(windows)
@@ -251,7 +251,7 @@ def getinput(question, default="", reader=raw_input,
         return reader()
 
 
-def get_or_create_pass():
+def get_or_create_pass():  # pragma: no cover
 
     p = getpass.getpass(prompt='Password (leave empty to create one):')
     if not p:
@@ -278,7 +278,7 @@ def _get_secret():
     return p
 
 
-def set_selection(new_node, items, selection, reader):
+def set_selection(new_node, items, selection, reader):  # pragma: no cover
     if selection == 0:
         new_node.username = getinput("Username:")
         items[0].getter = new_node.username
@@ -300,7 +300,7 @@ def set_selection(new_node, items, selection, reader):
         items[4].getter = new_node.tags
 
 
-class CMDLoop(object):  # pragma: no cover
+class CMDLoop(object):
 
     """
     The menu that drives editing of a node
@@ -311,10 +311,8 @@ class CMDLoop(object):  # pragma: no cover
         self.config = config
 
     def add(self, item):
-        if (isinstance(item, CliMenuItem)):
+        if isinstance(item, CliMenuItem):
             self.items.append(item)
-        else:
-            print (item.__class__)
 
     def run(self, new_node=None, reader=raw_input):
         while True:
@@ -322,23 +320,22 @@ class CMDLoop(object):  # pragma: no cover
                 print ("%s - %s: %s" % (i + 1, x.name, x.getter))
 
             print("X - Finish editing")
-            option = reader("E)ter your choice:")[0]
+            option = reader("Enter your choice:")[0]
             try:
                 print ("Selection, ", option)
                 # substract 1 because array subscripts start at 0
                 selection = int(option) - 1
                 set_selection(new_node, self.items, selection, reader)
-            except (ValueError, IndexError):
+            except (ValueError, IndexError):  # pragma: no cover
                 if (option.upper() == 'X'):
                     break
                 print("Invalid selection")
 
 
-class CliMenuItem(object):  # pragma: no cover
+class CliMenuItem(object):
 
-    def __init__(self, name, editor, getter):
+    def __init__(self, name, getter):
         self.name = name
-        self.editor = editor
         self.getter = getter
 
 

+ 2 - 2
pwman/util/config.py

@@ -100,7 +100,7 @@ class Config(object):
     def set_value(self, section, name, value):
         self.parser.set(section, name, value)
 
-    def save(self, filename, parser=None):
+    def save(self, filename, parser=None):  # pragma: no cover
         with open(filename, "w") as fp:
             if parser:
                 parser.write(fp)
@@ -108,7 +108,7 @@ class Config(object):
                 self.parser.write(fp)
 
 
-def get_pass_conf(config):
+def get_pass_conf(config):  # pragma: no cover
     numerics = config.get_value("Generator", "numerics").lower() == 'true'
     # TODO: allow custom leetifying through the config
     leetify = config.get_value("Generator", "leetify").lower() == 'true'