src/cm/scripts/compressjs.py
author Simon Descarpentries <sid@sopinspace.com>
Wed, 30 Oct 2013 18:08:42 +0100
changeset 556 69503659fe8f
parent 0 40c8f766c9b8
permissions -rwxr-xr-x
[c_selection.js] If safari_mobile, get current selection from a previously created global variable [c_sync.js] ref where the safari_mobile global is used [c_text_view_comments.js] if safari_mobile update selection also on selectionChange event [text_view_comments.html] if safari_mobile store a clone of the current selection on each selectionChange set layout width to 99% to improve display factorize safari mobile detection code

#!/usr/bin/python

import os
from time import time
import re

os.system("rm -rf temp")
os.system("mkdir temp")

timestamp = int(time())
for (prefix, destDir, destFile, containerFile) in [("c_", "../media/js/client/", "c_client-min.js","../../cm/templates/site/text_view_comments.html"),
                                                   ("f_", "../media/js/client/", "f_client-min.js", "../../cm/templates/site/text_view_frame.html")] :
    os.system("rm %s%s"%(destDir, destFile))
    os.system("touch %s%s"%(destDir, destFile))
    
    os.system("find ../media/js/client -name \"%s*.js\" > files"%prefix)
    os.system("find ../media/js/site -name \"%s*.js\" >> files"%prefix)
    
    f = open("files")    
    try:
        for fname in f :
            fullfilename = fname.replace('\n','')
            os.system("java -jar ../../cm/scripts/lib/yuicompressor-2.4.2/build/yuicompressor-2.4.2.jar --preserve-semi " + fullfilename + ">>" + destDir + destFile)
    finally: 
        f.close()
    os.system("rm files")
    
    # change reference to js to add datetimestamp int(time())
    # to prevent browser caching
    print ""
    print "setting timestamp %d in %s, commit the file" %(timestamp,containerFile)
    
    input = open(containerFile).read()
    p = re.compile('%s\?(\d*)"'%destFile)
    new_input = p.sub('%s?%d"' % (destFile,timestamp),input)
    ff = open(containerFile,'w')
    ff.write(new_input)
    ff.close()
    
os.system("rm -rf temp")