1
|
|
|
#!/usr/bin/env python3 |
|
|
|
|
2
|
|
|
# -*- coding: future_fstrings -*- |
3
|
|
|
|
4
|
|
|
""" |
5
|
|
|
|
6
|
|
|
""" |
7
|
|
|
import requests |
8
|
|
|
import semantic_version |
9
|
|
|
import random |
|
|
|
|
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 |
|
|
|
|
21
|
|
|
if mute is False: |
22
|
|
|
_colors = get_random_colors() |
23
|
|
|
print( |
24
|
|
|
output.CliFormat.BLACK + '##############################################' + output.CliFormat.ENDC) |
|
|
|
|
25
|
|
|
print( |
26
|
|
|
output.CliFormat.BLACK + '# #' + output.CliFormat.ENDC) |
|
|
|
|
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) |
|
|
|
|
29
|
|
|
print( |
30
|
|
|
output.CliFormat.BLACK + '# v' + info.__version__ + ' #' + output.CliFormat.ENDC) |
|
|
|
|
31
|
|
|
print(output.CliFormat.BLACK + '# ' + info.__homepage__ + ' #' + output.CliFormat.ENDC) |
32
|
|
|
print( |
33
|
|
|
output.CliFormat.BLACK + '# #' + output.CliFormat.ENDC) |
|
|
|
|
34
|
|
|
print( |
35
|
|
|
output.CliFormat.BLACK + '##############################################' + output.CliFormat.ENDC) |
|
|
|
|
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 |
|
|
|
|
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] |
|
|
|
|
88
|
|
|
return random.sample(_colors, 2) |
89
|
|
|
|
|
|
|
|
90
|
|
|
|