Selaa lähdekoodia

some start of editing without using set_ and get_

not  100%  complete to all elements, but it is a start
oz123 11 vuotta sitten
vanhempi
commit
a05ecf909a
4 muutettua tiedostoa jossa 77 lisäystä ja 14 poistoa
  1. 13 5
      pwman/data/nodes.py
  2. 8 7
      pwman/ui/cli.py
  3. 55 2
      pwman/ui/tools.py
  4. 1 0
      tests/db_tests.py

+ 13 - 5
pwman/data/nodes.py

@@ -36,7 +36,8 @@ class NewNode(object):
         self.set_tags(tags)
 
     def __getattr__(self, name):
-        if name in ['username', 'password', 'url', 'notes']:
+
+        if name in ['username', 'password', 'url']:  # 'notes']:
             enc = CryptoEngine.get()
             return enc.decrypt(eval('self._'+name).strip())
         elif name == 'tags':
@@ -58,9 +59,7 @@ class NewNode(object):
         else:
             object.__setattr__(self, name, value)
 
-
     def dump_edit_to_db(self):
-        enc = CryptoEngine.get()
         dump = ""
         dump += "username:"+self._username+"##"
         dump += "password:"+self._password+"##"
@@ -120,10 +119,19 @@ class NewNode(object):
         enc = CryptoEngine.get()
         self._url = enc.encrypt(url)
 
-    def set_notes(self, notes):
+    @property
+    def notes(self):
+        """Get the current notes."""
+        print "ass"
+        enc = CryptoEngine.get()
+        return enc.decrypt(self._notes).strip()
+
+
+    @notes.setter
+    def notes(self, value):
         """Set the Notes."""
         enc = CryptoEngine.get()
-        self._notes = enc.encrypt(notes)
+        self._notes = enc.encrypt(value).strip()
 
 
 class Node(object):

+ 8 - 7
pwman/ui/cli.py

@@ -784,20 +784,21 @@ class PwmanCliNew(PwmanCli):
 
                 menu.add(CliMenuItem("Username", self.get_username,
                                      node.username,
-                                     node.set_username))
+                                     node.username))
                 menu.add(CliMenuItem("Password", self.get_password,
                                      node.password,
-                                     node.set_password))
+                                     node.password))
                 menu.add(CliMenuItem("Url", self.get_url,
                                      node.url,
                                      node.set_url))
-                menu.add(CliMenuItem("Notes", self.get_notes,
-                                     node.notes,
-                                     node.set_notes))
+                menunotes = CliMenuItem("Notes", self.get_notes,
+                                        node.notes,
+                                        node.notes)
+                menu.add(menunotes)
                 menu.add(CliMenuItem("Tags", self.get_tags,
                                      node.tags,
-                                     node.set_tags))
-                menu.run()
+                                     node.tags))
+                menu.runner(node)
                 self._db.editnode(i, node)
                 # when done with node erase it
                 zerome(node._password)

+ 55 - 2
pwman/ui/tools.py

@@ -245,11 +245,64 @@ class CliMenu(object):
                 else:
                     try:
                         edit = self.items[selection].getter()
+                        value = self.items[selection].editor(edit)
+                        self.items[selection].setter(value)
                     except TypeError:
                         edit = self.items[selection].getter
+                        value = self.items[selection].editor(edit)
+                        self.items[selection].setter = value
+            except (ValueError, IndexError):
+                if (option.upper() == 'X'):
+                    break
+                print "Invalid selection"
+
+
+    def runner(self, new_node):
+        while True:
+            i = 0
+            for x in self.items:
+                i = i + 1
+                # don't break compatability with old db
+                try:
+                    current = x.getter()
+                except TypeError:
+                    current = x.getter
+                except AttributeError:
+                    current = x
+                currentstr = ''
+                if type(current) == list:
+                    for c in current:
+                        currentstr += ("%s " % (c))
+                else:
+                    currentstr = current
 
-                    value = self.items[selection].editor(edit)
-                self.items[selection].setter(value)
+                print ("%d - %-"+str(_defaultwidth)
+                       + "s %s") % (i, x.name+":",
+                                    currentstr)
+            print "%c - Finish editing" % ('X')
+            option = getonechar("Enter your choice:")
+            try:
+                print "selection, ", option
+                # substract 1 because array subscripts start at 0
+                selection = int(option) - 1
+                # new value is created by calling the editor with the
+                # previous value as a parameter
+                # TODO: enable overriding password policy as if new node
+                # is created.
+                if selection == 1:  # for password
+                    value = self.items[selection].editor(0)
+                elif selection == 3:
+                    new_node.notes = getinput("Notes:")
+                    self.items[3].getter = new_node.notes
+                else:
+                    try:
+                        edit = self.items[selection].getter()
+                        value = self.items[selection].editor(edit)
+                        self.items[selection].setter(value)
+                    except TypeError:
+                        edit = self.items[selection].getter
+                        value = self.items[selection].editor(edit)
+                        self.items[selection].setter = value
             except (ValueError, IndexError):
                 if (option.upper() == 'X'):
                     break

+ 1 - 0
tests/db_tests.py

@@ -80,6 +80,7 @@ class DBTests(unittest.TestCase):
         for key, attr in {'password': password, 'username': username,
                           'url': url, 'notes': notes}.iteritems():
             self.assertEquals(attr, eval('new_node.'+key))
+
         self.db.close()