我们已经看到 ecFlow 使用一些变量
(variable),比如 ECF_HOME
,ECF_INCLUDE
。
共有三种变量:
ECF_HOME
ECF
开头,推荐使用大写字母来定义变量。ECF_DATE
。之前的例子中,我们复制 t1.ecf
为 t2.ecf
。
编辑这两个文件,以用户定义的变量 SLEEP
为参数调用 unix 的 sleep
命令。
%include <head.h>
echo "I will now sleep for %SLEEP% seconds"
sleep %SLEEP%
%include <tail.h>
添加变量到 suite definition
# Definition of the suite test.
suite test
edit ECF_INCLUDE "$ECF_HOME" # replace '$ECF_HOME' with the path to your ECF_HOME directory
edit ECF_HOME "$ECF_HOME"
family f1
task t1
edit SLEEP 20
task t2
edit SLEEP 20
endfamily
endsuite
import os
from pathlib import Path
from ecflow import Defs, Suite, Task, Family, Edit
def create_family_f1():
return Family(
"f1",
Task("t1", Edit(SLEEP=20)),
Task("t2", Edit(SLEEP=20)))
print("Creating suite definition")
home = os.path.abspath(Path(Path(__file__).parent, "../../../build/course"))
defs = Defs(
Suite('test',
Edit(ECF_INCLUDE=home, ECF_HOME=home),
create_family_f1()))
print(defs)
print("Checking job creation: .ecf -> .job0")
print(defs.check_job_creation())
print("Saving definition to file 'test.def'")
defs.save_as_defs(str(Path(home, "test.def")))
# To restore the definition from file 'test.def' we can use:
# restored_defs = ecflow.Defs("test.def")
运行脚本:
$python test.py
Creating suite definition
# 4.8.0
suite test
edit ECF_INCLUDE '/g3/wangdp/project/study/ecflow/ecflow-tutorial-code/build/course'
edit ECF_HOME '/g3/wangdp/project/study/ecflow/ecflow-tutorial-code/build/course'
family f1
task t1
edit SLEEP '20'
task t2
edit SLEEP '20'
endfamily
endsuite
Checking job creation: .ecf -> .job0
Saving definition to file 'test.def'