diff options
-rw-r--r-- | src/leap/app.py | 2 | ||||
-rw-r--r-- | src/leap/eip/conductor.py | 2 | ||||
-rw-r--r-- | src/leap/util/__init__.py (renamed from src/leap/utils/__init__.py) | 0 | ||||
-rw-r--r-- | src/leap/util/coroutines.py (renamed from src/leap/utils/coroutines.py) | 0 | ||||
-rw-r--r-- | src/leap/util/fileutil.py | 73 | ||||
-rw-r--r-- | src/leap/util/leap_argparse.py (renamed from src/leap/utils/leap_argparse.py) | 0 |
6 files changed, 75 insertions, 2 deletions
diff --git a/src/leap/app.py b/src/leap/app.py index 0a61fd4f..186eb048 100644 --- a/src/leap/app.py +++ b/src/leap/app.py @@ -15,7 +15,7 @@ def main(): long live to the (hidden) leap window! """ import sys - from leap.utils import leap_argparse + from leap.util import leap_argparse parser, opts = leap_argparse.init_leapc_args() debug = getattr(opts, 'debug', False) diff --git a/src/leap/eip/conductor.py b/src/leap/eip/conductor.py index e3adadc4..3ce062aa 100644 --- a/src/leap/eip/conductor.py +++ b/src/leap/eip/conductor.py @@ -6,7 +6,7 @@ from __future__ import (division, unicode_literals, print_function) from functools import partial import logging -from leap.utils.coroutines import spawn_and_watch_process +from leap.util.coroutines import spawn_and_watch_process from leap.baseapp.config import get_config, get_vpn_stdout_mockup from leap.eip.vpnwatcher import EIPConnectionStatus, status_watcher from leap.eip.vpnmanager import OpenVPNManager, ConnectionRefusedError diff --git a/src/leap/utils/__init__.py b/src/leap/util/__init__.py index e69de29b..e69de29b 100644 --- a/src/leap/utils/__init__.py +++ b/src/leap/util/__init__.py diff --git a/src/leap/utils/coroutines.py b/src/leap/util/coroutines.py index 5e25eb63..5e25eb63 100644 --- a/src/leap/utils/coroutines.py +++ b/src/leap/util/coroutines.py diff --git a/src/leap/util/fileutil.py b/src/leap/util/fileutil.py new file mode 100644 index 00000000..86a44a89 --- /dev/null +++ b/src/leap/util/fileutil.py @@ -0,0 +1,73 @@ +from itertools import chain +import os +import platform +import stat + + +def is_user_executable(fpath): + st = os.stat(fpath) + return bool(st.st_mode & stat.S_IXUSR) + + +def extend_path(): + ourplatform = platform.system() + if ourplatform == "Linux": + return "/usr/local/sbin:/usr/sbin" + # XXX add mac / win extended search paths? + + +def which(program): + """ + an implementation of which + that extends the path with + other locations, like sbin + (f.i., openvpn binary is likely to be there) + @param program: a string representing the binary we're looking for. + """ + def is_exe(fpath): + """ + check that path exists, + it's a file, + and is executable by the owner + """ + # we would check for access, + # but it's likely that we're + # using uid 0 + polkitd + + return os.path.isfile(fpath)\ + and is_user_executable(fpath) + + def ext_candidates(fpath): + yield fpath + for ext in os.environ.get("PATHEXT", "").split(os.pathsep): + yield fpath + ext + + def iter_path(pathset): + """ + returns iterator with + full path for a given path list + and the current target bin. + """ + for path in pathset.split(os.pathsep): + exe_file = os.path.join(path, program) + #print 'file=%s' % exe_file + for candidate in ext_candidates(exe_file): + if is_exe(candidate): + yield candidate + + fpath, fname = os.path.split(program) + if fpath: + if is_exe(program): + return program + else: + # extended iterator + # with extra path + extended_path = chain( + iter_path(os.environ["PATH"]), + iter_path(extend_path())) + for candidate in extended_path: + if candidate is not None: + return candidate + + # sorry bro. + return None diff --git a/src/leap/utils/leap_argparse.py b/src/leap/util/leap_argparse.py index 9c355134..9c355134 100644 --- a/src/leap/utils/leap_argparse.py +++ b/src/leap/util/leap_argparse.py |