فهرست منبع

windows related bug fixes

 pyreadline, instead of readline
Oz Nahum 11 سال پیش
والد
کامیت
6b4b3c2ed5
3فایلهای تغییر یافته به همراه60 افزوده شده و 9 حذف شده
  1. 13 7
      debian/rules
  2. 47 1
      pwman/ui/win.py
  3. 0 1
      scripts/pwman3

+ 13 - 7
debian/rules

@@ -33,13 +33,20 @@ if sys.platform != 'win32':
     import termios
     import fcntl
     import tty
+    try:
+        import pyreadline as readline
+        _readline_available = True
+    except ImportError:
+        _readline_available = False
+       # raise ImportError("You need 'pyreadline' on Windows")
+else:
+    try:
+        import readline
+        _readline_available = True
+    except ImportError, e:
+        _readline_available = False
 
 _defaultwidth = 10
-try:
-    import readline
-    _readline_available = True
-except ImportError, e:
-    _readline_available = False
 
 class ANSI(object):
     """
@@ -169,8 +176,7 @@ def getinput(question, default="", completer=None, width=_defaultwidth):
             readline.set_completer(completer)
 
         x = raw_input(question.ljust(width))
-
-        readline.set_completer(oldcompleter)
+        readline.set_completer(completer)
         readline.set_startup_hook()
         return x
 

+ 47 - 1
pwman/ui/win.py

@@ -23,14 +23,60 @@
 
 
 from pwman.ui.cli import PwmanCliNew
+from pwman.data.nodes import NewNode
 from pwman.ui import tools
 import time
 import msvcrt
 import pwman.util.config as config
-
+import ast
+from pwman.util.crypto import zerome
 
 class PwmanCliWinNew(PwmanCliNew):
 
+    def do_new(self, args):
+        """
+        can override default config settings the following way:
+        Pwman3 0.2.1 (c) visit: http://github.com/pwman3/pwman3
+        pwman> n {'leetify':False, 'numerics':True, 'special_chars':True}
+        Password (Blank to generate):
+        """
+        errmsg = """could not parse config override, please input some"""\
+                 + """ kind of dictionary, e.g.: n {'leetify':False, """\
+                 + """'numerics':True, 'special_chars':True}"""
+        try:
+            username = self.get_username()
+            if args:
+                try:
+                    args = ast.literal_eval(args)
+                except Exception:
+                    raise Exception(errmsg)
+                if not isinstance(args, dict):
+                    raise Exception(errmsg)
+                password = self.get_password(1, **args)
+            else:
+                numerics = config.get_value(
+                    "Generator", "numerics").lower() == 'true'
+                # TODO: allow custom leetifying through the config
+                leetify = config.get_value(
+                    "Generator", "leetify").lower() == 'true'
+                special_chars = config.get_value(
+                    "Generator", "special_chars").lower() == 'true'
+                password = self.get_password(0,
+                                             numerics=numerics,
+                                             symbols=leetify,
+                                             special_signs=special_chars)
+            url = self.get_url()
+            notes = self.get_notes()
+            node = NewNode(username, password, url, notes)
+            tags = self.get_tags()
+            node.set_tags(tags)
+            self._db.addnodes([node])
+            print "Password ID: %d" % (node.get_id())
+            # when done with node erase it
+            zerome(password)
+        except Exception, e:
+            self.error(e)
+
     def print_node(self, node):
         width = str(tools._defaultwidth)
         print "Node %d." % (node.get_id())

+ 0 - 1
scripts/pwman3

@@ -58,7 +58,6 @@ if 'darwin' in sys.platform:
     from pwman.ui.mac import PwmanCliMacNew as PwmanCliNew
     OSX = True
 elif 'win' in sys.platform:
-    print 2
     from pwman.ui.win import PwmanCliWinNew as PwmanCli
     OSX = False
 else: