diff options
author | Руслан Ижбулатов <lrn1986@gmail.com> | 2014-02-21 11:16:35 +0000 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2014-02-22 18:21:03 -0500 |
commit | c82933bb6622eb816d87c2a1b2ab0ba273ee419c (patch) | |
tree | 9259b6b9dc55c74eb620590221c217b560eb89fc /giscanner/utils.py | |
parent | 798712445a121ec409da67b10aff3fcc99698aec (diff) | |
download | gobject-introspection-c82933bb6622eb816d87c2a1b2ab0ba273ee419c.tar.gz |
scanner: Support running under MSYS
https://bugzilla.gnome.org/show_bug.cgi?id=724880
Diffstat (limited to 'giscanner/utils.py')
-rw-r--r-- | giscanner/utils.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/giscanner/utils.py b/giscanner/utils.py index c0d49d26..b1fdcb46 100644 --- a/giscanner/utils.py +++ b/giscanner/utils.py @@ -182,3 +182,27 @@ def cflag_real_include_path(cflag): return cflag return "-I" + os.path.realpath(cflag[2:]) + +def which(program): + def is_exe(fpath): + return os.path.isfile(fpath) and os.access(fpath, os.X_OK) + + def is_nt_exe(fpath): + return not fpath.lower().endswith('.exe') and os.path.isfile(fpath + '.exe') and os.access(fpath + '.exe', os.X_OK) + + fpath, fname = os.path.split(program) + if fpath: + if is_exe(program): + return program + if os.name == 'nt' and is_nt_exe(program): + return program + '.exe' + else: + for path in os.environ["PATH"].split(os.pathsep): + path = path.strip('"') + exe_file = os.path.join(path, program) + if is_exe(exe_file): + return exe_file + if os.name == 'nt' and is_nt_exe(exe_file): + return exe_file + '.exe' + + return None |