Ver Fonte

Remove own which and use stdlib's which

 Issue #48
Oz N Tiram há 8 anos atrás
pai
commit
2585dcffaa
3 ficheiros alterados com 8 adições e 16 exclusões
  1. 3 12
      pwman/__init__.py
  2. 2 2
      tests/test_complete_ui.py
  3. 3 2
      tests/test_tools.py

+ 3 - 12
pwman/__init__.py

@@ -24,6 +24,7 @@ import os
 import pkg_resources
 import re
 import string
+import shutil
 import sys
 from pwman.util import config
 from pwman.data.factory import check_db_version
@@ -68,16 +69,6 @@ except IOError as E:
     website = 'http://pwman3.github.io/pwman3/'
 
 
-def which(cmd):  # pragma: no cover
-    _, 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):  # pragma: no cover
-            return cmd
-    return ''
-
-
 config_dir = os.path.expanduser("~/.pwman")
 
 
@@ -106,10 +97,10 @@ def get_conf(args):
 
 def set_xsel(configp, OSX):
     if not OSX:
-        xselpath = which("xsel")
+        xselpath = shutil.which("xsel")
         configp.set_value("Global", "xsel", xselpath)
     elif OSX:
-        pbcopypath = which("pbcopy")
+        pbcopypath = shutil.which("pbcopy")
         configp.set_value("Global", "xsel", pbcopypath)
 
 

+ 2 - 2
tests/test_complete_ui.py

@@ -20,9 +20,9 @@
 from __future__ import print_function
 import pexpect
 import unittest
+import shutil
 import sys
 import os
-from pwman import which
 
 class Ferrum(unittest.TestCase):
     def clean_files(self):
@@ -60,7 +60,7 @@ class Ferrum(unittest.TestCase):
     def test_c_change_pass(self):
         lfile = 'test-chg_passwd.log'
         logfile = open(lfile, 'wb')
-        cmd = which('pwman3')
+        cmd = shutil.which('pwman3')
         db = 'sqlite://' + os.path.join(os.path.dirname(__file__), 'foo.baz.db')
         child = pexpect.spawn(cmd + ' -d ' + db, logfile=logfile)
         if sys.version_info[0] > 2:

+ 3 - 2
tests/test_tools.py

@@ -1,6 +1,8 @@
 import os
 import os.path
+import shutil
 import sys
+
 if sys.version_info.major > 2:  # pragma: no cover
     from urllib.parse import urlparse
 else:
@@ -8,7 +10,6 @@ else:
 
 from pwman.data import factory
 from pwman.util import config
-from pwman import which
 from pwman.util.callback import Callback
 
 
@@ -105,7 +106,7 @@ class SetupTester(object):
                                )
 
         if not OSX:
-            self.xselpath = which("xsel")
+            self.xselpath = shutil.which("xsel")
             self.configp.set_value("Global", "xsel", self.xselpath)
         else:
             self.xselpath = "xsel"