| Conditions | 7 |
| Total Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | from pyprint.NullPrinter import NullPrinter |
||
| 9 | def get_exitcode(exception, log_printer=None): |
||
| 10 | log_printer = (LogPrinter(NullPrinter()) if log_printer is None |
||
| 11 | else log_printer) |
||
| 12 | |||
| 13 | if isinstance(exception, KeyboardInterrupt): # Ctrl+C |
||
| 14 | print("Program terminated by user.") |
||
| 15 | exitcode = 130 |
||
| 16 | elif isinstance(exception, EOFError): # Ctrl+D |
||
| 17 | print("Found EOF. Exiting gracefully.") |
||
| 18 | exitcode = 0 |
||
| 19 | elif isinstance(exception, SystemExit): |
||
| 20 | exitcode = exception.code |
||
| 21 | elif isinstance(exception, VersionConflict): |
||
| 22 | log_message = Constants.VERSION_CONFLICT_MESSAGE % str(exception.req) |
||
| 23 | log_printer.log_exception(log_message, exception) |
||
| 24 | exitcode = 13 |
||
| 25 | elif isinstance(exception, BaseException): |
||
| 26 | log_printer.log_exception(Constants.CRASH_MESSAGE, exception) |
||
| 27 | exitcode = 255 |
||
| 28 | else: |
||
| 29 | exitcode = 0 |
||
| 30 | |||
| 31 | return exitcode |
||
| 32 |