Source

Scripts / Utility / removeLineDebugJsFile.py

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

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

if __name__ == "__main__":

    parser = argparse.ArgumentParser(description = 'Process directory')
    parser.add_argument('-dir', help = 'directory to analyze', action = 'store')
    args = parser.parse_args()

    if os.path.exists(args.dir):
        for root, dirs, files in os.walk(os.path.normpath(args.dir)):
            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()
    else:
        print "Path is not exist"

    print "End"