Loading

Paste #pqtj3a8d2

  1. #!/usr/bin/env python
  2.  
  3. import re, sys
  4.  
  5. PAT_STR = re.compile("(STR_[^ ]*) *:(.*)")
  6.  
  7. files = sys.argv[1:]
  8.  
  9. for f in files:
  10.     railway = None
  11.     lines = []
  12.     for l in open(f):
  13.         l = l.strip()
  14.         lines.append(l)
  15.         m = PAT_STR.match(l)
  16.         if m and m.group(1) == "STR_RAIL_NAME_RAILROAD":
  17.             railway = m.group(2)
  18.  
  19.     if railway:
  20.         with open(f, "w") as o:
  21.             for l in lines:
  22.                 m = PAT_STR.match(l)
  23.                 if m and (m.group(1).startswith("STR_LAI_RAIL_DESCRIPTION_TRACK") or m.group(1) == "STR_LAI_RAIL_DESCRIPTION_TRAIN_DEPOT"):
  24.                     l = l.replace("{STRING}", railway)
  25.                     l = l.replace("{STRING.gen}", railway)
  26.                     l = l.replace("{STRING.n}", railway)
  27.                     l = l.replace("{STRING.ms}", railway)
  28.                 o.write(l + "\n")
  29.  
  30.  

Comments