p_minifyJson_one.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # -*- coding: utf-8
  2. import sys
  3. import os
  4. import re
  5. import json
  6. #root_dir_path = "../release/bytedancegame"
  7. root_dir_path = sys.argv[1]
  8. extern_name_list = [".json", ".ExportJson", ".ls", ".lh", ".lmat"]
  9. def removeBlankChar(filepath):
  10. f1 = open(filepath, "rb")
  11. content1 = f1.read()
  12. f1.close()
  13. content2 = re.sub("[*\\t\\n\\r]", "", content1) #"[\\s*\\t\\n\\r]"或"\s" (空格不去掉,以防命名中有空格)
  14. f2 = open(filepath, "wb")
  15. f2.write(content2)
  16. f2.close()
  17. print "remove blank char complete. file: %s" % filepath
  18. # end of removeBlankChar
  19. def removeBlankCharOfDir(dirpath):
  20. filename_list = os.listdir(dirpath)
  21. for filename in filename_list:
  22. filepath = dirpath + "/" + filename
  23. if os.path.isdir(filepath):
  24. removeBlankCharOfDir(filepath)
  25. else:
  26. for extern_name in extern_name_list:
  27. if filepath[-len(extern_name):] == extern_name:
  28. removeBlankChar(filepath)
  29. break
  30. # end of removeBlankCharOfDir
  31. removeBlankCharOfDir(root_dir_path)
  32. print "minifyJson complete"
  33. #raw_input("\n\ndone! ....")
  34. #sys.exit(0)