Horizontal Navigation Bar | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
The text examples allow indentation. In python, indentation affects the logical meaning of the program.
However, as we have seen we can use the Node constructor to provide indentation, to show the definition structure.
Code Block | ||||
---|---|---|---|---|
| ||||
import os
from ecflow import Defs,Suite,Family,Task,Edit,Trigger,Complete,Event,Meter,Time,Day,Date
print("Creating suite definition")
home = os.path.join(os.getenv("HOME"), "course")
defs = Defs(
Suite("test",
Edit(ECF_INCLUDE=home,ECF_HOME=home), | ||||
HTML | ||||
<div class="section" id="indentation"> <span id="index-0"></span><span id="id1"></span> <p>The text examples allow indentation. In python indentation affects the logical meaning of the program.</p> <p>However we can use python <strong>with</strong> statement to provide the indentation.</p> <p>Here is the previous example using the <strong>with</strong> statement:</p> <div class="highlight-python"><div class="highlight"><pre><span class="c">#!/usr/bin/env python2.7</span> <span class="kn">import</span> <span class="nn">os</span> <span class="kn">import</span> <span class="nn">ecflow</span> <span class="kn">import</span> <span class="nn">sys</span> <span class="n">version</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">version_info</span><span class="p">;</span> <span class="k">if</span> <span class="n">version</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o"><</span> <span class="mi">7</span> <span class="p">:</span> <span class="k">print</span> <span class="s">"This example requires python version 2.7, but found : "</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">version</span><span class="p">)</span> <span class="nb">exit</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> <span class="k">print</span> <span class="s">"Creating suite definition"</span> <span class="k">with</span> <span class="n">ecflow</span><span class="o">.</span><span class="n">Defs</span><span class="p">()</span> <span class="k">as</span> <span class="n">defs</span><span class="p">:</span> <span class="k">with</span> <span class="n">defs</span><span class="o">.</span><span class="n">add_suite</span><span class="p">(</span><span class="s">"test"</span><span class="p">)</span> <span class="k">as</span> <span class="n">suite</span><span class="p">:</span> <span class="n">suite</span><span class="o">.</span><span class="n">add_variable</span><span class="p">(</span><span class="s">"ECF_INCLUDE"</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">getenv</span><span class="p">(</span><span class="s">"HOME"</span><span class="p">)</span> <span class="o">+</span> <span class="s">"/course"</span><span class="p">)</span> <span class="n">suite</span><span class="o">.</span><span class="n">add_variable</span><span class="p">(</span><span class="s">"ECF_HOME"</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">getenv</span><span class="p">(</span><span class="s">"HOME"</span><span class="p">)</span> <span class="o">+</span> <span class="s">"/course"</span><span class="p">)</span> Family("f1", <span class="k">with</span> <span class="n">suite</span><span class="o">.</span><span class="n">add_family</span><span class="p">(</span><span class="s">"f1"</span><span class="p">)</span> <span class="k">as</span> <span class="n">f1</span><span class="p">:</span> Edit(SLEEP=20), Task("t1", Meter("progress", 1, 100, 90)), <span class="n">f1</span><span class="o">.</span><span class="n">add_variable</span><span class="p">(</span><span class="s">"SLEEP"</span><span class="p">,</span> <span class="mi">20</span><span class="p">)</span> Task("t2", Trigger("t1 == complete"),Event("a"),Event("b")), <span class="n">f1</span><span class="o">.</span><span class="n">add_task</span><span class="p">(</span><span class="s">"t1"</span><span class="p">)</span><span class="o">.</span><span class="n">add_meter</span><span class="p">(</span><span class="s">"progress"</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">100</span><span class="p">,</span> <span class="mi">90</span><span class="p">)</span> Task("t3", Trigger("t2:a")), Task("t4", Trigger("t2 == complete"), Complete("t2:b")), Task("t5", Trigger("t1:progress ge 30")), Task("t6", Trigger("t1:progress ge 60")), <span class="n">f1</span><span class="o">.</span><span class="n">add_task</span><span class="p">(</span><span class="s">"t2"</span><span class="p">)</span><span class="o">.</span><span class="n">add_trigger</span><span class="p">(</span><span class="s">"t1 eq complete"</span><span class="p">)</span><span class="o">.</span><span class="n">add_event</span><span class="p">(</span><span class="s">"a"</span><span class="p">)</span><span class="o">.</span><span class="n">add_event</span><span class="p">(</span><span class="s">"b"</span><span class="p">)</span> Task("t7", Trigger("t1:progress ge 90"))), Family("f2", Edit(SLEEP=20), Task("t1", Time( "00:30 23:30 00:30" )), Task("t2", Day( "sunday" )), <span class="n">f1</span><span class="o">.</span><span class="n">add_task</span><span class="p">(</span><span class="s">"t3"</span><span class="p">)</span><span class="o">.</span><span class="n">add_trigger</span><span class="p">(</span><span class="s">"t2:a"</span><span class="p">)</span> Task("t3", Date("1.*.*"), Time("12:00")), Task("t4", Time("+00:02")), <span class=Task("nt5">f1</span><span class="o">.</span><span class="n">add_task</span><span class="p">(</span><span class="s">"t4"</span><span class="p">)</span><span class="o">.</span><span class="n">add_trigger</span><span class="p">(</span><span class="s">"t2 eq complete"</span><span class="p">)</span><span class="o">.</span><span class="n">add_complete</span><span class="p">(</span><span class="s">"t2:b"</span><span class="p">)</span> , Time("00:02"))))) print(defs) print("Checking job creation: .ecf -> .job0") print(defs.check_job_creation()) print("Checking trigger expressions") assert len(defs.check()) == 0, defs.check() print("Saving definition to file 'test.def'") defs.save_as_defs("test.def") |
We can also use python with statement to provide the indentation.
Here is the previous example using the with statement:
Code Block | ||||
---|---|---|---|---|
| ||||
from ecflow import Defs,Suite,Family,Task,Edit,Trigger,Complete,Event,Meter,Time,Day,Date import os import sys print("Creating suite definition") with Defs() as defs: with defs.add_suite("test") as suite: suite += Edit(ECF_HOME=os.path.join(os.getenv("HOME"), "course")) <spansuite class="n">f1</span><span class="o">.</span><span class="n">add_task</span><span class="p">(</span><span class="s">"t5"</span><span class="p">)</span><span class="o">.</span><span class="n">add_trigger</span><span class="p">(</span><span class="s">"t1:progress ge 30"</span><span class="p">)</span> <span class="n">f1</span><span class="o">.</span><span class="n">add_task</span><span class="p">(</span><span class="s">"t6"</span><span class="p">)</span><span class="o">.</span><span class="n">add_trigger</span><span class="p">(</span><span class="s">"t1:progress ge 60"</span><span class="p">)</span> <span class="n">f1</span><span class="o">.</span><span class="n">add_task</span><span class="p">(</span><span class="s">"t7"</span><span class="p">)</span><span class="o">.</span><span class="n">add_trigger</span><span class="p">(</span><span class="s">"t1:progress ge 90"</span><span class="p">)</span> += Edit(ECF_INCLUDE =os.path.join(os.getenv("HOME"), "course")) with suite.add_family("f1") as f1: f1 += Edit(SLEEP=20) f1 += Task("t1", Meter("progress", 1, 100, 90)) f1 += Task("t2", Trigger("t1 == complete"), Event("a"), Event("b")) f1 += Task("t3", Trigger("t2:a")) f1 += Task("t4", Trigger("t2 == complete"), Complete("t2:b")) f1 += Task("t5", Trigger("t1:progress ge 30")) f1 += Task("t6", Trigger("t1:progress ge 60")) f1 += Task("t7", Trigger("t1:progress ge 90")) with suite.add_family("f2") as f2: f2 += Edit(SLEEP=20) <spanf2 class+="k">with</span> <span class="n">suite</span><span class="o">.</span><span class="n">add_family</span><span class="p">(</span><span class="s">"f2"</span><span class="p">)</span> <span class="k">as</span> <span class="n">f2</span><span class="p">:</span> Task("t1", Time("00:30 23:30 00:30")) f2 += Task("t2", Day("sunday")) f2 += Task("t3", Date(1, 0, 0), Time(12, 0)) f2 += Task("t4", Time(0, 2, True)) f2 += Task("t5", Time(0, 2)) <span class="n">f2</span><span class="o">.</span><span class="n">add_variable</span><span class="p">(</span><span class="s">"SLEEP"</span><span class="p">,</span> <span class="mi">20</span><span class="p">)</span> <span class="n">f2</span><span class="o">.</span><span class="n">add_task</span><span class="p">(</span><span class="s">"t1"</span><span class="p">)</span><span class="o">.</span><span class="n">add_time</span><span class="p">(</span> <span class="s">"00:30 23:30 00:30"</span> <span class="p">)</span> <span class="n">f2</span><span class="o">.</span><span class="n">add_task</span><span class="p">(</span><span class="s">"t2"</span><span class="p">)</span><span class="o">.</span><span class="n">add_day</span><span class="p">(</span> <span class="s">"sunday"</span> <span class="p">)</span> <span class="n">f2</span><span class="o">.</span><span class="n">add_task</span><span class="p">(</span><span class="s">"t3"</span><span class="p">)</span><span class="o">.</span><span class="n">add_date</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span><span class="o">.</span><span class="n">add_time</span><span class="p">(</span> <span class="mi">12</span><span class="p">,</span> <span class="mi">0</span> <span class="p">)</span> print(defs) print("Checking job creation: .ecf -> .job0") print(defs.check_job_creation()) print("Checking trigger expressions") assert len(defs.check()) == 0, defs.check() print("Saving definition to file 'test.def'") defs.save_as_defs("test.def") |
Horizontal Navigation Bar | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Alternative styles:
|
...
|
...
|
...
|
...
|
...
|
...
|
...
|
...
|
...
|
...
|
...
|
...
|