42 lines
1.2 KiB
Python
Executable File
42 lines
1.2 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import os, re
|
|
|
|
# Define the file paths
|
|
tmpl_file = "./src/http_static.cpp.tmpl"
|
|
out_file = "./src/http_static.cpp"
|
|
static_dir = "./src/static/"
|
|
|
|
def main():
|
|
# Print current working directory and username
|
|
print("Current working directory:", os.getcwd())
|
|
print("Current user:", os.getlogin())
|
|
|
|
# Read template file content
|
|
with open(tmpl_file, 'r') as f:
|
|
body = f.read()
|
|
|
|
# Iterate over placeholder expressions in the template
|
|
for tmpl_import in find_placeholder_expressions(body):
|
|
print("Found expression:", tmpl_import)
|
|
tmpl_filename = tmpl_import[1:-1]
|
|
template_path = os.path.join(static_dir, tmpl_filename)
|
|
|
|
# Read content of the file specified by the placeholder
|
|
with open(template_path, 'r') as f:
|
|
template = f.read()
|
|
|
|
# Replace placeholder with content of the file
|
|
body = body.replace(tmpl_import, template)
|
|
|
|
# Write modified content to the output file
|
|
with open(out_file, 'w') as f:
|
|
f.write(body)
|
|
|
|
def find_placeholder_expressions(body):
|
|
# Find and return placeholder expressions in the body
|
|
return [expr.group() for expr in re.finditer(r"%[^%]*%", body)]
|
|
|
|
if __name__ == "__main__":
|
|
main()
|