summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar enkore <public@enkore.de> 2013-03-26 00:57:37 +0100
committerGravatar enkore <public@enkore.de> 2013-03-26 00:57:37 +0100
commit7628fb554b6b740fc9ce53f78e93ce5254dd6fec (patch)
tree2cc21c4cc4ec6c159d1d604aca7ac1f6647928d2
parentRewrote FourChanOrg crypter (diff)
downloadpyload-7628fb554b6b740fc9ce53f78e93ce5254dd6fec.tar.xz
Add module.utils.which
-rw-r--r--module/utils.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/module/utils.py b/module/utils.py
index 8748b7693..895768cba 100644
--- a/module/utils.py
+++ b/module/utils.py
@@ -195,6 +195,26 @@ def html_unescape(text):
"""Removes HTML or XML character references and entities from a text string"""
return re.sub("&#?\w+;", fixup, text)
+def which(program):
+ """Works exactly like the unix command which
+
+ Courtesy of http://stackoverflow.com/a/377028/675646"""
+ def is_exe(fpath):
+ return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
+
+ fpath, fname = os.path.split(program)
+ if fpath:
+ if is_exe(program):
+ return program
+ 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
+
+ return None
+
if __name__ == "__main__":
print freeSpace(".")