kytos.cli.commands.web.api.WebAPI.update()   A
last analyzed

Complexity

Conditions 4

Size

Total Lines 19
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4.3731

Importance

Changes 0
Metric Value
cc 4
eloc 15
nop 2
dl 0
loc 19
ccs 10
cts 14
cp 0.7143
crap 4.3731
rs 9.65
c 0
b 0
f 0
1
"""Translate cli commands to non-cli code."""
2 1
import logging
3 1
from urllib.error import HTTPError, URLError
4
5 1
import requests
6
7 1
from kytos.utils.config import KytosConfig
8
9 1
LOG = logging.getLogger(__name__)
10
11
12 1
class WebAPI:  # pylint: disable=too-few-public-methods
13
    """An API for the command-line interface."""
14
15 1
    @classmethod
16
    def update(cls, args):
17
        """Call the method to update the Web UI."""
18 1
        kytos_api = KytosConfig().config.get('kytos', 'api')
19 1
        url = f"{kytos_api}api/kytos/core/web/update"
20 1
        version = args["<version>"]
21 1
        if version:
22 1
            url += f"/{version}"
23
24 1
        try:
25 1
            result = requests.post(url)
26
        except(HTTPError, URLError, requests.exceptions.ConnectionError):
27
            LOG.error("Can't connect to server: %s", kytos_api)
28
            return
29
30 1
        if result.status_code != 200:
31 1
            LOG.info("Error while updating web ui: %s", result.content)
32
        else:
33
            LOG.info("Web UI updated.")
34