Source

Scripts / Utility / removeLineDebuJsFile.py

Full commit
# -*- coding: utf-8 -*-
"""
@author: Michele Gatti

Analyze js file, find and remove debug line
"""
import fnmatch
import re
import os
import shutil
import sys

if __name__ == "__main__":
    
    if len(sys.argv) >= 2:
        sourceDir = sys.argv[1]
        print sourceDir
    else:
        sys.exit("Doesn't exist source dir")
    
    for root, dirs, files in os.walk(os.path.normpath(sourceDir)):
        for f in files:
            if fnmatch.fnmatch(f, '*.js'):
                stream = open(os.path.normpath(os.path.join(root, f)), "r")
                testo = stream.read()
                stream.close()
                if len(re.findall(r"(?i)(.*\//DEBUG|.*\// DEBUG)", testo)) > 0:
                    shutil.move(os.path.normpath(os.path.join(root, f)), os.path.normpath(os.path.join(root, f + ".bk")))
                    testo = re.sub(r"(?i)(.*\//DEBUG|.*\// DEBUG)", '', testo)

                    stream = open(os.path.normpath(os.path.join(root, f)), "w")
                    stream.writelines(testo)
                    stream.close()

    print "End"