|
1
|
|
|
""" |
|
2
|
|
|
Enarksh |
|
3
|
|
|
|
|
4
|
|
|
Copyright 2015-2016 Set Based IT Consultancy |
|
5
|
|
|
|
|
6
|
|
|
Licence MIT |
|
7
|
|
|
""" |
|
8
|
|
|
from xml.dom import minidom |
|
9
|
|
|
from xml.etree import ElementTree |
|
10
|
|
|
from xml.etree.ElementTree import Element, SubElement |
|
11
|
|
|
|
|
12
|
|
|
from enarksh_lib.xml_generator.node.CompoundJobNode import CompoundJobNode |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
class ScheduleNode(CompoundJobNode): |
|
|
|
|
|
|
16
|
|
|
""" |
|
17
|
|
|
Class for generating XML messages for elements of type 'ScheduleType'. |
|
18
|
|
|
""" |
|
19
|
|
|
|
|
20
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
|
21
|
|
|
def get_xml(self, encoding='utf-8'): |
|
22
|
|
|
""" |
|
23
|
|
|
Returns the XML-code of this schedule. |
|
24
|
|
|
|
|
25
|
|
|
The returned byte string contains the XML in the requested encoding. You save the byte sting to file in binary |
|
26
|
|
|
mode (the file will encoded the requested encoding). Or you can convert the byte string to a string with |
|
27
|
|
|
.decode(encoding). |
|
28
|
|
|
|
|
29
|
|
|
:param str encoding: The encoding of the XML. |
|
30
|
|
|
|
|
31
|
|
|
:rtype: bytes |
|
32
|
|
|
""" |
|
33
|
|
|
tree = Element(None) |
|
34
|
|
|
self.generate_xml(tree) |
|
35
|
|
|
|
|
36
|
|
|
xml_string = ElementTree.tostring(tree) |
|
37
|
|
|
document = minidom.parseString(xml_string) |
|
38
|
|
|
|
|
39
|
|
|
return document.toprettyxml(indent=' ', encoding=encoding) |
|
40
|
|
|
|
|
41
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
|
42
|
|
|
def ensure_dependencies(self): |
|
43
|
|
|
""" |
|
44
|
|
|
Remember a schedule node is the only compound node without input and output ports. Therefore we must override |
|
45
|
|
|
this method. |
|
46
|
|
|
""" |
|
47
|
|
|
if self.child_nodes: |
|
48
|
|
|
# Apply this method recursively for all child node. |
|
49
|
|
|
for node in self.child_nodes: |
|
50
|
|
|
node.ensure_dependencies() |
|
51
|
|
|
|
|
52
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
|
53
|
|
|
def generate_xml(self, parent): |
|
54
|
|
|
""" |
|
55
|
|
|
Generates the XML element for this node. |
|
56
|
|
|
""" |
|
57
|
|
|
schedule = SubElement(parent, 'Schedule') |
|
58
|
|
|
|
|
59
|
|
|
self._generate_xml_common(schedule) |
|
60
|
|
|
|
|
61
|
|
|
# ---------------------------------------------------------------------------------------------------------------------- |
|
62
|
|
|
|
Methods which raise
NotImplementedErrorshould be overridden in concrete child classes.