1 | from pyprint.NullPrinter import NullPrinter |
||
2 | |||
3 | from coalib.misc import Constants |
||
4 | from coalib.output.printers.LogPrinter import LogPrinter |
||
5 | |||
6 | from pkg_resources import VersionConflict |
||
7 | |||
8 | |||
9 | def get_exitcode(exception, log_printer=None): |
||
10 | log_printer = log_printer or LogPrinter(NullPrinter()) |
||
11 | |||
12 | if isinstance(exception, KeyboardInterrupt): # Ctrl+C |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
![]() |
|||
13 | print("Program terminated by user.") |
||
14 | exitcode = 130 |
||
15 | elif isinstance(exception, EOFError): # Ctrl+D |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
16 | print("Found EOF. Exiting gracefully.") |
||
17 | exitcode = 0 |
||
18 | elif isinstance(exception, SystemExit): |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
19 | exitcode = exception.code |
||
20 | elif isinstance(exception, VersionConflict): |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
21 | log_message = Constants.VERSION_CONFLICT_MESSAGE % str(exception.req) |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
22 | log_printer.log_exception(log_message, exception) |
||
23 | exitcode = 13 |
||
24 | elif isinstance(exception, BaseException): |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
25 | log_printer.log_exception(Constants.CRASH_MESSAGE, exception) |
||
26 | exitcode = 255 |
||
27 | else: |
||
28 | exitcode = 0 |
||
29 | |||
30 | return exitcode |
||
31 |