|
1 | 1 | import sys |
2 | 2 |
|
3 | | -__VERBOSE_MODE = False |
| 3 | +__VERBOSE_MODE: bool = False |
4 | 4 |
|
5 | 5 |
|
6 | | -def set_verbose(enabled): |
| 6 | +def set_verbose(enabled: bool) -> None: |
7 | 7 | global __VERBOSE_MODE |
8 | 8 | __VERBOSE_MODE = enabled |
9 | 9 |
|
10 | 10 |
|
11 | | -def print_message(message): |
| 11 | +def print_message(message: str) -> None: |
12 | 12 | print(message) |
13 | 13 |
|
14 | 14 |
|
15 | | -def print_error_and_exit(error_string): |
| 15 | +def print_error_and_exit(error_string: str) -> None: |
16 | 16 | print_error(error_string) |
17 | 17 | sys.exit(1) |
18 | 18 |
|
19 | 19 |
|
20 | | -def print_error(error_string): |
| 20 | +def print_error(error_string: str) -> None: |
21 | 21 | if _is_interactive_terminal(): |
22 | | - error_string = '%s%s%s' % (BashColors.FAIL, error_string, BashColors.ENDC) |
23 | | - print(error_string) |
| 22 | + print(f"{BashColors.FAIL}{error_string}{BashColors.ENDC}") |
| 23 | + else: |
| 24 | + print(error_string) |
24 | 25 |
|
25 | 26 |
|
26 | | -def print_verbose(message): |
27 | | - if __VERBOSE_MODE: |
28 | | - if _is_interactive_terminal(): |
29 | | - message = '%s%s%s' % (BashColors.WARNING, message, BashColors.ENDC) |
| 27 | +def print_verbose(message: str) -> None: |
| 28 | + if __VERBOSE_MODE and _is_interactive_terminal(): |
| 29 | + print(f"{BashColors.WARNING}{message}{BashColors.ENDC}") |
| 30 | + else: |
30 | 31 | print(message) |
31 | 32 |
|
32 | 33 |
|
33 | | -def _is_interactive_terminal(): |
| 34 | +def _is_interactive_terminal() -> bool: |
34 | 35 | return sys.stdout.isatty() |
35 | 36 |
|
36 | 37 |
|
37 | 38 | # Coloring approach inspired from https://stackoverflow.com/a/287944 |
38 | 39 | # pylint: disable=too-few-public-methods |
39 | 40 | class BashColors: |
40 | | - HEADER = '\033[95m' |
41 | | - OKBLUE = '\033[94m' |
42 | | - OKGREEN = '\033[92m' |
43 | | - WARNING = '\033[93m' |
44 | | - FAIL = '\033[91m' |
45 | | - ENDC = '\033[0m' |
46 | | - BOLD = '\033[1m' |
47 | | - UNDERLINE = '\033[4m' |
| 41 | + HEADER = "\033[95m" |
| 42 | + OKBLUE = "\033[94m" |
| 43 | + OKGREEN = "\033[92m" |
| 44 | + WARNING = "\033[93m" |
| 45 | + FAIL = "\033[91m" |
| 46 | + ENDC = "\033[0m" |
| 47 | + BOLD = "\033[1m" |
| 48 | + UNDERLINE = "\033[4m" |
0 commit comments