summaryrefslogtreecommitdiff
path: root/compressor/utils/__init__.py
diff options
context:
space:
mode:
authorJannis Leidel <jannis@leidel.info>2011-04-18 11:24:57 +0200
committerJannis Leidel <jannis@leidel.info>2011-04-18 11:25:09 +0200
commit9267bb6f2e39c9242604ee44482869b49dfb31bb (patch)
treec48c4c4d2335fe57b52a1c5e04a92e872df336a0 /compressor/utils/__init__.py
parent1f68326b879b9743412daf5280f5e2cab2dcab07 (diff)
downloaddjango-compressor-9267bb6f2e39c9242604ee44482869b49dfb31bb.tar.gz
Stop overwriting the CompileFilter's options attribute in the __init__ method. Added optional test for the CSSTidy filter. Fixes issue #33.
Diffstat (limited to 'compressor/utils/__init__.py')
-rw-r--r--compressor/utils/__init__.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/compressor/utils/__init__.py b/compressor/utils/__init__.py
index 2c13265..699e37d 100644
--- a/compressor/utils/__init__.py
+++ b/compressor/utils/__init__.py
@@ -57,3 +57,32 @@ def walk(root, topdown=True, onerror=None, followlinks=False):
if os.path.islink(p):
for link_dirpath, link_dirnames, link_filenames in walk(p):
yield (link_dirpath, link_dirnames, link_filenames)
+
+
+def find_command(cmd, paths=None, pathext=None):
+ """
+ Searches the PATH for the given command and returns its path
+ """
+ if paths is None:
+ paths = os.environ.get('PATH', []).split(os.pathsep)
+ if isinstance(paths, basestring):
+ paths = [paths]
+ # check if there are funny path extensions for executables, e.g. Windows
+ if pathext is None:
+ pathext = os.environ.get('PATHEXT', '.COM;.EXE;.BAT;.CMD')
+ pathext = [ext for ext in pathext.lower().split(os.pathsep)]
+ # don't use extensions if the command ends with one of them
+ if os.path.splitext(cmd)[1].lower() in pathext:
+ pathext = ['']
+ # check if we find the command on PATH
+ for path in paths:
+ # try without extension first
+ cmd_path = os.path.join(path, cmd)
+ for ext in pathext:
+ # then including the extension
+ cmd_path_ext = cmd_path + ext
+ if os.path.isfile(cmd_path_ext):
+ return cmd_path_ext
+ if os.path.isfile(cmd_path):
+ return cmd_path
+ return None