-
Notifications
You must be signed in to change notification settings - Fork 10
/
eopkg.py3
executable file
·82 lines (61 loc) · 1.99 KB
/
eopkg.py3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python3
# SPDX-FileCopyrightText: 2005-2011 TUBITAK/UEKAE, 2013-2017 Ikey Doherty, Solus Project
# SPDX-License-Identifier: GPL-2.0-or-later
import sys
import errno
import traceback
import signal
import pisi
import pisi.context as ctx
import pisi.cli.pisicli as pisicli
from pisi import translate as _
def sig_handler(sig, frame):
if sig == signal.SIGTERM:
exit()
def exit():
sys.exit(1)
def handle_exception(exception, value, tb):
signal.signal(signal.SIGINT, signal.SIG_IGN) # disable further interrupts
ui = pisi.cli.CLI() # make a temporary UI
show_traceback = False
if exception == KeyboardInterrupt:
ui.error(_("Keyboard Interrupt: Exiting..."))
exit()
elif isinstance(value, pisi.Error):
ui.error(_("Program terminated."))
elif isinstance(value, pisi.Exception):
show_traceback = True
ui.error(
_(
"Unhandled internal exception.\n"
"Please file a bug report to <https://github.com/getsolus/package-management/>."
)
)
elif isinstance(value, IOError) and value.errno == errno.EPIPE:
# Ignore broken pipe errors
sys.exit(0)
else:
# For any other exception (possibly Python exceptions) show
# the traceback!
show_traceback = ctx.get_option("debug")
ui.error(_("System error. Program terminated."))
if show_traceback:
ui.error("%s: %s" % (exception, str(value)))
else:
msg = str(value)
if msg:
ui.error(msg)
ui.info(_("Please use 'eopkg help' for general help."))
if show_traceback:
ui.info(_("\nTraceback:"))
traceback.print_tb(tb)
elif not isinstance(value, pisi.Error):
ui.info(_("Use --debug to see a traceback."))
exit()
def main():
sys.excepthook = handle_exception
signal.signal(signal.SIGTERM, sig_handler)
cli = pisicli.PisiCLI()
cli.run_command()
if __name__ == "__main__":
main()