Selaa lähdekoodia

remove duplicate code (which and default config)

both are now found in pwman/__init__.py
oz123 11 vuotta sitten
vanhempi
commit
6d9cfdd8ad
3 muutettua tiedostoa jossa 36 lisäystä ja 48 poistoa
  1. 26 1
      pwman/__init__.py
  2. 7 21
      pwman/tests/db_tests.py
  3. 3 26
      scripts/pwman3

+ 26 - 1
pwman/__init__.py

@@ -20,9 +20,34 @@
 #============================================================================
 
 appname = "Pwman3"
-version = "0.4.2"
+version = "0.4.3-dev"
 website = "http://github.com/pwman3/pwman3"
 author = "Oz Nahum"
 authoremail = "nahumoz@gmail.com"
 description = "Pwman -a command line password management application."
 keywords = "password management sqlite crypto"
+import os
+
+
+def which(cmd):
+    _, cmdname = os.path.split(cmd)
+
+    for path in os.environ["PATH"].split(os.pathsep):
+        cmd = os.path.join(path, cmdname)
+        if os.path.isfile(cmd) and os.access(cmd, os.X_OK):
+            return cmd
+
+    return None
+
+config_dir = os.path.expanduser("~/.pwman")
+
+default_config = {'Global': {'umask': '0100', 'colors': 'yes',
+                             'cls_timeout': '5'
+                             },
+                  'Database': {'type': 'SQLite',
+                               'filename': os.path.join(config_dir,
+                                                        "pwman.db")},
+                  'Encryption': {'algorithm': 'AES'},
+                  'Readline': {'history': os.path.join(config_dir,
+                                                       "history")}
+                  }

+ 7 - 21
pwman/tests/db_tests.py

@@ -20,30 +20,16 @@ import pwman.data.factory
 from pwman.data.nodes import NewNode
 from pwman.data.tags import Tag
 from pwman.util.crypto import CryptoEngine
+from pwman import which, default_config
 import unittest
 
-
-def which(cmd):
-    _, cmdname = os.path.split(cmd)
-    for path in os.environ["PATH"].split(os.pathsep):
-        cmd = os.path.join(path, cmdname)
-        if os.path.isfile(cmd) and os.access(cmd, os.X_OK):
-            return cmd
-    return None
-
 _saveconfig = False
-default_config = {'Global': {'umask': '0100', 'colors': 'yes',
-                             'cls_timeout': '5'
-                             },
-                  'Database': {'type': 'SQLite',
-                               'filename':
-                               os.path.join(os.path.dirname(__file__),
-                                            "test.pwman.db")},
-
-                  'Encryption': {'algorithm': 'AES'},
-                  'Readline': {'history': os.path.join("tests",
-                                                       "history")}
-                  }
+
+default_config['Database'] = {'type': 'SQLite',
+                              'filename':
+                              os.path.join(os.path.dirname(__file__),
+                                           "test.pwman.db")
+                              }
 
 
 class SetupTester(object):

+ 3 - 26
scripts/pwman3

@@ -21,11 +21,11 @@
 #============================================================================
 import os
 import os.path
+import argparse
+import sys
 
 _saveconfig = True
 
-import argparse
-
 
 parser = argparse.ArgumentParser(description=('pwman3 - a command line '
                                               'password manager.'))
@@ -50,11 +50,11 @@ without installation", action="store_true")
 
 args = parser.parse_args()
 
-import sys
 if args.test:
     sys.path.insert(0, os.getcwd())
 
 from pwman.util.crypto import CryptoEngine
+from pwman import default_config, which
 
 if 'darwin' in sys.platform:
     from pwman.ui.mac import PwmanCliMac as PwmanCli
@@ -74,34 +74,11 @@ import pwman.util.config as config
 import pwman.data.factory
 from pwman.data.convertdb import PwmanConvertDB
 
-
-def which(cmd):
-    _, cmdname = os.path.split(cmd)
-
-    for path in os.environ["PATH"].split(os.pathsep):
-        cmd = os.path.join(path, cmdname)
-        if os.path.isfile(cmd) and os.access(cmd, os.X_OK):
-            return cmd
-
-    return None
-
 try:
     config_dir = os.path.expanduser("~/.pwman")
     if not os.path.isdir(config_dir):
         os.mkdir(config_dir)
 
-    # 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")},
-                      'Encryption': {'algorithm': 'AES'},
-                      'Readline': {'history': os.path.join(config_dir,
-                                                           "history")}
-                      }
-
     if not os.path.exists(args.cfile):
         config.set_defaults(default_config)
     else: