1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
#
# Copyright 2009- ECMWF.
#
# This software is licensed under the terms of the Apache Licence version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.
#
from ecflow import Suite, Task, RepeatDate
if __name__ == "__main__":
class ExperimentalSuite(object):
def __init__(self, start, end):
self.start_ = start
self.end_ = end
self.start_cycle_ = 12
self.end_cycle_ = 12
def generate(self):
x_suite = Suite("x")
make_fam = x_suite.add_family("make")
make_fam.add_task("build")
make_fam.add_task("more_work")
main_fam = x_suite.add_family("main")
main_fam.add_repeat(RepeatDate("YMD", self.start_, self.end_))
main_fam.add_trigger("make == complete")
previous = 0
for FAM in (0, 6, 12, 18):
fam_fam = x_suite.add_family(str(FAM))
if FAM > 0:
fam_fam.add_trigger("./" + str(previous) + " == complete ")
self.add_complete(fam_fam, FAM)
fam_fam.add_task("run")
fam_fam.add_task("run_more").add_trigger("run == complete")
previous = FAM
return x_suite
def add_complete(self, family, fam):
if fam < self.start_cycle_ and fam > self.end_cycle_:
family.add_complete("../main:YMD eq " + str(self.start_) + " or ../main:YMD ge " + str(self.end_))
elif fam < self.start_cycle_:
family.add_complete("../main:YMD eq " + str(self.start_))
elif fam > self.end_cycle_:
family.add_complete("../main:YMD ge " + str(self.end_))
return
print(str(ExperimentalSuite(20050601, 20050605).generate()))
# ==========================================================================
# Control structure and looping
var = "aa"
if var in ("a", "aa", "aaa"):
print("it is a kind of a ")
elif var in ("b", "bb", "bb"):
print("it is a kind of b ")
else:
print("it is something else ")
# ====================================================================================
# Reuseable class for adding synoptic times
class VarAdder(object):
def __init__(self, node):
self.node = node
def add(self, time):
{
6: lambda self: self.add6(time),
12: lambda self: self.add12(time),
18: lambda self: self.add18(time),
24: lambda self: self.add24(time)
}.get(time, self.errorHandler)(self)
def add6(self, time):
print("add6 " + str(time))
self.node.add_today(17, 30)
self.node.add_variable("ANTIME", str(time))
def add12(self, time):
print("add12 " + str(time))
self.node.add_today(19, 15)
self.node.add_variable("ANTIME", str(time))
def add18(self, time):
print("add18 " + str(time))
self.node.add_time(1, 30)
self.node.add_variable("ANTIME", str(time))
def add24(self, time):
print("add24 " + str(time))
self.node.add_time(3, 0)
self.node.add_variable("ANTIME", "0")
self.node.add_variable("DELTA_DAY", "1")
self.node.add_variable("EXPVER", "0002")
def errorHandler(self, ignore): print("invalid time " + str(ignore))
for i in (0, 6):
task = Task("t" + str(i))
print(task.name())
varAdder = VarAdder(task)
varAdder.add(114)
for var in task.variables:
print(str(var) + "\n")
for the_time in task.times:
print(str(the_time) + "\n")
for today in task.todays:
print(str(today) + "\n")
# ==========================================================================
suite = Suite("x")
previous_time = 0
for i in (0, 6, 12, 18, 24):
the_fam = suite.add_family(str(i))
if i != 0:
the_fam.add_trigger("./" + previous_time + " == complete ")
the_fam.add_task("t1")
the_fam.add_task("t2").add_trigger("t1 == complete")
previous_time = str(i)
|