Passed
Push — master ( 2f86f7...74d48b )
by Markus
01:48
created

tcllib.tclcheck.TclCheckMixin.parse_check()   A

Complexity

Conditions 1

Size

Total Lines 13
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 13
nop 1
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
# -*- coding: utf-8 -*-
0 ignored issues
show
Coding Style introduced by
This module 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.

Loading history...
2
3
import time
4
from collections import OrderedDict
5
import requests
6
from defusedxml import ElementTree
7
8
class TclCheckMixin:
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
9
    def do_check(self, https=True, timeout=10, max_tries=5):
0 ignored issues
show
Coding Style introduced by
This method 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.

Loading history...
10
        protocol = "https://" if https else "http://"
11
        url = protocol + self.g2master + "/check.php"
12
        params = OrderedDict()
13
        params["id"]    = self.serid
0 ignored issues
show
Coding Style introduced by
Exactly one space required before assignment
Loading history...
14
        params["curef"] = self.curef
15
        params["fv"]    = self.fv
0 ignored issues
show
Coding Style introduced by
Exactly one space required before assignment
Loading history...
16
        params["mode"]  = self.mode.value
0 ignored issues
show
Coding Style introduced by
Exactly one space required before assignment
Loading history...
17
        params["type"]  = self.ftype
0 ignored issues
show
Coding Style introduced by
Exactly one space required before assignment
Loading history...
18
        params["cltp"]  = self.cltp.value
0 ignored issues
show
Coding Style introduced by
Exactly one space required before assignment
Loading history...
19
        params["cktp"]  = self.cktp.value
0 ignored issues
show
Coding Style introduced by
Exactly one space required before assignment
Loading history...
20
        params["rtd"]   = self.rtd.value
0 ignored issues
show
Coding Style introduced by
Exactly one space required before assignment
Loading history...
21
        params["chnl"]  = self.chnl.value
0 ignored issues
show
Coding Style introduced by
Exactly one space required before assignment
Loading history...
22
        #params["osvs"]  = self.osvs
23
        #params["ckot"]  = self.ckot.value
24
25
        last_response = None
26
        for num_try in range(0, max_tries):
0 ignored issues
show
Unused Code introduced by
The variable num_try seems to be unused.
Loading history...
27
            try:
28
                reqtime_start = time.perf_counter()
29
                req = self.sess.get(url, params=params, timeout=timeout)
30
                reqtime = time.perf_counter() - reqtime_start
31
                reqtime_avg = self.check_time_avg()
32
                self.check_time_add(reqtime)
33
                last_response = req
34
                if req.status_code == 200:
35
                    self.master_server_vote_on_time(reqtime, reqtime_avg)
36
                    req.encoding = "utf-8"    # Force encoding as server doesn't give one
1 ignored issue
show
Coding Style introduced by
This line is too long as per the coding-style (89/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
37
                    self.write_dump(req.text)
38
                    return req.text
39
                elif req.status_code == 204:
40
                    self.master_server_vote_on_time(reqtime, reqtime_avg)
41
                    raise requests.exceptions.HTTPError("No update available.", response=req)
1 ignored issue
show
Coding Style introduced by
This line is too long as per the coding-style (93/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
42
                elif req.status_code == 404:
43
                    self.master_server_vote_on_time(reqtime, reqtime_avg)
44
                    raise requests.exceptions.HTTPError("No data for requested CUREF/FV combination.", response=req)
1 ignored issue
show
Coding Style introduced by
This line is too long as per the coding-style (116/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
45
                elif req.status_code not in [500, 502, 503]:
46
                    self.master_server_downvote()
47
                    req.raise_for_status()
48
                    raise requests.exceptions.HTTPError("HTTP {}.".format(req.status_code), response=req)
1 ignored issue
show
Coding Style introduced by
This line is too long as per the coding-style (105/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
49
            except requests.exceptions.Timeout:
50
                pass
51
            # Something went wrong, try a different server
52
            self.master_server_downvote()
53
            self.g2master = self.get_master_server()
54
            protocol = "https://" if https else "http://"
55
            url = protocol + self.g2master + "/check.php"
56
        raise requests.exceptions.RetryError("Max tries ({}) reached.".format(max_tries), response=last_response)
1 ignored issue
show
Coding Style introduced by
This line is too long as per the coding-style (113/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
57
58
    @staticmethod
59
    def parse_check(xmlstr):
0 ignored issues
show
Coding Style introduced by
This method 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.

Loading history...
60
        root = ElementTree.fromstring(xmlstr)
61
        curef = root.find("CUREF").text
62
        fv = root.find("VERSION").find("FV").text
0 ignored issues
show
Coding Style Naming introduced by
The name fv does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

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...
63
        tv = root.find("VERSION").find("TV").text
0 ignored issues
show
Coding Style Naming introduced by
The name tv does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

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...
64
        fw_id = root.find("FIRMWARE").find("FW_ID").text
65
        fileinfo = root.find("FIRMWARE").find("FILESET").find("FILE")
66
        fileid   = fileinfo.find("FILE_ID").text
0 ignored issues
show
Coding Style introduced by
Exactly one space required before assignment
Loading history...
67
        filename = fileinfo.find("FILENAME").text
68
        filesize = fileinfo.find("SIZE").text
69
        filehash = fileinfo.find("CHECKSUM").text
70
        return curef, fv, tv, fw_id, fileid, filename, filesize, filehash
71