Advertisement
PikalaxALT

split_base_stats.py

Jan 10th, 2016
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. from sys import argv
  2.  
  3. def split_base_stats(file):
  4.     lines = open(file).readlines()
  5.     filename = None
  6.     start_line = 0
  7.     for id, line in enumerate(lines):
  8.         if "BaseData::" in line:
  9.             if filename:
  10.                 open(filename, "w+").write("".join(lines[start_line:(id-1)]))
  11.             filename = "data/base_stats/" + line.split("BaseData")[0].lower() + ".asm"
  12.             start_line = id + 1
  13.     open(filename, "w+").write("".join(lines[start_line:-1]))
  14.  
  15. def repl_with_includes(file):
  16.     lines = open(file).readlines()
  17.     building_file = []
  18.     for line in lines:
  19.         if "BaseData" in line:
  20.             building_file.append(line)
  21.             if "BaseData::" in line:
  22.                 filename = "data/base_stats/" + line.split("BaseData")[0].lower() + ".asm"
  23.                 building_file.append("INCLUDE \"" + filename + "\"\n\n")
  24.     open(file, "w+").write("".join(building_file))
  25.  
  26. if __name__ == "__main__":
  27.     if argv[1] == "split":
  28.         split_base_stats(argv[2])
  29.     elif argv[1] == "include":
  30.         repl_with_includes(argv[2])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement