Show More
@@ -261,24 +261,26 b' class plainformatter(baseformatter):' | |||||
261 | pass |
|
261 | pass | |
262 |
|
262 | |||
263 | class debugformatter(baseformatter): |
|
263 | class debugformatter(baseformatter): | |
264 | def __init__(self, ui, topic, opts): |
|
264 | def __init__(self, ui, out, topic, opts): | |
265 | baseformatter.__init__(self, ui, topic, opts, _nullconverter) |
|
265 | baseformatter.__init__(self, ui, topic, opts, _nullconverter) | |
266 | self._ui.write("%s = [\n" % self._topic) |
|
266 | self._out = out | |
|
267 | self._out.write("%s = [\n" % self._topic) | |||
267 | def _showitem(self): |
|
268 | def _showitem(self): | |
268 |
self._ |
|
269 | self._out.write(" " + repr(self._item) + ",\n") | |
269 | def end(self): |
|
270 | def end(self): | |
270 | baseformatter.end(self) |
|
271 | baseformatter.end(self) | |
271 |
self._ |
|
272 | self._out.write("]\n") | |
272 |
|
273 | |||
273 | class pickleformatter(baseformatter): |
|
274 | class pickleformatter(baseformatter): | |
274 | def __init__(self, ui, topic, opts): |
|
275 | def __init__(self, ui, out, topic, opts): | |
275 | baseformatter.__init__(self, ui, topic, opts, _nullconverter) |
|
276 | baseformatter.__init__(self, ui, topic, opts, _nullconverter) | |
|
277 | self._out = out | |||
276 | self._data = [] |
|
278 | self._data = [] | |
277 | def _showitem(self): |
|
279 | def _showitem(self): | |
278 | self._data.append(self._item) |
|
280 | self._data.append(self._item) | |
279 | def end(self): |
|
281 | def end(self): | |
280 | baseformatter.end(self) |
|
282 | baseformatter.end(self) | |
281 |
self._ |
|
283 | self._out.write(pickle.dumps(self._data)) | |
282 |
|
284 | |||
283 | def _jsonifyobj(v): |
|
285 | def _jsonifyobj(v): | |
284 | if isinstance(v, dict): |
|
286 | if isinstance(v, dict): | |
@@ -299,28 +301,29 b' def _jsonifyobj(v):' | |||||
299 | return '"%s"' % encoding.jsonescape(v) |
|
301 | return '"%s"' % encoding.jsonescape(v) | |
300 |
|
302 | |||
301 | class jsonformatter(baseformatter): |
|
303 | class jsonformatter(baseformatter): | |
302 | def __init__(self, ui, topic, opts): |
|
304 | def __init__(self, ui, out, topic, opts): | |
303 | baseformatter.__init__(self, ui, topic, opts, _nullconverter) |
|
305 | baseformatter.__init__(self, ui, topic, opts, _nullconverter) | |
304 |
self._ |
|
306 | self._out = out | |
|
307 | self._out.write("[") | |||
305 | self._ui._first = True |
|
308 | self._ui._first = True | |
306 | def _showitem(self): |
|
309 | def _showitem(self): | |
307 | if self._ui._first: |
|
310 | if self._ui._first: | |
308 | self._ui._first = False |
|
311 | self._ui._first = False | |
309 | else: |
|
312 | else: | |
310 |
self._ |
|
313 | self._out.write(",") | |
311 |
|
314 | |||
312 |
self._ |
|
315 | self._out.write("\n {\n") | |
313 | first = True |
|
316 | first = True | |
314 | for k, v in sorted(self._item.items()): |
|
317 | for k, v in sorted(self._item.items()): | |
315 | if first: |
|
318 | if first: | |
316 | first = False |
|
319 | first = False | |
317 | else: |
|
320 | else: | |
318 |
self._ |
|
321 | self._out.write(",\n") | |
319 |
self._ |
|
322 | self._out.write(' "%s": %s' % (k, _jsonifyobj(v))) | |
320 |
self._ |
|
323 | self._out.write("\n }") | |
321 | def end(self): |
|
324 | def end(self): | |
322 | baseformatter.end(self) |
|
325 | baseformatter.end(self) | |
323 |
self._ |
|
326 | self._out.write("\n]\n") | |
324 |
|
327 | |||
325 | class _templateconverter(object): |
|
328 | class _templateconverter(object): | |
326 | '''convert non-primitive data types to be processed by templater''' |
|
329 | '''convert non-primitive data types to be processed by templater''' | |
@@ -346,8 +349,9 b' class _templateconverter(object):' | |||||
346 | lambda d: fmt % d[name]) |
|
349 | lambda d: fmt % d[name]) | |
347 |
|
350 | |||
348 | class templateformatter(baseformatter): |
|
351 | class templateformatter(baseformatter): | |
349 | def __init__(self, ui, topic, opts): |
|
352 | def __init__(self, ui, out, topic, opts): | |
350 | baseformatter.__init__(self, ui, topic, opts, _templateconverter) |
|
353 | baseformatter.__init__(self, ui, topic, opts, _templateconverter) | |
|
354 | self._out = out | |||
351 | self._topic = topic |
|
355 | self._topic = topic | |
352 | self._t = gettemplater(ui, topic, opts.get('template', ''), |
|
356 | self._t = gettemplater(ui, topic, opts.get('template', ''), | |
353 | cache=templatekw.defaulttempl) |
|
357 | cache=templatekw.defaulttempl) | |
@@ -371,7 +375,7 b' class templateformatter(baseformatter):' | |||||
371 | else: |
|
375 | else: | |
372 | props = self._item |
|
376 | props = self._item | |
373 | g = self._t(self._topic, ui=self._ui, cache=self._cache, **props) |
|
377 | g = self._t(self._topic, ui=self._ui, cache=self._cache, **props) | |
374 |
self._ |
|
378 | self._out.write(templater.stringify(g)) | |
375 |
|
379 | |||
376 | def lookuptemplate(ui, topic, tmpl): |
|
380 | def lookuptemplate(ui, topic, tmpl): | |
377 | # looks like a literal template? |
|
381 | # looks like a literal template? | |
@@ -423,17 +427,17 b' def maketemplater(ui, topic, tmpl, cache' | |||||
423 | def formatter(ui, topic, opts): |
|
427 | def formatter(ui, topic, opts): | |
424 | template = opts.get("template", "") |
|
428 | template = opts.get("template", "") | |
425 | if template == "json": |
|
429 | if template == "json": | |
426 | return jsonformatter(ui, topic, opts) |
|
430 | return jsonformatter(ui, ui, topic, opts) | |
427 | elif template == "pickle": |
|
431 | elif template == "pickle": | |
428 | return pickleformatter(ui, topic, opts) |
|
432 | return pickleformatter(ui, ui, topic, opts) | |
429 | elif template == "debug": |
|
433 | elif template == "debug": | |
430 | return debugformatter(ui, topic, opts) |
|
434 | return debugformatter(ui, ui, topic, opts) | |
431 | elif template != "": |
|
435 | elif template != "": | |
432 | return templateformatter(ui, topic, opts) |
|
436 | return templateformatter(ui, ui, topic, opts) | |
433 | # developer config: ui.formatdebug |
|
437 | # developer config: ui.formatdebug | |
434 | elif ui.configbool('ui', 'formatdebug'): |
|
438 | elif ui.configbool('ui', 'formatdebug'): | |
435 | return debugformatter(ui, topic, opts) |
|
439 | return debugformatter(ui, ui, topic, opts) | |
436 | # deprecated config: ui.formatjson |
|
440 | # deprecated config: ui.formatjson | |
437 | elif ui.configbool('ui', 'formatjson'): |
|
441 | elif ui.configbool('ui', 'formatjson'): | |
438 | return jsonformatter(ui, topic, opts) |
|
442 | return jsonformatter(ui, ui, topic, opts) | |
439 | return plainformatter(ui, topic, opts) |
|
443 | return plainformatter(ui, topic, opts) |
General Comments 0
You need to be logged in to leave comments.
Login now