|
1
|
|
|
# This program is free software: you can redistribute it and/or modify it |
|
2
|
|
|
# under the terms of the GNU Affero General Public License as published by the |
|
3
|
|
|
# Free Software Foundation, either version 3 of the License, or (at your |
|
4
|
|
|
# option) any later version. |
|
5
|
|
|
# |
|
6
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT |
|
7
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
8
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License |
|
9
|
|
|
# for more details. |
|
10
|
|
|
# |
|
11
|
|
|
# You should have received a copy of the GNU Affero General Public License |
|
12
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
13
|
|
|
|
|
14
|
|
|
import functools |
|
15
|
|
|
|
|
16
|
|
|
from pyprint.ConsolePrinter import ConsolePrinter |
|
17
|
|
|
|
|
18
|
|
|
from coalib.coala_main import run_coala |
|
19
|
|
|
from coalib.collecting.Collectors import ( |
|
20
|
|
|
collect_all_bears_from_sections, filter_section_bears_by_languages) |
|
21
|
|
|
from coalib.misc.Exceptions import get_exitcode |
|
22
|
|
|
from coalib.output.ConsoleInteraction import ( |
|
23
|
|
|
acquire_settings, nothing_done, print_results, print_section_beginning, |
|
24
|
|
|
show_bears) |
|
25
|
|
|
from coalib.output.printers.LogPrinter import LogPrinter |
|
26
|
|
|
from coalib.parsing.DefaultArgParser import default_arg_parser |
|
27
|
|
|
from coalib.settings.ConfigurationGathering import load_configuration |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
def display_bears(args, |
|
31
|
|
|
log_printer, |
|
32
|
|
|
console_printer=ConsolePrinter(), |
|
33
|
|
|
show_json=False): |
|
34
|
|
|
""" |
|
35
|
|
|
Display the bears. |
|
36
|
|
|
:param is_json: True for coala-json else False. |
|
37
|
|
|
""" |
|
38
|
|
|
sections, _ = load_configuration(arg_list=None, |
|
39
|
|
|
log_printer=log_printer) |
|
40
|
|
|
local_bears, global_bears = collect_all_bears_from_sections( |
|
41
|
|
|
sections, log_printer) |
|
42
|
|
|
if args.filter_by_language: |
|
43
|
|
|
local_bears = filter_section_bears_by_languages( |
|
44
|
|
|
local_bears, args.filter_by_language) |
|
45
|
|
|
global_bears = filter_section_bears_by_languages( |
|
46
|
|
|
global_bears, args.filter_by_language) |
|
47
|
|
|
|
|
48
|
|
|
show_bears_data = show_bears(local_bears, |
|
49
|
|
|
global_bears, |
|
50
|
|
|
args.show_description or args.show_details, |
|
51
|
|
|
args.show_details, |
|
52
|
|
|
console_printer, |
|
53
|
|
|
show_json) |
|
54
|
|
|
if show_json: |
|
55
|
|
|
return show_bears_data |
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
def main(): |
|
59
|
|
|
try: |
|
60
|
|
|
console_printer = ConsolePrinter() |
|
61
|
|
|
log_printer = LogPrinter(console_printer) |
|
62
|
|
|
# Note: We parse the args here once to check whether to show bears or |
|
63
|
|
|
# not. |
|
64
|
|
|
args = default_arg_parser().parse_args() |
|
65
|
|
|
|
|
66
|
|
|
if args.show_bears: |
|
67
|
|
|
display_bears(args, |
|
68
|
|
|
log_printer, |
|
69
|
|
|
console_printer) |
|
70
|
|
|
return 0 |
|
71
|
|
|
except BaseException as exception: # pylint: disable=broad-except |
|
72
|
|
|
return get_exitcode(exception, log_printer) |
|
73
|
|
|
|
|
74
|
|
|
partial_print_sec_beg = functools.partial( |
|
75
|
|
|
print_section_beginning, |
|
76
|
|
|
console_printer) |
|
77
|
|
|
results, exitcode, _ = run_coala( |
|
78
|
|
|
print_results=print_results, |
|
79
|
|
|
acquire_settings=acquire_settings, |
|
80
|
|
|
print_section_beginning=partial_print_sec_beg, |
|
81
|
|
|
nothing_done=nothing_done) |
|
82
|
|
|
|
|
83
|
|
|
return exitcode |
|
84
|
|
|
|
|
85
|
|
|
|
|
86
|
|
|
if __name__ == '__main__': # pragma: no cover |
|
87
|
|
|
main() |
|
88
|
|
|
|