Passed
Push — master ( 4b3140...3dcfbb )
by P.R.
01:38
created

CommandJobNode.append_argument()   A

Complexity

Conditions 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
1
"""
2
Enarksh
3
4
Copyright 2015-2016 Set Based IT Consultancy
5
6
Licence MIT
7
"""
8
from xml.etree.ElementTree import SubElement
9
10
from enarksh_lib.xml_generator.node.Node import Node
11
12
13
class CommandJobNode(Node):
14
    """
15
    Class for generating XML messages for elements of type 'CommandJobType'.
16
    """
17
18
    # ------------------------------------------------------------------------------------------------------------------
19
    def __init__(self, name):
20
        """
21
        Object constructor.
22
23
        :param str name: The name of the node.
24
        """
25
        Node.__init__(self, name)
26
27
        self.args = []
28
        """
29
        The arguments of the executable.
30
31
        :type: list[str]
32
        """
33
34
        self.path = ''
35
        """
36
        The path of the executable that must be run by this job.
37
38
        :type: str
39
        """
40
41
    # ------------------------------------------------------------------------------------------------------------------
42
    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
        command_job = SubElement(parent, 'CommandJob')
49
50
        self._generate_xml_common(command_job)
51
52
        path = SubElement(command_job, 'Path')
53
        path.text = self.path
54
55
        if self.args:
56
            args_element = SubElement(command_job, 'Args')
57
58
            for arg in self.args:
59
                argument = SubElement(args_element, 'Arg')
60
                argument.text = str(arg)
61
62
    # ------------------------------------------------------------------------------------------------------------------
63
    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
        port = self.get_output_port(port_name)
73
74
        if port not in ports:
75
            if level:
76
                ports.append(port)
77
78
        self.get_implicit_dependencies_input_ports(self.ALL_PORT_NAME, ports, level + 1)
79
80
    # ------------------------------------------------------------------------------------------------------------------
81
    def append_argument(self, argument):
82
        """
83
        Appends an argument to the list of arguments of the command.
84
85
        :param str argument: The argument.
86
        """
87
        self.args.append(argument)
88
89
    # ------------------------------------------------------------------------------------------------------------------
90
    def set_path(self, path):
91
        """
92
        Set the path to the executable that must be run by this job.
93
94
        :param str path: The path to the executable that must be run by this job
95
        """
96
        self.path = path
97
98
# ----------------------------------------------------------------------------------------------------------------------
99