Passed
Push — master ( bd4b5e...fa3bf6 )
by P.R.
01:57
created

CommandJobNode.generate_xml()   A

Complexity

Conditions 3

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 19
ccs 10
cts 10
cp 1
rs 9.4285
cc 3
crap 3
1
"""
2
Enarksh
3
4
Copyright 2015-2016 Set Based IT Consultancy
5
6
Licence MIT
7
"""
8 1
from xml.etree.ElementTree import SubElement
9
10 1
from enarksh_lib.xml_generator.node.Node import Node
11
12
13 1
class CommandJobNode(Node):
14
    """
15
    Class for generating XML messages for elements of type 'CommandJobType'.
16
    """
17
18
    # ------------------------------------------------------------------------------------------------------------------
19 1
    def __init__(self, name):
20
        """
21
        Object constructor.
22
23
        :param str name: The name of the node.
24
        """
25 1
        Node.__init__(self, name)
26
27 1
        self.args = []
28
        """
29
        The arguments of the executable.
30
31
        :type: list[str]
32
        """
33
34 1
        self.path = ''
35 1
        """
36
        The path of the executable that must be run by this job.
37
38
        :type: str
39
        """
40
41
    # ------------------------------------------------------------------------------------------------------------------
42 1
    def generate_xml(self, parent):
43
        """
44
        Generates the XML element for this node.
45
46
        :param xml.etree.ElementTree.Element parent: The parent XML element.
47
        """
48 1
        command_job = SubElement(parent, 'CommandJob')
49
50 1
        self._generate_xml_common(command_job)
51
52 1
        path = SubElement(command_job, 'Path')
53 1
        path.text = self.path
54
55 1
        if self.args:
56 1
            args_element = SubElement(command_job, 'Args')
57
58 1
            for arg in self.args:
59 1
                argument = SubElement(args_element, 'Arg')
60 1
                argument.text = str(arg)
61
62
    # ------------------------------------------------------------------------------------------------------------------
63 1
    def get_implicit_dependencies_output_ports(self, port_name, ports, level):
64
        """
65
66
        :param str                                                port_name:
67
        :param list[enarksh_lib.xml_generator.port.Port.Port] ports:
68
        :param int                                                level:
69
70
        :rtype: list[]
71
        """
72 1
        port = self.get_output_port(port_name)
73
74 1
        if port not in ports:
75 1
            if level:
76
                ports.append(port)
77
78 1
        self.get_implicit_dependencies_input_ports(self.ALL_PORT_NAME, ports, level + 1)
79
80
# ----------------------------------------------------------------------------------------------------------------------
81