1
2
3
4
5
6
7
8
9
10
11
12
13
14 import sys
15 import traceback
16 import types
17
18 from conary import errors
19 from conary.lib import log, api
20
22 f._passExceptions = True
23 return f
24
26 def wrapper(*args, **kwargs):
27 if hasattr(method, '_passExceptions') and method._passExceptions:
28 return method(*args, **kwargs)
29
30 try:
31 return method(*args, **kwargs)
32 except Exception, e:
33 exc_info = sys.exc_info()
34 if errors.exceptionIsUncatchable(e):
35 raise
36 exceptionCallback(exc_info)
37
38 return wrapper
39
41
43 etype, e, tb = exc_info
44
45 msg = '%s' % etype.__name__
46 s = str(e)
47 if s:
48 msg += ': %s' % s
49
50 inner = tb.tb_next
51 while inner.tb_next:
52 inner = inner.tb_next
53 filename = inner.tb_frame.f_code.co_filename
54 linenum = inner.tb_frame.f_lineno
55 log.warning('Unhandled exception occurred when invoking callback:\n'
56 '%s:%s\n'
57 ' %s', filename, linenum, msg)
58
59 log.debug(''.join(traceback.format_exception(*exc_info)))
60 if not hasattr(self, 'exceptions'):
61 self.exceptions = []
62 self.exceptions.append(e)
63
72
74 """Return True if we should cancel the operation as soon as it is
75 safely possible"""
76 if not hasattr(self, 'exceptions'):
77 return False
78 for exc in self.exceptions:
79 if hasattr(exc, 'cancelOperation'):
80 return exc.cancelOperation
81 return False
82
85
87
89 """
90 Called before an update begins and before it looks for the requested
91 troves.
92
93 @return: None
94 """
95 pass
96
98 """
99 Called right before requesting a changeset from a repository.
100 @return: None
101 """
102 pass
103
106
109
111 """
112 Called when downloading a changeset.
113 @param got: number of bytes received so far.
114 @type got: integer
115 @param need: number of bytes total to be retrieved.
116 @type need: integer
117 @return: None
118 """
119 pass
120
122 """
123 Called right before requesting file contents from a repository.
124 @return: None
125 """
126 pass
127
128 - def downloadingFileContents(self, got, need):
129 """
130 Called when downloading file contents.
131 @param got: number of bytes received so far.
132 @type got: integer
133 @param need: number of bytes total to be retrieved
134 @type need: integer
135 @return: None
136 """
137 pass
138
140 """
141 Called when creating changesets, such as when downloading changesets.
142 @param hunk: the number of the changeset being created (starts at 1)
143 @type hunk: integer
144 @param hunkCount: total number of changesets to be created.
145 @type hunkCount: integer
146 @return: None
147 """
148 pass
149
152
155
156 - def error(self, msg, *args, **kwargs):
157 """Error handling callback
158
159 @param msg: A message to display
160 @type msg: str
161 @keyword exc_text: Traceback text that should be printed verbatim
162 @type exc_text: str
163 """
164 exc_text = kwargs.pop('exc_text', None)
165
166 if exc_text:
167 msg += "\n%s"
168 args += (exc_text, )
169 return log.error(msg, *args, **kwargs)
170
171 - def warning(self, msg, *args, **kwargs):
172 """Warning handling callback
173
174 @param msg: A message to display
175 @type msg: str
176 @keyword exc_text: Traceback text that should be printed verbatim
177 @type exc_text: str
178 """
179 exc_text = kwargs.pop('exc_text', None)
180
181 if exc_text:
182 msg += "\n%s"
183 args += (exc_text, )
184 return log.warning(msg, *args, **kwargs)
185
187 """This callback gets called if missing files were detected in the
188 upstream server
189 @param missingFiles: a list of tuples:
190 (troveName, troveVersion, troveFlavor, pathId, path, fileId, version)
191 """
192 return False
193