regression env

文章描述了如何使用Python和Jinja2模板引擎读取CSV文件中的数据,动态渲染多个模板,并在每个目录下执行Makefile以进行自动化构建的过程。
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.")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值