Parcourir la source

Implement do_rm

oz123 il y a 10 ans
Parent
commit
55b4415f26
2 fichiers modifiés avec 45 ajouts et 29 suppressions
  1. 28 28
      pwman/ui/base.py
  2. 17 1
      pwman/ui/baseui.py

+ 28 - 28
pwman/ui/base.py

@@ -250,34 +250,34 @@ class BaseCommands(object):
         #except Exception as e:
         #    self.error(e)
 
-    def do_print(self, arg):
-        for i in self.get_ids(arg):
-            try:
-                node = self._db.getnodes([i])
-                self.print_node(node[0])
-                # when done with node erase it
-                zerome(node[0]._password)
-            except Exception as e:
-                self.error(e)
-
-    def do_delete(self, arg):
-        ids = self.get_ids(arg)
-        try:
-            nodes = self._db.getnodes(ids)
-            for n in nodes:
-                ans = ''
-                while True:
-                    ans = tools.getinput(("Are you sure you want to"
-                                         " delete '%s@%s' ([y/N])?"
-                                          ) % (n.username, n.url)
-                                         ).lower().strip('\n')
-                    if ans == '' or ans == 'y' or ans == 'n':
-                        break
-            if ans == 'y':
-                self._db.removenodes([n])
-                print ("%s@%s deleted" % (n.username, n.url))
-        except Exception as e:
-            self.error(e)
+    #def do_print(self, arg):
+    #    for i in self.get_ids(arg):
+    #        try:
+    #            node = self._db.getnodes([i])
+    #            self.print_node(node[0])
+    #            # when done with node erase it
+    #            zerome(node[0]._password)
+    #        except Exception as e:
+    #            self.error(e)
+
+    #def do_delete(self, arg):
+    #    ids = self.get_ids(arg)
+    #    try:
+    #        nodes = self._db.getnodes(ids)
+    #        for n in nodes:
+    #            ans = ''
+    #            while True:
+    #                ans = tools.getinput(("Are you sure you want to"
+    #                                     " delete '%s@%s' ([y/N])?"
+    #                                      ) % (n.username, n.url)
+    #                                     ).lower().strip('\n')
+    #                if ans == '' or ans == 'y' or ans == 'n':
+    #                    break
+    #        if ans == 'y':
+    #            self._db.removenodes([n])
+    #            print ("%s@%s deleted" % (n.username, n.url))
+    #    except Exception as e:
+    #        self.error(e)
 
     def get_ids(self, args):
         """

+ 17 - 1
pwman/ui/baseui.py

@@ -248,8 +248,24 @@ class BaseCommands(HelpUIMixin, AliasesMixin):
 
     def do_print(self, args):
         if not args.isdigit():
-            print("print accepts only IDs ...")
+            print("print accepts only a single ID ...")
             return
         nodes = self._db.getnodes([args])
         node = self._db_entries_to_nodes(nodes)[0]
         print(node)
+
+    def _do_rm(self, args):
+        for i in args.split():
+            if not i.isdigit():
+                print("%s is not a node ID" % i)
+                return None
+
+        for i in args.split():
+            ans = tools.getinput(("Are you sure you want to delete node {}"
+                                  " [y/N]?".format(i)))
+            if ans.lower() == 'y':
+                self._db.removenodes([i])
+
+    def do_delete(self, args):  # pragma: no cover
+        CryptoEngine.get()
+        self._do_rm(args)