Created
March 9, 2011 02:28
-
-
Save meehow/861574 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import re | |
import os | |
import commands | |
import sys | |
EXT = ('js', 'css') | |
JAR = '~/workspace/yuicompressor-2.4.2.jar' | |
re_ext = re.compile(r'.*\.(%s)$' % '|'.join(EXT), re.I) | |
re_min = re.compile(r'\.min\.') | |
def find_file(basedir): | |
for fname in os.listdir(basedir): | |
string = os.path.join(basedir, fname) | |
if os.path.isdir(string): | |
for s in find_file(string): | |
yield s | |
elif re_ext.match(string) and not re_min.search(string): | |
yield string | |
def inject_min(fname): | |
return re.sub(r'^(.*)\.([^.]+)$', r'\1.min.\2', fname) | |
def main(basedir): | |
for fname in find_file(basedir): | |
fname_min = inject_min(fname) | |
print '%s -> %s' % (fname, fname_min), commands.getoutput('java -jar %s -o %s %s' % (JAR, fname_min,fname)) | |
if __name__ == '__main__': | |
main(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment