From: Frank Brehm Date: Thu, 23 Mar 2017 16:43:50 +0000 (+0100) Subject: Adding function caller_search_path() to pp_lib/common.py X-Git-Tag: 0.1.2~223 X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=98abbd2822c02c58584b188dbad81bce899a2b05;p=pixelpark%2Fadmin-tools.git Adding function caller_search_path() to pp_lib/common.py --- diff --git a/pp_lib/common.py b/pp_lib/common.py index 370d3e7..fa02403 100644 --- a/pp_lib/common.py +++ b/pp_lib/common.py @@ -21,7 +21,7 @@ import six # Own modules -__version__ = '0.3.1' +__version__ = '0.4.1' LOG = logging.getLogger(__name__) @@ -236,6 +236,57 @@ def to_str(obj, encoding='utf-8'): return to_unicode(obj, encoding) +# ============================================================================= +def caller_search_path(): + """ + Builds a search path for executables from environment $PATH + including some standard paths. + + @return: all existing search paths + @rtype: list + """ + + path_list = [] + search_path = os.environ['PATH'] + if not search_path: + search_path = os.defpath + + search_path_list = [ + '/opt/PPlocal/bin', + ] + + for d in search_path.split(os.pathsep): + search_path_list.append(d) + + default_path = [ + '/bin', + '/usr/bin', + '/usr/local/bin', + '/sbin', + '/usr/sbin', + '/usr/local/sbin', + '/usr/ucb', + '/usr/sfw/bin', + '/opt/csw/bin', + '/usr/openwin/bin', + '/usr/ccs/bin', + ] + + for d in default_path: + search_path_list.append(d) + + for d in search_path_list: + if not os.path.exists(d): + continue + if not os.path.isdir(d): + continue + d_abs = os.path.realpath(d) + if d_abs not in path_list: + path_list.append(d_abs) + + return path_list + + # ============================================================================= if __name__ == "__main__":