| Total Complexity | 10 |
| Total Lines | 77 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | #!/usr/bin/env python3 |
||
|
|
|||
| 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 |
||
| 20 | if mute is False: |
||
| 21 | print( |
||
| 22 | output.CliFormat.BLACK + '##############################################' + output.CliFormat.ENDC) |
||
| 23 | print( |
||
| 24 | output.CliFormat.BLACK + '# #' + output.CliFormat.ENDC) |
||
| 25 | print( |
||
| 26 | output.CliFormat.BLACK + '#' + output.CliFormat.ENDC + ' db sync tool ' + output.CliFormat.BLACK + '#' + output.CliFormat.ENDC) |
||
| 27 | print( |
||
| 28 | output.CliFormat.BLACK + '# v' + info.__version__ + ' #' + output.CliFormat.ENDC) |
||
| 29 | print(output.CliFormat.BLACK + '# ' + info.__homepage__ + ' #' + output.CliFormat.ENDC) |
||
| 30 | print( |
||
| 31 | output.CliFormat.BLACK + '# #' + output.CliFormat.ENDC) |
||
| 32 | print( |
||
| 33 | output.CliFormat.BLACK + '##############################################' + output.CliFormat.ENDC) |
||
| 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 |
||
| 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 |