1import argparse 2import os 3import os.path 4 5 6def main() -> None: 7 parser = argparse.ArgumentParser() 8 parser.add_argument("--input-file") 9 parser.add_argument("--output-file") 10 parser.add_argument("--install-dir", "--install_dir") 11 parser.add_argument("--replace", action="append", nargs=2) 12 options = parser.parse_args() 13 14 with open(options.input_file) as f: 15 contents = f.read() 16 17 output_file = os.path.join(options.install_dir, options.output_file) 18 os.makedirs(os.path.dirname(output_file), exist_ok=True) 19 20 for old, new in options.replace: 21 contents = contents.replace(old, new) 22 23 with open(output_file, "w") as f: 24 f.write(contents) 25 26 27if __name__ == "__main__": 28 main() # pragma: no cover 29