<style type="text/css
<div class="section" id="using-python-scripting">
.highlight .hll { background-color: #ffffcc }
.highlight { background: #eeffcc; }
.highlight .c { color: #408090; font-style: italic } /* Comment */
.highlight .err { border: 1px solid #FF0000 } /* Error */
.highlight .k { color: #007020; font-weight: bold } /* Keyword */
.highlight .o { color: #666666 } /* Operator */
.highlight .cm { color: #408090; font-style: italic } /* Comment.Multiline */
.highlight .cp { color: #007020 } /* Comment.Preproc */
.highlight .c1 { color: #408090; font-style: italic } /* Comment.Single */
.highlight .cs { color: #408090; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #A00000 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #FF0000 } /* Generic.Error */
.highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */
.highlight .gi { color: #00A000 } /* Generic.Inserted */
.highlight .go { color: #303030 } /* Generic.Output */
.highlight .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
.highlight .gt { color: #0040D0 } /* Generic.Traceback */
.highlight .kc { color: #007020; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #007020; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #007020; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #007020 } /* Keyword.Pseudo */
.highlight .kr { color: #007020; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #902000 } /* Keyword.Type */
.highlight .m { color: #208050 } /* Literal.Number */
.highlight .s { color: #4070a0 } /* Literal.String */
.highlight .na { color: #4070a0 } /* Name.Attribute */
.highlight .nb { color: #007020 } /* Name.Builtin */
.highlight .nc { color: #0e84b5; font-weight: bold } /* Name.Class */
.highlight .no { color: #60add5 } /* Name.Constant */
.highlight .nd { color: #555555; font-weight: bold } /* Name.Decorator */
.highlight .ni { color: #d55537; font-weight: bold } /* Name.Entity */
.highlight .ne { color: #007020 } /* Name.Exception */
.highlight .nf { color: #06287e } /* Name.Function */
.highlight .nl { color: #002070; font-weight: bold } /* Name.Label */
.highlight .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */
.highlight .nt { color: #062873; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #bb60d5 } /* Name.Variable */
.highlight .ow { color: #007020; font-weight: bold } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mf { color: #208050 } /* Literal.Number.Float */
.highlight .mh { color: #208050 } /* Literal.Number.Hex */
.highlight .mi { color: #208050 } /* Literal.Number.Integer */
.highlight .mo { color: #208050 } /* Literal.Number.Oct */
.highlight .sb { color: #4070a0 } /* Literal.String.Backtick */
.highlight .sc { color: #4070a0 } /* Literal.String.Char */
.highlight .sd { color: #4070a0; font-style: italic } /* Literal.String.Doc */
.highlight .s2 { color: #4070a0 } /* Literal.String.Double */
.highlight .se { color: #4070a0; font-weight: bold } /* Literal.String.Escape */
.highlight .sh { color: #4070a0 } /* Literal.String.Heredoc */
.highlight .si { color: #70a0d0; font-style: italic } /* Literal.String.Interpol */
.highlight .sx { color: #c65d09 } /* Literal.String.Other */
.highlight .sr { color: #235388 } /* Literal.String.Regex */
.highlight .s1 { color: #4070a0 } /* Literal.String.Single */
.highlight .ss { color: #517918 } /* Literal.String.Symbol */
.highlight .bp { color: #007020 } /* Name.Builtin.Pseudo */
.highlight .vc { color: #bb60d5 } /* Name.Variable.Class */
.highlight .vg { color: #bb60d5 } /* Name.Variable.Global */
.highlight .vi { color: #bb60d5 } /* Name.Variable.Instance */
.highlight .il { color: #208050 } /* Literal.Number.Integer.Long */
</style>
<div class="section" id="using-python-scripting">
<span id="index-0"></span><span id="id1"></span>
<p>As you have already seen, ecFlow has a <a class="reference internal" href="/wiki/display/ECFLOW/ecFlow+Python+Api#python-api"><em>ecFlow Python Api</em></a>:</p>
<div class="highlight-python"><div class="highlight"<span id="index-0"></span><span id="id1"></span>
<p>As you have already seen, ecFlow has a <a class="reference internal" href="/wiki/display/ECFLOW/ecFlow+Python+Api#python-api"><em>ecFlow Python Api</em></a>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c">#!/usr/bin/env python2.5<7</span>
<span class="kn">import</span> <span class="nn">ecflow</span>
</pre></div>
</div>
<div class="line-block">
<div class="line">This allows the <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-suite-definition"><em class="xref std std-term">suite definition</em></a> to be built with python.</div>
<div class="line">It also allows communication with the <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-ecfecflow-server"><em class="xref std std-term">ecf>ecflow_server</em></a>.</div>
</div>
<div class="line-block">
<div class="line">This is a very powerful feature, that helps to define very complex suites in a relatively compact way.</div>
<div class="line">Consider the following <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-suite"><em class="xref std std-term">suite</em></a></div>
</div>
<div class="highlight-python"><pre>suite test
family f1
task a
task b
task c
task d
task e
endfamily
family f2
task a
task b
task c
task d
task e
endfamily
family f3
task a
task b
task c
task d
task e
endfamily
family f4
task a
task b
task c
task d
task e
endfamily
family f5f3
task a
task b
task c
task d
task e
endfamily
family f6f4
task a
task b
task c
task d
task e
endfamily
endsuite</pre>
</div>
<p>This can be written in python as:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">create_suite</span><span class="p">(</span><span class="n">name</span><span class="p">)</span> <span class="p">:</span> family f5
task a
task b
task c
<span class="n">suite</span> <span class="o">=</span> <span class="n">ecflow</span><span class="o">.</span><span class="n">Suite</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">7</span><span class="p">)</span> <span class="p">:</span> task d
task e
endfamily
family f6
task a
task b
task c
task d
<span class="n">fam</span> <span class="o">=</span> <span class="n">suite</span><span class="o">.</span><span class="n">add_family</span><span class="p">(</span><span class="s">"f"</span> <span class="o">+< task e
endfamily
endsuite</pre>
</div>
<p>This can be written in python as:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nbnf">str<>create_suite</span><span class="p">(</span><span class="n">i<>name</span><span class="p">))</span>
<span class="kp">for<>:</span> <span class="n">t</span> <span class="ow">in</span>
<span class="pn">(<>suite</span> <span class="so">"a"</span><span class="p">,</span> <span class="s">"b"<n">ecflow</span><span class="po">,.</span> <spanspan><span class="s">"c"<n">Suite</span><span class="p">,(</span>span><span <span class="s">"d"<n">name</span><span class="p">,)</span>
<span class="s">"e"<k">for</span> <span class="pn">)<>i</span> <span class="pow">:<>in</span>
<span class="nnb">fam<>range</span><span class="op">.(</span><span class="nmi">add_task<>1</span><span class="p">(,</span><spanspan> <span class="nmi">t<>7</span><span class="p">);</span>
<span class="kp">return<>:</span>
<span class="n">suite<>fam</span>
</pre></div>
</div>
<div<span class="line-blocko">
<div=</span> <span class="line">Python variables can be used to generate <a n">suite</span><span class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-trigger"><emo">.</span><span class="n">add_family</span><span class="xref std std-term">trigger</em></a> <ap">(</span><span class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-dependencies"><em class="xref std std-term">dependencies</em></a>.</div>
<div class="line">Imagine that we want to chain the families f1 to f6, so that f2 runs after f1, f3 after f2 and so on.</div>
<div class="line">The following will do the trick:</div>
</div>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def<s">"f"</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">))</span>
<span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="p">(</span> <span class="s">"a"</span><span class="p">,</span> <span class="s">"b"</span><span class="p">,</span> <span class="nf">create_seqeuntial_suite<s">"c"</span><span class="p">(,</span><spanspan> <span class="n">name<s">"d"</span><span class="p">),</span> <span class="ps">:"e"</span>
<span class="np">suite<>)</span> <span class="op">=:</span>
<span class="n">ecflow<>fam</span><span class="o">.</span><span class="n">Suite<>add_task</span><span class="p">(</span><span class="n">name<>t</span><span class="p">)</span>
<span class="k">for</span> <span</span>
<span class="k">return</span> <span class="n">suite</span>
</pre></div>
</div>
<div class="line-block">
<div class="n">i</span> <span class="ow">in</span> <spanline">Python variables can be used to generate <a class="nb">range</span><span class="p">(</span><spanreference internal" href="/wiki/display/ECFLOW/Glossary#term-trigger"><em class="mi">1</span><spanxref std std-term">trigger</em></a> <a class="p">,</span><span class="mi">7</span><spanreference internal" href="/wiki/display/ECFLOW/Glossary#term-dependencies"><em class="p">)</span> <span xref std std-term">dependencies</em></a>.</div>
<div class="p">:</span>
<span class="n">fam</span> <span class="o">=</span> <span class="n">suite</span><span class="o">.</span><span class="n">add_family</span><span class="p">(</span><span class="s">"f"</span> <span class="o">+<line">Imagine that we want to chain the families f1 to f6, so that f2 runs after f1, f3 after f2 and so on.</div>
<div class="line">The following will do the trick:</div>
</div>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nb">str<nf">create_seqeuntial_suite</span><span class="p">(</span><span class="n">i<>name</span><span class="p">))</span>
<span class="kp">if<>:</span>
<span class="n">i<>suite</span> <span class="o">!=</span> <span class="min">1<>ecflow</span><span class="po">:.</span>
<span span><span class="n">fam<>Suite</span><span class="op">.(</span><span class="n">add_trigger<>name</span><span class="p">()</span><spanspan>
<span class="s">"f"<k">for</span> <span class="on">+<>i</span> <span class="nbow">str<>in</span><span class="p">(</span><spanspan> <span class="nnb">i<>range</span><span class="op">-(</span><span class="mi">1</span><span class="p">),</span> <span class="o">+</span> <span class="s">" == complete"<mi">7</span><span class="p">)</span> <span class="c"># or fam.add_family( "f%d == complete" % (i-1) )p">:</span>
<span class="kn">for<>fam</span> <span class="no">t<>=</span> <span class="ow">in</span> <spann">suite</span><span class="o">.</span><span class="n">add_family</span><span class="p">(</span> <spanspan><span class="s">"af"</span><spanspan> <span class="po">,+</span> <span class="s">"b"<"nb">str</span><span class="p">,(</span> <spanspan><span class="s">"c"<n">i</span><span class="p">,))</span>
<span class="s">"d"</span><spank">if</span> <span class="pn">,<>i</span> <span class="so">"e"!=</span> <span class="pmi">)</span> <span>1</span><span class="p">:</span>
<span class="n">fam</span><span class="o">.</span><span class="n">add_task<trigger</span><span class="p">(</span><span class="n">t</span><spans">"f"</span> <span class="po">)+</span>
<span class="knb">return<>str</span> <spanspan><span class="n">suite</span>
</pre></div>
</div>
<divp">(</span><span class="line-block">
<divn">i</span><span class="line">The following python code shows <strong>examples</strong> of adding the various attributes to a <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-node"><em class="xref std std-term">node</em></a> tree.</div>
<div class="line">For a detailed explanation please consult the user manual.</div>
</div>
<div class="highlight-python"><div class="highlight"><pre><spano">-</span><span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="s">" == complete"</span><span class="p">)</span> <span class="c"># provides *examples* of add adding node attributes using the python API</span>
or fam.add_family( "f%d == complete" % (i-1) )</span>
<span class="ck">#>for</span> hence does *not* represent a real suite definition</span>
<span<span class="n">t</span> <span class="ow">in</span> <span class="p">(</span> <span class="s">"a"</span><span class="knp">from<>,</span> <span class="nn">ecflow</span> <spans">"b"</span><span class="knp">import<>,</span> <span class="os">*"c"</span>
<span span><span class="kp">def<>,</span> <span class="nf">list_to_int_vec<s">"d"</span><span class="p">(,</span> <span class="n">thePythonList<s">"e"</span> <span class="p">):</span>
<span class="sd">"""Converts a python list to a C++ IntVec in ecflow extension """p">:</span>
<span class="n">intvec<>fam</span>span><span <span class="o">.</span><span class="n">add_task</span><span class="p">(</span> <spanspan><span class="n">IntVec<>t</span><span class="p">()</span>
<span class="k">for<>return</span> <span class="n">theInt</span> <span class="ow">in</span> <span class="n">thePythonList</span><span class="p">:</span>
<span class="n">IntVec</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">intvec</span><span class="p">,</span><span class="n">theInt</span><span class="p">)>suite</span>
</pre></div>
</div>
<div class="line-block">
<div class="line">The following python code shows <strong>examples</strong> of adding the various attributes to a <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-node"><em class="xref std std-term">node</em></a> tree.</div>
<div class="line">For a detailed explanation please consult the user manual.</div>
</div>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># provides *examples* of add adding node attributes using the python API</span>
<span class="c"># hence does *not* represent a real suite definition</span>
<span class="kn">from</span> <span class="nn">ecflow</span> <span class="kn">import</span> <span class="o">*</span>
<span class="k">return<>if</span> <span class="n">intvec<>__name__</span>
<span class="k">def<o">==</span> <span class="nf">list_to_str_vec<s">"__main__"</span><span class="p">(:</span>
<span class="n">theList</span>c"># adding variables </span>
<span class="p">):<n">suite</span>
<span class="sd">"""Converts a python list to a C++ StrVec in ecflow extension"""o">=</span> <span class="n">Suite</span><span class="p">(</span><span class="s">"s1"</span><span class="p">);</span>
<span class="n">strvec<>suite</span> <spanspan><span class="o">=.</span> <spanspan><span class="n">StrVec<>add_variable</span><span class="p">()</span>
<span span><span class="n">Variable</span><span class="kp">for<>(</span>span><span <span class="n">theStr</span> <span s">"ECF_HOME"</span><span class="owp">in<>,</span> <span class="n">theList<s">"/tmp/"</span><span class="p">:))</span>
<span class="n">StrVec<>suite</span><span class="o">.</span><span class="n">append<>add_variable</span><span class="p">(</span><span class="n">strvec<s">"ECF_URL_CMD"</span><span class="p">,</span> <span class="s">"${BROWSER:=firefox} -remote 'openURL(</span><span class="nsi">theStr<>%E</span><span class="p">)s">CF_URL_BASE%/</span>
<span span><span class="ksi">return<>%E</span> <spanspan><span class="n">strvec<s">CF_URL%)'"</span><span class="p">;)</span>
<span class="kn">if<>suite</span> <spanspan><span class="o">.</span><span class="n">__name__</span> <span>add_variable</span><span class="op">==(</span> <spanspan><span class="s">"__main__NAME"</span><span class="p">:,</span>
<span class="cmi"># adding variables >10</span><span class="p">)</span>
<span class="n">suite<>a_dict</span> <span class="o">=</span> <span class="n">Suite</span><span class="p">({</span><spanspan> <span class="s">"s1name"</span><span class="p">);:</span>
<span span><span class="n">suite<s">"value"</span><span class="op">.,</span><spanspan> <span class="n">add_variable<s">"name2"</span><span class="p">(:</span><span class="n">Variable<s">"value2"</span><span class="p">(,</span><spanspan> <span class="s">"ECF_HOMEname3"</span><span class="p">,:</span><span class="s">"/tmp/value3"</span><span class="p">)),</span>
<span class="n">suite</span><span class="o">.s">"name4"</span><span class="n">add_variable</span><span class="p">(:</span><span class="s">"ECF_URL_CMDvalue4"</span><spanspan> <span class="p">,}</span>
<span class="s">"${BROWSER:=firefox} -remote 'openURL(<n">suite</span><span class="sio">%E<>.</span><span class="sn">CF>add_URL_BASE%variable</</span><span class="sip">%E<>(</span><span class="sn">CF_URL%)'"<>a_dict</span><span class="p">)</span>
<span class="c"># adding limits</span>
<span class="n">suite</span><span class="o">.</span><span class="n">add_limit</span><span class="p">(</span> <span class="n">Limit</span><span class="p">(</span><span class="s">"limitName1"</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span> <span class="p">)</span>
<span class="n">suite</span><span class="o">.</span><span class="n">add_limit</span><span class="p">(</span> <span class="s">"limitName3"</span><span class="p">,</span> <span class="mi">10</span> <span class="p">)</span>
<span class="c"># adding inlimits</span>
<span class="n">suite</span><span class="o">.</span><span class="n">add_inlimit</span><span class="p">(</span> <span class="n">InLimit</span><span class="p">(</span><span class="s">"limitName1"</span><span class="p">,</span><spanspan> <span class="s">"/s1/f1"</span><span class="p">,</span><spanspan> <span class="mi">2</span><span class="p">)</span> <span class="p">)</span>
<span class="n">suite</span><span class="o">.</span><span class="n">add_inlimit</span><span class="p">(</span> <span class="s">"limitName3"</span><span class="p">,</span><spanspan> <span class="s">"/s1/f1"</span><span class="p">,</span><spanspan> <span class="mi">2</span><span class="p">)</span>
<span class="c"># add short triggers and complete</span>
<span class="n">task</span> <span class="o">=</span> <span class="n">Task</span><span class="p">(</span><span class="s">"task"</span><span class="p">)</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_trigger</span><span class="p">(</span> <span class="s">"t2 == active"</span> <span class="p">)</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_complete</span><span class="p">(</span> <span class="s">"t2 == complete"</span> <span class="p">)</span>
<span class="c"># add long triggers and complete, in example below 'True' mean AND and 'False' means OR</span>
<span class="n">task</span> <span class="o">=</span> <span class="n">Task</span><span class="p">(</span><span class="s">"trigger"</span><span class="p">)</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_part_trigger</span><span class="p">(</span> <span class="s">"t1 == complete"</span> <span class="p">)</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_part_trigger</span><span class="p">(</span> <span class="s">"t2 == active"</span><span class="p">,</span><spanspan> <span class="bp">True</span> <span class="p">)</span> <span class="c"># for long and/or expressions, subsequent expr must be and/or</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_part_complete</span><span class="p">(</span> <span class="s">"t3 == complete"</span> <span class="p">)</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_part_complete</span><span class="p">(</span> <span class="s">"t4 == active"</span><span class="p">,</span><spanspan> <span class="bp">False</span><span class="p">)</span> <span class="c"># for long and/or expressions, subsequent expr must be and/or</span>
<span class="c"># add events</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_event</span><span class="p">(</span> <span class="n">Event</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="p">)</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_event</span><span class="p">(</span> <span class="mi">2</span> <span class="p">)</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_event</span><span class="p">(</span> <span class="n">Event</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span><spanspan> <span class="s">"Eventname"</span><span class="p">)</span> <span class="p">)</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_event</span><span class="p">(</span> <span class="mi">10</span><span class="p">,</span><spanspan> <span class="s">"Eventname2"</span> <span class="p">)</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_event</span><span class="p">(</span> <span class="s">"fred"</span> <span class="p">)</span>
<span class="c"># add meter</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_meter</span><span class="p">(</span> <span class="n">Meter</span><span class="p">(</span><span class="s">"metername1"</span><span class="p">,</span><spanspan> <span class="mi">0</span><span class="p">,</span><spanspan> <span class="mi">100</span><span class="p">,</span><spanspan> <span class="mi">50</span><span class="p">)</span> <span class="p">)</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_meter</span><span class="p">(</span> <span class="s">"metername3"</span><span class="p">,</span><spanspan> <span class="mi">0</span><span class="p">,</span><spanspan> <span class="mi">100</span> <span class="p">)</span>
<span class="c"># add label</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_label</span><span class="p">(</span> <span class="n">Label</span><span class="p">(</span><span class="s">"label_name1"</span><span class="p">,</span> <span class="s">"value"</span><span class="p">)</span> <span class="p">)</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_label</span><span class="p">(</span> <span class="s">"label_name3"</span><span class="p">,</span> <span class="s">"value"</span> <span class="p">)</span>
<span class="c"># add Repeat. A node can only have one repeat, hence we delete the repeat before, adding another</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_repeat</span><span class="p">(</span> <span class="n">RepeatInteger</span><span class="p">(</span><span class="s">"integer"</span><span class="p">,</span><spanspan> <span class="mi">0</span><span class="p">,</span><spanspan> <span class="mi">100</span><span class="p">,</span><spanspan> <span class="mi">2</span><span class="p">)</span> <span class="p">);</span>
<span class="n">task</span><span class="o">.</span><span class="n">delete_repeat</span><span class="p">();</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_repeat</span><span class="p">(</span> <span class="n">RepeatEnumerated</span><span class="p">(</span><span class="s">"enum"</span><span class="p">,</span><span class="n">list_to_str_vec</span><span class="p">(</span> <span class="p">[</span><span class="s">"red"</span><span class="p">,</span> <span class="s">"green"</span><span class="p">,</span> <span class="s">"blue"</span> <span class="p">]</span> <span class="p">))</span> <span class="p">);</span>
<span class="n">task</span><span class="o">.</span><span class="n">delete_repeat</span><span class="p">();</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_repeat</span><span class="p">(</span> <span class="n">RepeatDate</span><span class="p">(</span><span class="s">"date"</span><span class="p">,</span><spanspan> <span class="mi">20100111</span><span class="p">,</span><spanspan> <span class="mi">20100115</span><span class="p">,</span><spanspan> <span class="mi">2</span><span class="p">)</span> <span class="p">)</span>
<span class="n">task</span><span class="o">.</span><span class="n">delete_repeat</span><span class="p">();</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_repeat</span><span class="p">(</span> <span class="n">RepeatString</span><span class="p">(</span><span class="s">"string"</span><span class="p">,(</span>span><span <span class="n">list_to_str_vec<s">"string"</span><span class="p">(,</span> <span class="p">[</span><span class="s">"a"</span><span class="p">,</span> <span class="s">"b"</span><span class="p">,</span> <span class="s">"c"</span> <span class="p">]</span> <span class="p">))</span> <span class="p">)</span>
<span class="n">task</span><span class="o">.</span><span class="n">delete_repeat</span><span class="p">();</span>
<span class="c"># create a time series, used for adding time and today and cron</span>
<span class="n">start</span> <span class="o">=</span> <span class="n">TimeSlot</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><spanspan> <span class="mi">0</span><span class="p">)</span>
<span class="n">finish</span> <span class="o">=</span> <span class="n">TimeSlot</span><span class="p">(</span><span class="mi">23</span><span class="p">,</span><spanspan> <span class="mi">0</span><span class="p">)</span>
<span class="n">incr</span> <span class="o">=</span> <span class="n">TimeSlot</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><spanspan> <span class="mi">30</span><span class="p">)</span>
<span class="n">time_series</span> <span class="o">=</span> <span class="n">TimeSeries</span><span class="p">(</span> <span class="n">start</span><span class="p">,</span> <span class="n">finish</span><span class="p">,</span> <span class="n">incr</span><span class="p">,</span> <span class="bp">True</span><span class="p">);</span> <span class="c"># True means relative to suite start</span>
<span class="c"># add a today</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_today</span><span class="p">(</span> <span class="s">"00:30"</span> <span class="p">)</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_today</span><span class="p">(</span> <span class="s">"+00:30"</span> <span class="p">)</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_today</span><span class="p">(</span> <span class="s">"+00:30 20:00 01:00"</span> <span class="p">)</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_today</span><span class="p">(</span> <span class="n">Today</span><span class="p">(</span> <span class="n">time_series</span><span class="p">)</span> <span class="p">)</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_today</span><span class="p">(</span> <span class="n">Today</span><span class="p">(</span> <span class="mi">0</span><span class="p">,</span><spanspan> <span class="mi">10</span> <span class="p">))</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_today</span><span class="p">(</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">59</span><span class="p">,</span> <span class="bp">True</span> <span class="p">)</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_today</span><span class="p">(</span> <span class="n">Today</span><span class="p">(</span><span class="n">TimeSlot</span><span class="p">(</span><span class="mi">20</span><span class="p">,</span><spanspan> <span class="mi">10</span><span class="p">))</span> <span class="p">)</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_today</span><span class="p">(</span> <span class="n">Today</span><span class="p">(</span><span class="n">TimeSlot</span><span class="p">(</span><span class="mi">20</span><span class="p">,</span><spanspan> <span class="mi">20</span><span class="p">),</span><spanspan> <span class="bp">False</span><span class="p">))</span>
<span class="c"># add time</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_time</span><span class="p">(</span> <span class="s">"00:30"</span> <span class="p">)</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_time</span><span class="p">(</span> <span class="s">"+00:30"</span> <span class="p">)</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_time</span><span class="p">(</span> <span class="s">"+00:30 20:00 01:00"</span> <span class="p">)</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_time</span><span class="p">(</span> <span class="n">Time</span><span class="p">(</span><span class="n">time_series</span> <span class="p">))</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_time</span><span class="p">(</span> <span class="n">Time</span><span class="p">(</span> <span class="mi">0</span><span class="p">,</span><spanspan> <span class="mi">10</span> <span class="p">))</span>
<span class="n">task</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">59</span><span class="p">,</span> <span class="bp">True</span><span class="p">)</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_time</span><span class="p">(</span> <span class="n">Time</span><span class="p">(</span><span class="n">TimeSlot</span><span class="p">(</span><span class="mi">20</span><span class="p">,</span><spanspan> <span class="mi">10</span><span class="p">))</span> <span class="p">)</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_time</span><span class="p">(</span> <span class="n">Time</span><span class="p">(</span><span class="n">TimeSlot</span><span class="p">(</span><span class="mi">20</span><span class="p">,</span><spanspan> <span class="mi">20</span><span class="p">),</span><spanspan> <span class="bp">False</span><span class="p">))</span>
<span class="c"># add date</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="p">[</span> <span class="mi">1</span><span class="p">,</span><spanspan> <span class="mi">2</span><span class="p">,</span><spanspan> <span class="mi">4</span><span class="p">,</span><spanspan> <span class="mi">8</span><span class="p">,</span><spanspan> <span class="mi">16</span> <span class="p">]</span> <span class="p">:</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_date</span><span class="p">(</span> <span class="n">i</span><span class="p">,</span><spanspan> <span class="mi">0</span><span class="p">,</span><spanspan> <span class="mi">0</span><span class="p">)</span> <span class="c"># day,month,year, where corresponding 0 means any possible day,month, year</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_date</span><span class="p">(</span> <span class="n">Date</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><spanspan> <span class="mi">1</span><span class="p">,</span><spanspan> <span class="mi">2010</span><span class="p">))</span>
<span class="c"># add day</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_day</span><span class="p">(</span> <span class="n">Day</span><span class="p">(</span><span class="n">Days</span><span class="o">.</span><span class="n">sunday</span><span class="p">))</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_day</span><span class="p">(</span> <span class="n">Days</span><span class="o">.</span><span class="n">monday</span><span class="p">)</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_day</span><span class="p">(</span> <span class="s">"tuesday"</span><span class="p">)</span>
<span class="c"># create cron, showing different ways adding the time, to a cron attribute</span>
<span class="n">cron</span> <span class="o">=</span> <span class="n">Cron</span><span class="p">()</span>
<span class="n">cron</span><span class="o">.</span><span class="n">set_week_days</span><span class="po">(.</span> <spanspan><span class="n">list>set_toweek_int_vec<days</span><span class="p">(</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span><spanspan> <span class="mi">1</span><span class="p">,</span><spanspan> <span class="mi">2</span><span class="p">,</span><spanspan> <span class="mi">3</span><span class="p">,</span><spanspan> <span class="mi">4</span><span class="p">,</span><spanspan> <span class="mi">5</span><span class="p">,</span><spanspan> <span class="mi">6</span><span class="p">]</span> <span class="p">)</span> <span class="p">)</span>
<span class="n">cron</span><span class="o">.</span><span class="n">set_days_of_month</span><span class="p">(</span> <span class="n">list_to_int_vec</span><span class="p">(</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span><spanspan> <span class="mi">2</span><span class="p">,</span><spanspan> <span class="mi">3</span><span class="p">,</span><spanspan> <span class="mi">4</span><span class="p">,</span><spanspan> <span class="mi">5</span><span class="p">,</span><spanspan> <span class="mi">6</span><span class="p">]</span> <span class="p">)</span> <span class="p">)</span>
<span class="n">cron</span><span class="o">.</span><span class="n">set_months<>cron</span><span class="po">(.</span> <spanspan><span class="n">list_to_int_vec<>set_months</span><span class="p">(</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span><spanspan> <span class="mi">2</span><span class="p">,</span><spanspan> <span class="mi">3</span><span class="p">,</span><spanspan> <span class="mi">4</span><span class="p">,</span><spanspan> <span class="mi">5</span><span class="p">,</span><spanspan> <span class="mi">6</span><span class="p">]</span> <span class="p">)</span> <span class="p">)</span>
<span class="n">start</span> <span class="o">=</span> <span class="n">TimeSlot</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><spanspan> <span class="mi">0</span><span class="p">)</span>
<span class="n">finish</span> <span class="o">=</span> <span class="n">TimeSlot</span><span class="p">(</span><span class="mi">23</span><span class="p">,</span><spanspan> <span class="mi">0</span><span class="p">)</span>
<span class="n">incr</span> <span class="o">=</span> <span class="n">TimeSlot</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><spanspan> <span class="mi">30</span><span class="p">)</span>
<span class="n">ts</span> <span class="o">=</span> <span class="n">TimeSeries</span><span class="p">(</span> <span class="n">start</span><span class="p">,</span> <span class="n">finish</span><span class="p">,</span> <span class="n">incr</span><span class="p">,</span> <span class="bp">True</span><span class="p">);</span> <span class="c"># True means relative to suite start</span>
<span class="n">cron</span><span class="o">.</span><span class="n">set_time_series</span><span class="p">(</span> <span class="n">ts</span> <span class="p">)</span>
<span class="n">cron1</span> <span class="o">=</span> <span class="n">Cron</span><span class="p">()</span>
<span class="n">cron1</span><span class="o">.</span><span class="n">set_week_days</span><span class="p">(</span> <span class="n">list_to_int_vec</span><span class="p">(</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span><spanspan> <span class="mi">1</span><span class="p">,</span><spanspan> <span class="mi">2</span><span class="p">,</span><spanspan> <span class="mi">3</span><span class="p">,</span><spanspan> <span class="mi">4</span><span class="p">,</span><spanspan> <span class="mi">5</span><span class="p">,</span><spanspan> <span class="mi">6</span><span class="p">]</span> <span class="p">)]</span> <span class="p">)</span>
<span class="n">cron1</span><span class="o">.</span><span class="n">set_time_series</span><span class="p">(</span> <span class="mi">1</span><span class="p">,</span><spanspan> <span class="mi">30</span><span class="p">,</span> <span class="bp">True</span> <span class="p">)</span>
<span class="n">cron2</span> <span class="o">=</span> <span class="n">Cron</span><span class="p">()</span>
<span class="n">cron2</span><span class="o">.</span><span class="n">set_week_days</span><span class="p">(</span> <span class="n">list_to_int_vec</span><span class="p">(</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span><spanspan> <span class="mi">1</span><span class="p">,</span><spanspan> <span class="mi">2</span><span class="p">,</span><spanspan> <span class="mi">3</span><span class="p">,</span><spanspan> <span class="mi">4</span><span class="p">,</span><spanspan> <span class="mi">5</span><span class="p">,</span><spanspan> <span class="mi">6</span><span class="p">]</span> <span class="p">)</span> <span class="p">)</span>
<span class="n">cron2</span><span class="o">.</span><span class="n">set_time_series</span><span class="p">(</span> <span class="s">"00:30 01:30 00:01"</span> <span class="p">)</span>
<span class="n">cron3</span> <span class="o">=</span> <span class="n">Cron</span><span class="p">()</span>
<span class="n">cron3</span><span class="o">.</span><span class="n">set_week_days</span><span class="p">(</span> <span class="n">list_to_int_vec</span><span class="p">(</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span><spanspan> <span class="mi">1</span><span class="p">,</span><spanspan> <span class="mi">2</span><span class="p">,</span><spanspan> <span class="mi">3</span><span class="p">,</span><spanspan> <span class="mi">4</span><span class="p">,</span><spanspan> <span class="mi">5</span><span class="p">,</span><spanspan> <span class="mi">6</span><span class="p">]</span> <span /span><span class="p">)]</span> <span class="p">)</span>
<span class="n">cron3</span><span class="o">.</span><span class="n">set_time_series</span><span class="p">(</span> <span class="s">"+00:30"</span> <span class="p">)</span>
<span class="c"># add auto cancel</span>
<span class="n">t1</span> <span class="o">=</span> <span class="n">Task</span><span class="p">(</span><span class="s">"t1"</span><span class="p">);</span>
<span class="n">t3</span> <span class="o">=</span> <span class="n">Task</span><span class="p">(</span><span class="s">"t3"</span><span class="p">)</span>
<span class="n">t4</span> <span class="o">=</span> <span class="n">Task</span><span class="p">(</span><span class="s">"t4"</span><span class="p">)</span>
<span class="n">t5</span> <span class="o">=</span> <span class="n">Task</span><span class="p">(</span><span class="s">"t5"</span><span class="p">)</span>
<span class="n">t1</span><span class="o">.</span><span class="n">add_autocancel</span><span class="p">(</span> <span class="mi">3</span> <span class="p">)</span> <span class="c"># 3 days</span>
<span class="n">t3</span><span class="o">.</span><span class="n">add_autocancel</span><span class="p">(</span> <span class="mi">20</span><span class="p">,</span><spanspan> <span class="mi">10</span><span class="p">,</span><spanspan> <span class="bp">True</span> <span class="p">)</span> <span class="c"># hour,minutes,relative</span>
<span class="n">t4</span><span class="o">.</span><span class="n">add_autocancel</span><span class="p">(</span> <span class="n">TimeSlot</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span><spanspan> <span class="mi">10</span><span class="p">),</span><spanspan> <span class="bp">True</span> <span class="p">)</span> <span class="c"># hour,minutes,relative</span>
<span class="n">t5</span><span class="o">.</span><span class="n">add_autocancel</span><span class="p">(</span> <span class="n">Autocancel</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><spanspan> <span class="mi">10</span><span class="p">,</span><spanspan> <span class="bp">True</span><span class="p">)</span> <span class="p">)</span> <span class="c"># hour,minutes,relative</span>
<span class="c"># add late</span>
<span class="n">late</span> <span class="o">=</span> <span class="n">Late</span><span class="p">()</span>
<span class="n">late</span><span class="o">.</span><span class="n">submitted</span><span class="p">(</span> <span class="n">TimeSlot</span><span class="p">(</span><span class="mi">20</span><span class="p">,</span><spanspan> <span class="mi">10</span><span class="p">)</span> <span class="p">)</span>
<span class="n">late</span><span class="o">.</span><span class="n">active</span><span class="p">(</span> <span class="n">TimeSlot</span><span class="p">(</span><span class="mi">20</span><span class="p">,</span><spanspan> <span class="mi">10</span><span class="p">))</span>
<span class="n">late</span><span class="o">.</span><span class="n">complete</span><span class="p">(</span> <span class="n">TimeSlot</span><span class="p">(</span><span class="mi">20</span><span class="p">,</span><spanspan> <span class="mi">10</span><span class="p">),</span><spanspan> <span class="bp">True</span><span class="p">)</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_late</span><span class="p">(</span> <span class="n">late</span> <span class="p">)</span>
<span class="n">late</span> <span class="o">=</span> <span class="n">Late</span><span class="p">()</span>
<span class="n">late</span><span class="o">.</span><span class="n">submitted</span><span class="p">(</span> <span class="mi">20</span><span class="p">,</span><spanspan> <span class="mi">10</span> <span class="p">)</span>
<span class="n">late</span><span class="o">.</span><span class="n">active</span><span class="p">(</span> <span class="mi">20</span><span class="p">,</span><spanspan> <span class="mi">10</span> <span class="p">)</span>
<span class="n">late</span><span class="o">.</span><span class="n">complete</span><span class="p">(</span> <span class="mi">20</span><span class="p">,</span><spanspan> <span class="mi">10</span><span class="p">,</span><spanspan> <span class="bp">True</span><span class="p">)</span>
<span class="n">t1</span><span class="o">.</span><span class="n">add_late</span><span class="p">(</span> <span class="n">late</span> <span class="p">)</span>
<span class="c"># add defstatus, last one set takes effect</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_defstatus</span><span class="p">(</span> <span class="n">DState</span><span class="o">.</span><span class="n">complete</span> <span class="p">)</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_defstatus</span><span class="p">(</span> <span class="n">DState</span><span class="o">.</span><span class="n">queued</span> <span class="p">)</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_defstatus</span><span class="p">(</span> <span class="n">DState</span><span class="o">.</span><span class="n">aborted</span> <span class="p">)</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_defstatus</span><span class="p">(</span> <span class="n">DState</span><span class="o">.</span><span class="n">submitted</span> <span class="p">)</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_defstatus</span><span class="p">(</span> <span class="n">DState</span><span class="o">.</span><span class="n">suspended</span> <span class="p">)</span>
<span class="n">task</span><span class="o">.</span><span class="n">add_defstatus</span><span class="p">(</span> <span class="n">DState</span><span class="o">.</span><span class="n">active</span> <span class="p">)</span>
<span class="c"># add clock,<clock</span>
<span class="n">clock</span> <span class="o">=</span> <span class="n">Clock</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><spanspan> <span class="mi">1</span><span class="p">,</span><spanspan> <span class="mi">2010</span><span class="p">,</span><spanspan> <span class="bp">False</span><span class="p">);</span> <span class="c"># day,month, year, hybrid(true), real(False)</span>
<span class="n">clock</span><span class="o">.</span><span class="n">set_gain</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><spanspan> <span class="mi">10</span><span class="p">,</span><spanspan> <span class="bp">True</span><span class="p">);</span> <span class="c"># True means positive gain</span>
<span class="n">suite</span> <span class="o">=</span> <span class="n">Suite</span><span class="p">(</span><span class="s">"suite"</span><span class="p">)</span>
<span class="n">suite</span><span class="o">.</span><span class="n">add_clock</span><span class="p">(</span><span class="n">clock</span><span class="p">);</span>
<span class="n">clock</span> <span class="o">=</span> <span class="n">Clock</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><spanspan> <span class="mi">1</span><span class="p">,</span><spanspan> <span class="mi">2011</span><span class="p">,</span><spanspan> <span class="bp">True</span><span class="p">);</span> <span class="c"># day,month,year,hybrid</span>
<span class="n">clock</span><span class="o">.</span><span class="n">set_gain_in_seconds</span><span class="p">(</span><span class="mi">12</span><span class="p">,</span><spanspan> <span class="bp">True</span><span class="p">);</span>
<span class="n">s1</span> <span class="o">=</span> <span class="n">Suite</span><span class="p">(</span><span class="s">"s1"</span><span class="p">)</span>
<span class="n">s1</span><span class="o">.</span><span class="n">add_clock</span><span class="p">(</span><span class="n">clock</span><span class="p">)</span>
</pre></div>
</div>
</div>
|