Passed
Push — master ( f57091...64c755 )
by Konrad
08:51
created

db_sync_tool.utility.info.check_updates()   A

Complexity

Conditions 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 17
rs 9.9
c 0
b 0
f 0
cc 2
nop 0
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
from db_sync_tool.utility import mode, system, output
10
from db_sync_tool import info
11
12
13
def print_header(mute):
14
    """
15
    Printing console header
16
    :param mute: Boolean
17
    :return:
18
    """
19
    # pylint: max-line-length=240
0 ignored issues
show
introduced by
Unrecognized file option 'max-line-length'
Loading history...
20
    if mute is False:
21
        print(
22
            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...
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 + '                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 (169/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 + '#                   v' + info.__version__ + '                   #' + output.CliFormat.ENDC)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (129/100).

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

Loading history...
29
        print(output.CliFormat.BLACK + '#  ' + info.__homepage__ + '  #' + output.CliFormat.ENDC)
30
        print(
31
            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...
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
        check_updates()
35
36
37
def check_updates():
38
    """
39
    Check for updates of the db_sync_tool
40
    :return:
41
    """
42
    try:
43
        response = requests.get(f'{info.__pypi_package_url__}/json')
44
        latest_version = response.json()['info']['version']
45
        if semantic_version.Version(info.__version__) < semantic_version.Version(latest_version):
46
            output.message(
47
                output.Subject.WARNING,
48
                f'A new version {output.CliFormat.BOLD}v{latest_version}{output.CliFormat.ENDC} is '
49
                f'available for the db-sync-tool: {info.__pypi_package_url__}',
50
                True
51
            )
52
    finally:
53
        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...
54
55
56
def print_footer():
57
    """
58
    Printing console footer
59
    :return:
60
    """
61
    if system.config['dry_run']:
62
        _message = 'Successfully executed dry run'
63
    elif not system.config['keep_dump'] and \
64
            not system.config['is_same_client'] and \
65
            not mode.is_import():
66
        _message = 'Successfully synchronized databases'
67
    elif mode.is_import():
68
        _message = 'Successfully imported database dump'
69
    else:
70
        _message = 'Successfully created database dump'
71
72
    output.message(
73
        output.Subject.INFO,
74
        _message,
75
        True,
76
        True
77
    )
78