#!/usr/bin/env python3 import re import sys def main(filename): root = "/".join(filename.split("/")[:-1]) with open(filename, "r") as f: lines = f.readlines() i = 0 while i < len(lines): line = lines[i] if line.lower().startswith("source"): included_file = re.sub(r"\s+", " ", line).strip().split("source ")[1] included_file = re.sub(r"""['"]""", "", included_file.strip()) with open(f"{root}/{included_file}", "r") as f: lines = lines[:i] + f.readlines() + lines[i + 1 :] i += 1 print("".join(lines)) if __name__ == "__main__": main(sys.argv[1])