Преглед на файлове

Move get_ui_platform to pwman/__init__.py

This allows reusing in the test suite, thus we can
remove the same code from the test suite.
oz123 преди 11 години
родител
ревизия
7d0c72c919
променени са 3 файла, в които са добавени 17 реда и са изтрити 24 реда
  1. 14 0
      pwman/__init__.py
  2. 2 9
      pwman/tests/db_tests.py
  3. 1 15
      scripts/pwman3

+ 14 - 0
pwman/__init__.py

@@ -29,6 +29,20 @@ keywords = "password management sqlite crypto"
 import os
 
 
+def get_ui_platform(platform):
+    if 'darwin' in platform:
+        from ui.mac import PwmanCliMacNew as PwmanCliNew
+        OSX = True
+    elif 'win' in platform:
+        from ui.win import PwmanCliWinNew as PwmanCliNew
+        OSX = False
+    else:
+        from ui.cli import PwmanCliNew
+        OSX = False
+
+    return PwmanCliNew, OSX
+
+
 def which(cmd):
     _, cmdname = os.path.split(cmd)
 

+ 2 - 9
pwman/tests/db_tests.py

@@ -50,16 +50,9 @@ class DummyCallback4(Callback):
     def getnewsecret(self, question):
         return u'newsecret'
 
+from pwman import get_ui_platform
 
-if 'darwin' in sys.platform:  # pragma: no cover
-    from pwman.ui.mac import PwmanCliMacNew as PwmanCliNew
-    OSX = True
-elif 'win' in sys.platform:  # pragma: no cover
-    from pwman.ui.win import PwmanCliWinNew as PwmanCliNew
-    OSX = False
-else:
-    from pwman.ui.cli import PwmanCliNew
-    OSX = False
+PwmanCliNew, OSX = get_ui_platform(sys.platform)
 
 import pwman.util.config as config
 import pwman.data.factory

+ 1 - 15
scripts/pwman3

@@ -30,25 +30,11 @@ import pwman.util.config as config
 import pwman.data.factory
 from pwman.data.convertdb import PwmanConvertDB
 from pwman.util.crypto import CryptoEngine
-from pwman import default_config, which
+from pwman import default_config, which, get_ui_platform
 
 _saveconfig = True
 
 
-def get_ui_platform(platform):
-    if 'darwin' in platform:
-        from pwman.ui.mac import PwmanCliMacNew as PwmanCliNew
-        OSX = True
-    elif 'win' in platform:
-        from pwman.ui.win import PwmanCliWinNew as PwmanCliNew
-        OSX = False
-    else:
-        from pwman.ui.cli import PwmanCliNew
-        OSX = False
-
-    return PwmanCliNew, OSX
-
-
 def parser_options():
     parser = argparse.ArgumentParser(description=('pwman3 - a command line '
                                                   'password manager.'))