Source

Scripts / Utility / removeLineDebuJsFile.py

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

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

if __name__ == "__main__":

    for root, dirs, files in os.walk(os.path.normpath("SOURCE")):
        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"