1 # Copyright (C) 2008 Novell Inc. All rights reserved.
2 # This program is free software; it may be used, copied, modified
3 # and distributed under the terms of the GNU General Public Licence,
4 # either version 2, or (at your option) any later version.
10 from urllib2 import URLError, HTTPError
11 from oscsslexcp import NoSecureSSLError
12 from osc.util.cpio import CpioError
13 from osc.util.packagequery import PackageError
16 from M2Crypto.SSL.Checker import SSLVerificationError
17 from M2Crypto.SSL import SSLError as SSLError
20 SSLVerificationError = None
23 # import as RPMError because the class "error" is too generic
24 from rpm import error as RPMError
26 # if rpm-python isn't installed (we might be on a debian system):
30 # the good things are stolen from Matt Mackall's mercurial
33 raise oscerr.SignalInterrupt
35 for name in 'SIGBREAK', 'SIGHUP', 'SIGTERM':
36 num = getattr(signal, name, None)
37 if num: signal.signal(num, catchterm)
45 if '--debugger' in sys.argv:
49 # here we actually run the program:
53 # look for an option in the prg.options object and in the config dict
54 # print stack trace, if desired
55 if getattr(prg.options, 'traceback', None) or getattr(prg.conf, 'config', {}).get('traceback', None) or \
56 getattr(prg.options, 'post_mortem', None) or getattr(prg.conf, 'config', {}).get('post_mortem', None):
58 traceback.print_exc(file=sys.stderr)
59 # we could use http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52215
61 # enter the debugger, if desired
62 if getattr(prg.options, 'post_mortem', None) or getattr(prg.conf, 'config', {}).get('post_mortem', None):
63 if sys.stdout.isatty() and not hasattr(sys, 'ps1'):
65 pdb.post_mortem(sys.exc_info()[2])
67 print >>sys.stderr, 'sys.stdout is not a tty. Not jumping into pdb.'
70 except oscerr.SignalInterrupt:
71 print >>sys.stderr, 'killed!'
74 except KeyboardInterrupt:
75 print >>sys.stderr, 'interrupted!'
78 except oscerr.UserAbort:
79 print >>sys.stderr, 'aborted.'
82 except oscerr.APIError, e:
83 print >>sys.stderr, 'BuildService API error:', e.msg
86 except oscerr.LinkExpandError, e:
87 print >>sys.stderr, 'Link "%s/%s" cannot be expanded:\n' % (e.prj, e.pac), e.msg
88 print >>sys.stderr, 'Use "osc repairlink" to fix merge conflicts.\n'
91 except oscerr.WorkingCopyWrongVersion, e:
94 except oscerr.NoWorkingCopy, e:
96 if os.path.isdir('.git'): print >>sys.stderr, "Current directory looks like git."
97 if os.path.isdir('.hg'): print >>sys.stderr, "Current directory looks like mercurial."
98 if os.path.isdir('.svn'): print >>sys.stderr, "Current directory looks like svn."
99 if os.path.isdir('CVS'): print >>sys.stderr, "Current directory looks like cvs."
103 print >>sys.stderr, 'Server returned an error:', e
104 if hasattr(e, 'osc_msg'):
105 print >>sys.stderr, e.osc_msg
109 except AttributeError:
112 if getattr(prg.options, 'debug', None) or \
113 getattr(prg.conf, 'config', {}).get('debug', None):
114 print >>sys.stderr, e.hdrs
115 print >>sys.stderr, body
117 if e.code in [ 400, 403, 404, 500 ]:
118 if '<summary>' in body:
119 msg = body.split('<summary>')[1]
120 msg = msg.split('</summary>')[0]
121 print >>sys.stderr, msg
126 print >>sys.stderr, 'Failed to reach a server:\n', e.reason
129 except (oscerr.ConfigError, oscerr.NoConfigfile), e:
130 print >>sys.stderr, e.msg
133 except oscerr.OscIOError, e:
134 print >>sys.stderr, e.msg
135 if getattr(prg.options, 'debug', None) or \
136 getattr(prg.conf, 'config', {}).get('debug', None):
137 print >>sys.stderr, e.e
140 except (oscerr.WrongOptions, oscerr.WrongArgs), e:
141 print >>sys.stderr, e
144 except oscerr.ExtRuntimeError, e:
145 print >>sys.stderr, e.msg
148 except oscerr.WorkingCopyOutdated, e:
149 print >>sys.stderr, e
152 except (oscerr.PackageExists, oscerr.PackageMissing, oscerr.WorkingCopyInconsistent), e:
153 print >>sys.stderr, e.msg
156 except oscerr.PackageInternalError, e:
158 print >>sys.stderr, 'a package internal error occured\n' \
159 'please file a bug and attach your current package working copy ' \
160 'and the following traceback to it:'
161 print >>sys.stderr, e.msg
162 traceback.print_exc(file=sys.stderr)
164 except oscerr.PackageError, e:
165 print >>sys.stderr, e.msg
168 except PackageError, e:
169 print >>sys.stderr, '%s:' % e.fname, e.msg
173 print >>sys.stderr, e
177 print >>sys.stderr, "SSL Error:", e
180 except SSLVerificationError, e:
181 print >>sys.stderr, "Certificate Verification Error:", e
184 except NoSecureSSLError, e:
185 print >>sys.stderr, e
189 print >>sys.stderr, e