1 | """ |
||
2 | Enarksh |
||
3 | |||
4 | Copyright 2013-2016 Set Based IT Consultancy |
||
5 | |||
6 | Licence MIT |
||
7 | """ |
||
8 | import logging |
||
9 | import os |
||
10 | |||
11 | from lxml import etree |
||
0 ignored issues
–
show
|
|||
12 | |||
13 | from enarksh.C import C |
||
14 | from enarksh.xml_reader.Host import Host |
||
15 | from enarksh.xml_reader.node import create_node |
||
16 | |||
17 | |||
18 | class XmlReader: |
||
0 ignored issues
–
show
This class should have a docstring.
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods: class SomeClass:
def some_method(self):
"""Do x and return foo."""
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions. ![]() |
|||
19 | # ------------------------------------------------------------------------------------------------------------------ |
||
20 | @staticmethod |
||
21 | def parse_schedule(xml, filename): |
||
22 | """ |
||
23 | Parses a schedule definition in XML. |
||
24 | |||
25 | :param str xml: The XML with a schedule definition |
||
26 | :param str filename: |
||
27 | |||
28 | :rtype: enarksh.xml_reader.node.ScheduleNode |
||
29 | """ |
||
30 | with open(os.path.join(C.HOME, 'etc/enarksh.xsd'), 'rb') as f: |
||
0 ignored issues
–
show
The name
f does not conform to the variable naming conventions ([a-z_][a-z0-9_]{1,60}$ ).
This check looks for invalid names for a range of different identifiers. You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements. If your project includes a Pylint configuration file, the settings contained in that file take precedence. To find out more about Pylint, please refer to their site. ![]() |
|||
31 | xsd = f.read() |
||
32 | |||
33 | etree.clear_error_log() |
||
34 | schema_root = etree.XML(xsd) |
||
35 | schema = etree.XMLSchema(schema_root) |
||
36 | parser = etree.XMLParser(schema=schema, encoding='utf8') |
||
37 | try: |
||
38 | root = etree.fromstring(bytes(xml, 'utf8'), parser) |
||
39 | |||
40 | # Root element must be a schedule. |
||
41 | if root.tag != 'Schedule': |
||
42 | raise Exception("Root element must be 'Schedule' but '{0!s}' was found.".format(root.tag)) |
||
43 | |||
44 | schedule = create_node('Schedule') |
||
45 | schedule.read_xml(root) |
||
46 | error = schedule.validate() |
||
47 | if error: |
||
48 | raise Exception( |
||
49 | "File '{0!s}' is not a valid schedule configuration file.\n{1!s}".format(filename, error)) |
||
50 | |||
51 | # Set recursion and dependency levels. |
||
52 | schedule.set_levels() |
||
53 | except etree.XMLSyntaxError as exception: |
||
54 | log = logging.getLogger('enarksh') |
||
55 | log.error(exception.error_log.filter_from_level(etree.ErrorLevels.WARNING)) |
||
56 | raise exception |
||
57 | |||
58 | View Code Duplication | return schedule |
|
0 ignored issues
–
show
|
|||
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: |
||
0 ignored issues
–
show
The name
f does not conform to the variable naming conventions ([a-z_][a-z0-9_]{1,60}$ ).
This check looks for invalid names for a range of different identifiers. You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements. If your project includes a Pylint configuration file, the settings contained in that file take precedence. To find out more about Pylint, please refer to their site. ![]() |
|||
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 | View Code Duplication | return worker |
|
0 ignored issues
–
show
|
|||
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 |
||
126 | |||
127 | # ---------------------------------------------------------------------------------------------------------------------- |
||
128 |
This can be caused by one of the following:
1. Missing Dependencies
This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.
2. Missing __init__.py files
This error could also result from missing
__init__.py
files in your module folders. Make sure that you place one file in each sub-folder.