From 484e584f00fce5456778d2d110d3f9b1c3b88097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ozan=20=C3=87a=C4=9Flayan?= Date: Wed, 8 Jun 2011 11:21:36 +0000 Subject: [PATCH] util: add search_executable() to find search for an executable in PATH --- pisi/util.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pisi/util.py b/pisi/util.py index 82cbf6bf..cd324f6c 100644 --- a/pisi/util.py +++ b/pisi/util.py @@ -175,6 +175,14 @@ def format_by_columns(strings, sep_width=2): # Process Releated Functions # ############################## +def search_executable(executable): + """Search for the executable in user's paths and return it.""" + for _path in os.environ["PATH"].split(":"): + full_path = os.path.join(_path, executable) + if os.path.exists(full_path) and os.access(full_path, os.X_OK): + return full_path + return None + def run_batch(cmd): """Run command and report return value and output.""" ctx.ui.info(_('Running ') + cmd, verbose=True)