Set the encoding to 'utf_8', if the encoding returned by
[gentoolkit.git] / bin / equery
1 #!/usr/bin/python
2 #
3 # Copyright 2002-2009 Gentoo Technologies, Inc.
4 # Distributed under the terms of the GNU General Public License v2 or later
5 #
6 # $Header$
7
8 """equery is a flexible utility for Gentoo linux which can display various
9 information about packages, such as the files they own, their USE flags,
10 the MD5 sum of each file owned by a given package, and many other things.
11 """
12
13 from __future__ import print_function
14
15 import os
16 import sys
17 # This block ensures that ^C interrupts are handled quietly.
18 try:
19         import signal
20
21         def exithandler(signum,frame):
22                 signal.signal(signal.SIGINT, signal.SIG_IGN)
23                 signal.signal(signal.SIGTERM, signal.SIG_IGN)
24                 print()
25                 sys.exit(1)
26
27         signal.signal(signal.SIGINT, exithandler)
28         signal.signal(signal.SIGTERM, exithandler)
29         signal.signal(signal.SIGPIPE, signal.SIG_DFL)
30
31 except KeyboardInterrupt:
32         print()
33         sys.exit(1)
34
35 from gentoolkit import equery, errors
36
37 try:
38         equery.main()
39 except errors.GentoolkitException as err:
40         if '--debug' in sys.argv or bool(os.getenv('DEBUG', False)):
41                 raise
42         else:
43                 from gentoolkit import pprinter as pp
44                 sys.stderr.write(pp.error(str(err)))
45                 if err.is_serious:
46                         print()
47                         print("Add '--debug' to global options for traceback.")
48                 sys.exit(1)