<div class="section" id="indentation">
<span id="index-0"></span><span id="id1"></span>
<p>The text examples allow indentation. In python indentation
effects 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="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> Edit(ECF_INCLUDE=home,ECF_HOME=home),
<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",
Edit(SLEEP=20),
Task("t1", Meter("progress", 1, 100, 90)),
<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=Task("kt2">as</span> <span class="n">f1</span><span class="p">:</span>
, Trigger("t1 == complete"),Event("a"),Event("b")),
<span class=Task("nt3">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>, Trigger("t2:a")),
Task("t4", Trigger("t2 == complete"), Complete("t2: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("t5", Trigger("t1:progress ge 30")),
Task("t6", Trigger("t1:progress ge 60")),
Task("t7", Trigger("t1:progress ge 90"))),
Family("f2",
Edit(SLEEP=20),
<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>
<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>
<span class="n">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> Task("t1", Time( "00:30 23:30 00:30" )),
Task("t2", Day( "sunday" )),
Task("t3", Date("1.*.*"), Time("12:00")),
Task("t4", Time("+00:02")),
Task("t5", 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") |