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.
Passed
Push — master ( fbdd84...45bad2 )
by P.R.
04:28
created

LogFileMessageEventHandler.handle()   D

Complexity

Conditions 11

Size

Total Lines 62

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 132

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 11
c 1
b 0
f 0
dl 0
loc 62
ccs 0
cts 32
cp 0
crap 132
rs 4.0298

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Complexity

Complex classes like LogFileMessageEventHandler.handle() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
"""
2
Enarksh
3
4
Copyright 2013-2016 Set Based IT Consultancy
5
6
Licence MIT
7
"""
8
import os
9
10
from enarksh.DataLayer import DataLayer
11
12
13
class LogFileMessageEventHandler:
14
    """
15
    An event handler for a LogFileMessage received events.
16
    """
17
    @staticmethod
18
    # ------------------------------------------------------------------------------------------------------------------
19
    def handle(_event, message, _listener_data):
20
        """
21
        Handles a LogFileMessage received event.
22
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
23
        :param * _event: Not used.
24
        :param enarksh.message.logger.LogFileMessage.LogFileMessage message: The message.
25
        :param * _listener_data: Not used.
26
        """
27
        del _event, _listener_data
28
29
        print("%s %s %s" % (message.rnd_id, message.name, message.total_size))
30
31
        DataLayer.connect()
32
33
        if message.total_size > 0:
34
            # Read the log file or log files and concatenate if necessary.
35
            with open(message.filename1, 'rb') as f:
0 ignored issues
show
Coding Style Naming introduced by
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.

Loading history...
36
                log = f.read()
37
38
            if message.filename2:
39
                with open(message.filename2, 'rb') as f:
0 ignored issues
show
Coding Style Naming introduced by
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.

Loading history...
40
                    buf2 = f.read()
41
            else:
42
                buf2 = ''
43
44
            # Compute the number of skipped bytes.
45
            skipped = message.total_size - len(log) - len(buf2)
46
47
            if skipped != 0:
48
                # Add a newline to the end of the buffer, if required.
49
                if log[-1:] != '\n':
50
                    log += '\n'
51
52
                    # Note: This concatenation doesn't work for multi byte character sets.
53
                    log += '\n'
54
                    log += "Enarksh: Skipped {0} bytes.\n".format(skipped)
55
                    log += '\n'
56
57
                log += buf2
58
59
            blb_id = DataLayer.enk_blob_insert_blob(message.name, 'text/plain', log)
60
61
        else:
62
            blb_id = None
63
64
        if message.name == 'out':
65
            DataLayer.enk_back_run_node_update_log(message.rnd_id, blb_id, message.total_size)
66
        elif message.name == 'err':
67
            DataLayer.enk_back_run_node_update_err(message.rnd_id, blb_id, message.total_size)
68
        else:
69
            raise ValueError("Unknown output name '%s'" % message.name)
70
71
        # Remove the (temporary) log files.
72
        if message.filename1:
73
            os.unlink(message.filename1)
74
        if message.filename2:
75
            os.unlink(message.filename2)
76
77
        DataLayer.commit()
78
        DataLayer.disconnect()
79
80
# ----------------------------------------------------------------------------------------------------------------------
81