aboutsummaryrefslogtreecommitdiff
blob: a9a56432c2360903af2f1f023ab62fa606369644 (plain)
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
#!/usr/bin/python
# Copyright 2006-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

from __future__ import print_function

import platform
import signal
import sys
# This block ensures that ^C interrupts are handled quietly.
try:

	def exithandler(signum,frame):
		signal.signal(signal.SIGINT, signal.SIG_IGN)
		signal.signal(signal.SIGTERM, signal.SIG_IGN)
		sys.exit(128 + signum)

	signal.signal(signal.SIGINT, exithandler)
	signal.signal(signal.SIGTERM, exithandler)
	# Prevent "[Errno 32] Broken pipe" exceptions when
	# writing to a pipe.
	signal.signal(signal.SIGPIPE, signal.SIG_DFL)

except KeyboardInterrupt:
	sys.exit(128 + signal.SIGINT)

def debug_signal(signum, frame):
	import pdb
	pdb.set_trace()

if platform.python_implementation() == 'Jython':
	debug_signum = signal.SIGUSR2 # bug #424259
else:
	debug_signum = signal.SIGUSR1

signal.signal(debug_signum, debug_signal)

try:
	from _emerge.main import emerge_main
except ImportError:
	from os import path as osp
	import sys
	sys.path.insert(0, osp.join(osp.dirname(osp.dirname(osp.realpath(__file__))), "pym"))
	from _emerge.main import emerge_main

if __name__ == "__main__":
	import sys
	from portage.exception import ParseError, PermissionDenied
	try:
		retval = emerge_main()
	except PermissionDenied as e:
		sys.stderr.write("Permission denied: '%s'\n" % str(e))
		sys.exit(e.errno)
	except ParseError as e:
		sys.stderr.write("%s\n" % str(e))
		sys.exit(1)
	except SystemExit:
		raise
	except Exception:
		# If an unexpected exception occurs then we don't want the mod_echo
		# output to obscure the traceback, so dump the mod_echo output before
		# showing the traceback.
		import traceback
		tb_str = traceback.format_exc()
		try:
			from portage.elog import mod_echo
		except ImportError:
			pass
		else:
			mod_echo.finalize()
		sys.stderr.write(tb_str)
		sys.exit(1)
	sys.exit(retval)