@@ 58-89 (lines=32) @@ | ||
55 | log.error(exception.error_log.filter_from_level(etree.ErrorLevels.WARNING)) |
|
56 | raise exception |
|
57 | ||
58 | return schedule |
|
59 | ||
60 | # ------------------------------------------------------------------------------------------------------------------ |
|
61 | @staticmethod |
|
62 | def parse_dynamic_worker(xml, parent): |
|
63 | """ |
|
64 | Parses a schedule definition in XML. |
|
65 | ||
66 | :param str xml: The XML with a schedule definition |
|
67 | :param parent: |
|
68 | ||
69 | :rtype: enarksh.xml_reader.node.CompoundJobNode |
|
70 | """ |
|
71 | with open(os.path.join(C.HOME, 'etc/enarksh.xsd'), 'rb') as f: |
|
72 | xsd = f.read() |
|
73 | ||
74 | schema_root = etree.XML(xsd) |
|
75 | schema = etree.XMLSchema(schema_root) |
|
76 | parser = etree.XMLParser(schema=schema, encoding='utf8') |
|
77 | root = etree.fromstring(bytes(xml, 'utf8'), parser) |
|
78 | ||
79 | # Root element must be a dynamic inner worker. |
|
80 | if root.tag != 'DynamicInnerWorker': |
|
81 | raise Exception("Root element must be 'DynamicInnerWorker' but '{0!s}' was found.".format(root.tag)) |
|
82 | ||
83 | worker = create_node('DynamicInnerWorker') |
|
84 | worker.read_xml(root) |
|
85 | error = worker.validate(parent) |
|
86 | if error: |
|
87 | raise Exception("XML message is not a valid dynamic worker configuration.\n{0!s}".format(error)) |
|
88 | ||
89 | # Set recursion and dependency levels. |
|
90 | worker.set_levels() |
|
91 | ||
92 | return worker |
|
@@ 92-122 (lines=31) @@ | ||
89 | # Set recursion and dependency levels. |
|
90 | worker.set_levels() |
|
91 | ||
92 | return worker |
|
93 | ||
94 | # ------------------------------------------------------------------------------------------------------------------ |
|
95 | @staticmethod |
|
96 | def parse_host(filename): |
|
97 | """ |
|
98 | Parses a host definition in XML. |
|
99 | ||
100 | :param str filename: The XML file with a host definition |
|
101 | ||
102 | :rtype: enarksh.xml_reader.Host.Host |
|
103 | """ |
|
104 | with open(filename, 'rt', encoding='utf-8') as stream: |
|
105 | xml = stream.read() |
|
106 | ||
107 | with open(os.path.join(C.HOME, 'etc/enarksh.xsd'), 'rb') as stream: |
|
108 | xsd = stream.read() |
|
109 | ||
110 | schema_root = etree.XML(xsd) |
|
111 | schema = etree.XMLSchema(schema_root) |
|
112 | parser = etree.XMLParser(schema=schema, encoding='utf8') |
|
113 | root = etree.fromstring(bytes(xml, 'utf8'), parser) |
|
114 | ||
115 | # Root element must be a schedule. |
|
116 | if root.tag != 'Host': |
|
117 | raise Exception("Root element must be 'Host' but '{0!s}' was found.".format(root.tag)) |
|
118 | ||
119 | host = Host() |
|
120 | host.read_xml(root) |
|
121 | error = host.validate() |
|
122 | if error: |
|
123 | raise Exception("File '{0!s}' is not a valid host configuration file.\n{1!s}".format(filename, error)) |
|
124 | ||
125 | return host |