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

coalib/misc/Exceptions.py (6 issues)

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
The variable KeyboardInterrupt does not seem to be defined.
Loading history...
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
The variable EOFError does not seem to be defined.
Loading history...
16
        print("Found EOF. Exiting gracefully.")
17
        exitcode = 0
18
    elif isinstance(exception, SystemExit):
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable SystemExit does not seem to be defined.
Loading history...
19
        exitcode = exception.code
20
    elif isinstance(exception, VersionConflict):
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable VersionConflict does not seem to be defined.
Loading history...
21
        log_message = Constants.VERSION_CONFLICT_MESSAGE % str(exception.req)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable Constants does not seem to be defined.
Loading history...
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
The variable BaseException does not seem to be defined.
Loading history...
25
        log_printer.log_exception(Constants.CRASH_MESSAGE, exception)
26
        exitcode = 255
27
    else:
28
        exitcode = 0
29
30
    return exitcode
31