from jinja2 import Environment, FileSystemLoader
import os
import csv
import subprocess
import concurrent.futures
import time
templatedir= ./tempLate
#
env = Environment(loader=FileSystemLoader(template_dir))
#
csv_file = './input.csv'
#
#template = env.get_template('regression_template.j2')
#
#regression_env = template.render(variables)
#for _, row in df.iterrows():
with open(csv file,'r') as file:
reader = csv.DictReader(file)
variable names = reader.fieldnames
print(variable_names)
render_queue = []
for row in reader:
print(row)
variables = (name: row[name] for name in variable names}
for root, dirs, files in os.walk(template_dir):
for file in'files:
relative_path = os.path.relpath(os.path.join(root, file), template_dir)
template = env.get_template(relative_path)
rendered_content.= template.render(variables)
output_dir = os:path.join('./', variables['platform']+"_"+variables['pattern']+"_"+variables['timeout'])
os.makedirs(output_dir, exist_ok=True)
output file = os.path.join(output dir,relative path)
with open(output_file, 'w') as f:
f.write(rendered content)
if file'= 'Makefile':
makefile_dir = os.path.dirname(output_file)
render_queue.append(makefile_dir)
with concurrent.futures.ThreadPoolExecutor() as executor:
futures = [executor.submit(subprocess.run, ['make'], cwd=makefile_dir, shell=True) for makefile_dir in render_queue]
while any(not future.done() for future in futures):
for makefile_dir in render_queue:
log_file = os.path.join(makefile_dir,'xrun.log')
if os.path.isfile(log_file):
with open(log_file,.'r') as f:
lines = f.readlines()
if lines:
last_line = lines[-l].strip()
print(f"[{makefile_dir}] Last line: {last_line}")
time.sleep(1)
for future in concurrent:futures.as_completed(futures):
try:
future.result() #
except Exception as e:
print(f"An error occurred: {str(e)}")
print("Regression environment configuration file created successfully.")
regression env
最新推荐文章于 2026-06-22 23:38:57 发布
文章描述了如何使用Python和Jinja2模板引擎读取CSV文件中的数据,动态渲染多个模板,并在每个目录下执行Makefile以进行自动化构建的过程。

409

被折叠的 条评论
为什么被折叠?



