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
108 if getattr(prg.options, 'debug', None) or \
109 getattr(prg.conf, 'config', {}).get('debug', None):
110 print >>sys.stderr, e.hdrs
111 print >>sys.stderr, body
113 if e.code in [ 400, 403, 404, 500 ]:
114 if '<summary>' in body:
115 msg = body.split('<summary>')[1]
116 msg = msg.split('</summary>')[0]
117 print >>sys.stderr, msg
122 print >>sys.stderr, 'Failed to reach a server:\n', e.reason
125 except (oscerr.ConfigError, oscerr.NoConfigfile), e:
126 print >>sys.stderr, e.msg
129 except oscerr.OscIOError, e:
130 print >>sys.stderr, e.msg
131 if getattr(prg.options, 'debug', None) or \
132 getattr(prg.conf, 'config', {}).get('debug', None):
133 print >>sys.stderr, e.e
136 except (oscerr.WrongOptions, oscerr.WrongArgs), e:
137 print >>sys.stderr, e
140 except oscerr.WorkingCopyOutdated, e:
141 print >>sys.stderr, e
144 except (oscerr.PackageExists, oscerr.PackageMissing), e:
145 print >>sys.stderr, e.msg
148 except AttributeError, e:
149 print >>sys.stderr, e
153 print >>sys.stderr, e
157 print >>sys.stderr, "SSL Error:", e
160 except SSLVerificationError, e:
161 print >>sys.stderr, "Certificate Verification Error:", e
164 except NoSecureSSLError, e:
165 print >>sys.stderr, e
169 print >>sys.stderr, e
173 print >>sys.stderr, e
176 except PackageError, e:
177 print >>sys.stderr, e.msg