db_sync_tool.utility.info   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 11
eloc 51
dl 0
loc 89
rs 10
c 0
b 0
f 0

4 Functions

Rating   Name   Duplication   Size   Complexity  
A print_header() 0 23 2
B print_footer() 0 21 6
A check_updates() 0 17 2
A get_random_colors() 0 7 1
1
#!/usr/bin/env python3
0 ignored issues
show
Documentation introduced by
Empty module docstring
Loading history...
2
# -*- coding: future_fstrings -*-
3
4
"""
5
6
"""
7
import requests
8
import semantic_version
9
import random
0 ignored issues
show
introduced by
standard import "import random" should be placed before "import requests"
Loading history...
10
from db_sync_tool.utility import mode, system, output
11
from db_sync_tool import info
12
13
14
def print_header(mute):
15
    """
16
    Printing console header
17
    :param mute: Boolean
18
    :return:
19
    """
20
    # pylint: max-line-length=240
0 ignored issues
show
introduced by
Unrecognized file option 'max-line-length'
Loading history...
21
    if mute is False:
22
        _colors = get_random_colors()
23
        print(
24
            output.CliFormat.BLACK + '##############################################' + output.CliFormat.ENDC)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (110/100).

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

Loading history...
25
        print(
26
            output.CliFormat.BLACK + '#                                            #' + output.CliFormat.ENDC)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (110/100).

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

Loading history...
27
        print(
28
            output.CliFormat.BLACK + '#' + output.CliFormat.ENDC + '              ' + _colors[0] + '⥣ ' + _colors[1] + '⥥ ' + output.CliFormat.ENDC + ' db sync tool             ' + output.CliFormat.BLACK + '#' + output.CliFormat.ENDC)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (234/100).

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

Loading history...
29
        print(
30
            output.CliFormat.BLACK + '#                   v' + info.__version__ + '                  #' + output.CliFormat.ENDC)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (128/100).

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

Loading history...
31
        print(output.CliFormat.BLACK + '#  ' + info.__homepage__ + '  #' + output.CliFormat.ENDC)
32
        print(
33
            output.CliFormat.BLACK + '#                                            #' + output.CliFormat.ENDC)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (110/100).

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

Loading history...
34
        print(
35
            output.CliFormat.BLACK + '##############################################' + output.CliFormat.ENDC)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (110/100).

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

Loading history...
36
        check_updates()
37
38
39
def check_updates():
40
    """
41
    Check for updates of the db_sync_tool
42
    :return:
43
    """
44
    try:
45
        response = requests.get(f'{info.__pypi_package_url__}/json')
46
        latest_version = response.json()['info']['version']
47
        if semantic_version.Version(info.__version__) < semantic_version.Version(latest_version):
48
            output.message(
49
                output.Subject.WARNING,
50
                f'A new version {output.CliFormat.BOLD}v{latest_version}{output.CliFormat.ENDC} is '
51
                f'available for the db-sync-tool: {info.__pypi_package_url__}',
52
                True
53
            )
54
    finally:
55
        return
0 ignored issues
show
Bug Best Practice introduced by
return statements in finally blocks should be avoided.

Placing a return statement inside finally will swallow all exceptions that may have been thrown in the try block.

Loading history...
56
57
58
def print_footer():
59
    """
60
    Printing console footer
61
    :return:
62
    """
63
    if system.config['dry_run']:
64
        _message = 'Successfully executed dry run'
65
    elif not system.config['keep_dump'] and \
66
            not system.config['is_same_client'] and \
67
            not mode.is_import():
68
        _message = 'Successfully synchronized databases'
69
    elif mode.is_import():
70
        _message = 'Successfully imported database dump'
71
    else:
72
        _message = 'Successfully created database dump'
73
74
    output.message(
75
        output.Subject.INFO,
76
        _message,
77
        True,
78
        True
79
    )
80
81
82
def get_random_colors():
83
    """
84
    Generate a tuple of random console colors
85
    :return:
86
    """
87
    _colors = [output.CliFormat.BEIGE, output.CliFormat.PURPLE, output.CliFormat.BLUE, output.CliFormat.YELLOW, output.CliFormat.GREEN, output.CliFormat.RED]
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (157/100).

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

Loading history...
88
    return random.sample(_colors, 2)
89
0 ignored issues
show
coding-style introduced by
Trailing newlines
Loading history...
90