Sfoglia il codice sorgente

Start working on do edit

oz123 10 anni fa
parent
commit
ab68655116
2 ha cambiato i file con 43 aggiunte e 6 eliminazioni
  1. 2 2
      pwman/ui/base.py
  2. 41 4
      pwman/ui/baseui.py

+ 2 - 2
pwman/ui/base.py

@@ -237,8 +237,8 @@ class BaseCommands(object):
     #               "%d sec.)" % flushtimeout)
     #         waituntil_enter(heardEnter, flushtimeout)
 
-    def do_passwd(self, args):
-        raise Exception("Not Implemented ...")
+    #def do_passwd(self, args):
+    #    raise Exception("Not Implemented ...")
         #try:
         #    key = self._db.changepassword()
         #    self._db.savekey(key)

+ 41 - 4
pwman/ui/baseui.py

@@ -30,6 +30,9 @@ from pwman.data.nodes import Node
 from pwman.ui import tools
 from pwman.util.crypto_engine import CryptoEngine
 from .base import HelpUIMixin, AliasesMixin
+from pwman.util.crypto_engine import zerome
+from pwman.ui.tools import CliMenuItem
+from pwman.ui.tools import CMDLoop
 
 if sys.version_info.major > 2:  # pragma: no cover
     raw_input = input
@@ -133,10 +136,6 @@ class BaseCommands(HelpUIMixin, AliasesMixin):
         """clear the screen"""
         os.system("clear")
 
-    def do_edit(self, args):
-        """edit a node"""
-        pass
-
     def do_export(self, args):
         """export the database to a given format"""
         try:
@@ -248,6 +247,44 @@ class BaseCommands(HelpUIMixin, AliasesMixin):
             _nodes_inst[-1]._id = node[0]
         return _nodes_inst
 
+    def do_edit(self, args, menu=None):
+        ids = self._get_ids(args)
+        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)
+
+                if not menu:
+                    menu = CMDLoop()
+                    print ("Editing node %d." % (i))
+
+                    menu.add(CliMenuItem("Username",
+                                         self._get_input,
+                                         node.username,
+                                         node.username))
+                    menu.add(CliMenuItem("Password", self._get_secret,
+                                         node.password,
+                                         node.password))
+                    menu.add(CliMenuItem("Url", self._get_input,
+                                         node.url,
+                                         node.url))
+                    menunotes = CliMenuItem("Notes", self._get_input,
+                                            node.notes,
+                                            node.notes)
+                    menu.add(menunotes)
+                    menu.add(CliMenuItem("Tags", self._get_input,
+                                         node.tags,
+                                         node.tags))
+                menu.run(node)
+                self._db.editnode(i, node)
+                # when done with node erase it
+                zerome(node._password)
+            except Exception as e:
+                self.error(e)
+
     def do_list(self, args):
         """list all existing nodes in database"""
         rows, cols = self._prep_term()