2023-05-27 18:52:13 +07:00
|
|
|
import re
|
|
|
|
|
|
|
|
|
|
|
|
def read_config(filename):
|
2023-07-09 16:31:47 +07:00
|
|
|
with open(filename, "r") as f:
|
|
|
|
return "".join(f.readlines())
|
2023-05-27 18:52:13 +07:00
|
|
|
|
|
|
|
|
|
|
|
def replacetext(src_file, dest_file, search_text, replace_text):
|
2023-07-09 16:31:47 +07:00
|
|
|
with open(src_file, "r+") as src:
|
2023-05-27 18:52:13 +07:00
|
|
|
src_file = src.read() # Read
|
|
|
|
src.close()
|
2023-07-09 16:31:47 +07:00
|
|
|
with open(dest_file, "w") as dest:
|
2023-05-27 18:52:13 +07:00
|
|
|
dest_file = re.sub(search_text, replace_text, src_file) # Replace
|
|
|
|
dest.seek(0) # Setting the position to the top of the page to insert data
|
|
|
|
dest.write(dest_file) # Write
|
|
|
|
|
|
|
|
dest.close()
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2023-07-09 16:31:47 +07:00
|
|
|
search_text = "<!-- TEXT REPLACE -->"
|
|
|
|
replace_text = read_config("example.dae")
|
2023-05-27 18:52:13 +07:00
|
|
|
|
|
|
|
replacetext(
|
2023-07-09 16:31:47 +07:00
|
|
|
"hack/templates/example-config.md",
|
|
|
|
"hack/sync/example-config.md",
|
2023-05-27 18:52:13 +07:00
|
|
|
search_text,
|
|
|
|
replace_text,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-07-09 16:31:47 +07:00
|
|
|
if __name__ == "__main__":
|
2023-05-27 18:52:13 +07:00
|
|
|
main()
|