oz123 пре 12 година
родитељ
комит
70abdbc6ee
4 измењених фајлова са 61 додато и 31 уклоњено
  1. 0 1
      .gitignore
  2. 24 1
      README
  3. 26 23
      pwman/ui/cli.py
  4. 11 6
      scripts/pwman3

+ 0 - 1
.gitignore

@@ -1,2 +1 @@
 *.pyc
-build

+ 24 - 1
README

@@ -27,8 +27,9 @@ when using python >= 2.5
     python-crypto
 
 for nicer functionality:
+    
     xsel - to copy password to clipboard on Linux
-
+    
 
 
 Pwman now uses argparse, which is only
@@ -46,6 +47,28 @@ To install:
 
     $ python setup.py install
 
+## User Insterface
+
+   1. When xsel is install on a Linux system, you can copy passwords directly to clipboard with the copy command.
+   2. The command 'open' will open the default browser if URL is specified.
+   3. An automatic 'clear screen' function is called after printing an entry in the database. 
+      The screen will be cleared after 5 seconds by default. However, this can be changed by changing the 
+      correct value in `~.pwman/config`:
+      
+      ```
+      [Global]
+      ...
+      cls_timeout = 10
+      ```
+      To disable the automatic 'clear screen' functionality set `cls_timeout` to a negative integer. 
+
+      ```
+      [Global]
+      ...
+      cls_timeout = -1
+      ```
+
+
 ## ikegam's function 
 
  * making a password from the numeric character and the alphabet character ([A-Za-z0-9]).

+ 26 - 23
pwman/ui/cli.py

@@ -18,6 +18,9 @@
 #============================================================================
 # Copyright (C) 2006 Ivan Kelly <ivan@ivankelly.net>
 #============================================================================
+"""
+Define the CLI interface for pwman3 and the helper functions
+"""
 
 import pwman
 import pwman.exchange.importer as importer
@@ -140,7 +143,7 @@ class PwmanCli(cmd.Cmd):
     def get_notes(self, default=""):
         return getinput("Notes: ", default)
 
-    def get_tags(self, default=""):
+    def get_tags(self, default="tag"):
         defaultstr = ''
 
         if len(default) > 0:
@@ -213,13 +216,15 @@ class PwmanCli(cmd.Cmd):
                     break
                 time.sleep(period)
             self.do_cls('')
-
-        if sys.platform != 'win32':
-            print "Type Enter to flush screen (autoflash in 5 sec.)"
-            waituntil_enter(heardEnter, 5)
-        else:
-            print "Press any key to flush screen (autoflash in 5 sec.)"
-            waituntil_enter(heardEnterWin, 5)
+        
+        flushtimeout = int(config.get_value("Global", "cls_timeout"))
+        if flushtimeout > 0:
+            if sys.platform != 'win32':
+                print "Type Enter to flush screen (autoflash in 5 sec.)"
+                waituntil_enter(heardEnter, flushtimeout)
+            else:
+                print "Press any key to flush screen (autoflash in 5 sec.)"
+                waituntil_enter(heardEnterWin, flushtimeout)
 
     def do_tags(self, arg):
         tags = self._db.listtags()
@@ -310,15 +315,15 @@ class PwmanCli(cmd.Cmd):
             args = arg.split()
             if len(args) == 0:
                 types = importer.Importer.types()
-                ftype = select("Select filetype:", types)
-                imp = importer.Importer.get(ftype)
-                imfile = getinput("Select file:")
-                imp.import_data(self._db, imfile)
+                intype = select("Select filetype:", types)
+                imp = importer.Importer.get(intype)
+                infile = getinput("Select file:")
+                imp.import_data(self._db, infile)
             else:
                 for i in args:
                     types = importer.Importer.types()
-                    ftype = select("Select filetype:", types)
-                    imp = importer.Importer.get(ftype)
+                    intype = select("Select filetype:", types)
+                    imp = importer.Importer.get(intype)
                     imp.import_data(self._db, i)
         except Exception, e:
             self.error(e)
@@ -330,12 +335,12 @@ class PwmanCli(cmd.Cmd):
             types = exporter.Exporter.types()
             ftype = select("Select filetype:", types)
             exp = exporter.Exporter.get(ftype)
-            exfile = getinput("Select output file:")
+            out_file = getinput("Select output file:")
             if len(nodes) > 0:
                 b = getyesno("Export nodes %s?" % (nodes), True)
                 if not b:
                     return
-                exp.export_data(self._db, exfile, nodes)
+                exp.export_data(self._db, out_file, nodes)
             else:
                 nodes = self._db.listnodes()
                 tags = self._db.currenttags()
@@ -348,7 +353,7 @@ class PwmanCli(cmd.Cmd):
                 b = getyesno("Export all nodes%s?" % (tagstr), True)
                 if not b:
                     return
-                exp.export_data(self._db, exfile, nodes)
+                exp.export_data(self._db, out_file, nodes)
             print "Data exported."
         except Exception, e:
             self.error(e)
@@ -569,9 +574,6 @@ the url must contain http:// or https://."
         self.usage("cls")
         print "Clear the Screen from information."
 
-    def help_ls(self):
-        self.help_list()
-
     def help_list(self):
         self.usage("list <tag> ...")
         print "List nodes that match current or specified filter. ls is an alias."
@@ -676,8 +678,8 @@ the url must contain http:// or https://."
         connecion, see if we have xsel ...
         """
         cmd.Cmd.__init__(self)
-        self.intro = "%s %s (c) %s <%s>" % (pwman.appname, pwman.version,
-                                            pwman.author, pwman.authoremail)
+        self.intro = "%s %s (c) visit: %s" % (pwman.appname, pwman.version,
+                                            pwman.website)
         self._historyfile = config.get_value("Readline", "history")
         self.hasxsel = hasxsel
         try:
@@ -800,8 +802,9 @@ def getinput(question, default="", completer=None, width=_defaultwidth):
         return raw_input(question.ljust(width))
     else:
         def defaulter(): 
+            """define default behavior startup"""
             readline.insert_text(default)
-        
+
         readline.set_startup_hook(defaulter)
         oldcompleter = readline.get_completer()
         readline.set_completer(completer)

+ 11 - 6
scripts/pwman3

@@ -51,12 +51,14 @@ if args.test:
 from pwman.util.crypto import CryptoEngine
 import getopt
 import sys
+
 if 'darwin' in sys.platform:
     from pwman.ui.cli import PwmanCliMac as PwmanCli
-    OSX=True
+    OSX = True
 else:
     from pwman.ui.cli import PwmanCli
-    OSX=False
+    OSX = False
+
 
 import pwman.util.config as config
 import pwman.data.factory
@@ -81,8 +83,10 @@ try:
         os.mkdir(config_dir)
 
     config_file = os.path.join(config_dir, "config")
-
-    default_config = {'Global': {'umask': '0100', 'colors': 'yes'},
+    # set cls_timout to negative number (e.g. -1) to disable
+    default_config = {'Global': {'umask': '0100', 'colors': 'yes',
+                                 'cls_timeout': '5'
+                                },
                       'Database': {'type': 'SQLite',
                                    'filename': os.path.join(config_dir,
                                                             "pwman.db")},
@@ -90,8 +94,9 @@ try:
                       'Readline': {'history': os.path.join(config_dir,
                                                            "history")}
                       }
+    
     config.set_defaults(default_config)
-
+    
     if os.path.exists(config_file):
         config.load(config_file)
         xselpath = config.get_value("Global", "xselpath")
@@ -114,7 +119,7 @@ try:
     os.umask(umask)
 
     enc = CryptoEngine.get()
-
+    
     dbtype = config.get_value("Database", "type")
     db = pwman.data.factory.create(dbtype)
     cli = PwmanCli(db, xselpath)