Commits

Mikele Gatti committed 4c21b4f

Sostitute sys.args with argparse

Comments (0)

Files changed (2)

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
-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"

Utility/removeLineDebugJsFile.py

+# -*- 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"
+