<div class="section" id="indentation">
<span id="index-0"></span><span id="id1"></span>
<p>The text examples allow indentation. In python indentation
effectsaffects 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> <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="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>
<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>
<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>
<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>
<span 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>
<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">"f2"</span><span class="p">)</span> <span class="k">as</span> <span class="n">f2</span><span class="p">:</span>
<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>
<span class="n">f2</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_time</span><span class="p">(</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="bp">True</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">"t5"</span><span class="p">)</span><span class="o">.</span><span class="n">add_time</span><span class="p">(</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span> <span class="p">)</span>
<span class="k">print</span> <span class="n">defs</span>
<span class="k">print</span> <span class="s">"Checking job creation: .ecf -> .job0"</span>
<span class="k">print</span> <span class="n">defs</span><span class="o">.</span><span class="n">check_job_creation</span><span class="p">()</span>
<span class="k">print</span> <span class="s">"Saving definition to file 'test.def'"</span>
<span class="n">defs</span><span class="o">.</span><span class="n">save_as_defs</span><span class="p">(</span><span class="s">"test.def"</span><span class="p">)</span>
</pre></div>
</div>
</div>
|