GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

NodeActionClient.__init__()   B
last analyzed

Complexity

Conditions 1

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 26
ccs 0
cts 5
cp 0
crap 2
rs 8.8571
1
"""
2
Enarksh
3
4
Copyright 2013-2016 Set Based IT Consultancy
5
6
Licence MIT
7
"""
8
import zmq
9
10
from enarksh.Config import Config
11
from enarksh.controller.message.NodeActionMessage import NodeActionMessage
12
13
14
class NodeActionClient:
15
    """
16
    A client for requesting the controller for a node action.
17
    """
18
19
    # ------------------------------------------------------------------------------------------------------------------
20
    def __init__(self, io):
21
        """
22
        Object constructor.
23
24
        :param enarksh.style.EnarkshStyle.EnarkshStyle io: The output decorator.
25
        """
26
        self.__zmq_context = None
27
        """
28
        The ZMQ context.
29
30
        :type: Context
31
        """
32
33
        self.__zmq_controller = None
34
        """
35
        The socket for communicating with the controller.
36
37
        :type: zmq.sugar.socket.Socket
38
        """
39
40
        self._io = io
41
        """
42
        The output decorator.
43
44
        :type: enarksh.style.EnarkshStyle.EnarkshStyle
45
        """
46
47
    # ------------------------------------------------------------------------------------------------------------------
48
    def main(self, uri, act_id):
49
        """
50
        The main function of node_action.
51
52
        :param str uri: The URI of the (trigger) node that must be triggered.
53
        :param int act_id: The ID of the requested action.
54
        """
55
        # Initialize ZMQ.
56
        self.__zmq_init()
57
58
        # Compose the message for the controller.
59
        message = NodeActionMessage(uri, act_id)
60
61
        # Send the message to the controller.
62
        self.__zmq_controller.send_pyobj(message)
63
64
        # Await the response from the controller.
65
        response = self.__zmq_controller.recv_pyobj()
66
67
        if response['ret'] == 0:
68
            self._io.log_verbose(response['message'])
69
        else:
70
            self._io.error(response['message'])
71
72
        return response['ret']
73
74
    # ------------------------------------------------------------------------------------------------------------------
75
    def __zmq_init(self):
76
        """
77
        Initializes ZMQ.
78
        """
79
        config = Config.get()
80
81
        self.__zmq_context = zmq.Context()
82
83
        # Create socket for communicating with the controller.
84
        self.__zmq_controller = self.__zmq_context.socket(zmq.REQ)
85
        self.__zmq_controller.connect(config.get_controller_lockstep_end_point())
86
87
# ----------------------------------------------------------------------------------------------------------------------
88