Failed Conditions
Pull Request — master (#2076)
by Abdeali
02:04
created

coalib/coala.py (5 issues)

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 collect_all_bears_from_sections
20
from coalib.misc.Exceptions import get_exitcode
21
from coalib.output.ConsoleInteraction import (
22
    acquire_settings, nothing_done, print_results, print_section_beginning,
23
    show_bears)
24
from coalib.output.printers.LogPrinter import LogPrinter
25
from coalib.parsing.DefaultArgParser import default_arg_parser
26
from coalib.settings.ConfigurationGathering import load_configuration
27
from coalib.settings.SectionFilling import fill_settings
28
29
30
def main():
31
    # Note: We parse the args here once to check whether to show bears or not.
32
    arg_parser = default_arg_parser()
33
    args = arg_parser.parse_args()
34
35
    console_printer = ConsolePrinter()
36
    if args.show_bears or args.show_all_bears:
37
        log_printer = LogPrinter(console_printer)
38
        try:
39
            sections, _ = load_configuration(arg_list=None,
40
                                             log_printer=log_printer)
41
            if args.show_all_bears:
42
                local_bears, global_bears = collect_all_bears_from_sections(
43
                    sections, log_printer)
44
            else:
45
                # We ignore missing settings as it's not important.
46
                local_bears, global_bears = fill_settings(
47
                    sections,
48
                    acquire_settings=lambda *args, **kwargs: {},
49
                    log_printer=log_printer)
50
            show_bears(local_bears, global_bears, args.show_all_bears,
51
                       console_printer)
52
        except BaseException as exception:  # pylint: disable=broad-except
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable BaseException does not seem to be defined.
Loading history...
53
            return get_exitcode(exception, log_printer)
54
        return 0
55
56
    partial_print_sec_beg = functools.partial(
57
        print_section_beginning,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable print_section_beginning does not seem to be defined.
Loading history...
58
        console_printer)
59
    results, exitcode, _ = run_coala(
60
        print_results=print_results,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable print_results does not seem to be defined.
Loading history...
61
        acquire_settings=acquire_settings,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable acquire_settings does not seem to be defined.
Loading history...
62
        print_section_beginning=partial_print_sec_beg,
63
        nothing_done=nothing_done)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable nothing_done does not seem to be defined.
Loading history...
64
65
    return exitcode
66