2 # -*- coding: utf-8 -*-
11 A new format named 'foo-bar' corresponds to Python module
12 'tracetool/format/foo_bar.py'.
14 A format module should provide a docstring, whose first non-empty line will be
15 considered its short description.
17 All formats must generate their contents through the 'tracetool.out' routine.
23 ======== ==================================================================
25 ======== ==================================================================
26 generate Called to generate a format-specific file.
27 ======== ==================================================================
31 __author__
= "Lluís Vilanova <vilanova@ac.upc.edu>"
32 __copyright__
= "Copyright 2012-2014, Lluís Vilanova <vilanova@ac.upc.edu>"
33 __license__
= "GPL version 2 or (at your option) any later version"
35 __maintainer__
= "Stefan Hajnoczi"
36 __email__
= "stefanha@linux.vnet.ibm.com"
45 """Get a list of (name, description) pairs."""
48 for filename
in os
.listdir(tracetool
.format
.__path
__[0]):
49 if filename
.endswith('.py') and filename
!= '__init__.py':
50 modnames
.append(filename
.rsplit('.', 1)[0])
51 for modname
in sorted(modnames
):
52 module
= tracetool
.try_import("tracetool.format." + modname
)
54 # just in case; should never fail unless non-module files are put there
62 doc
= doc
.strip().split("\n")[0]
64 name
= modname
.replace("_", "-")
65 res
.append((name
, doc
))
70 """Return whether the given format exists."""
73 name
= name
.replace("-", "_")
74 return tracetool
.try_import("tracetool.format." + name
)[1]
77 def generate(events
, format
, backend
, group
):
78 if not exists(format
):
79 raise ValueError("unknown format: %s" % format
)
80 format
= format
.replace("-", "_")
81 func
= tracetool
.try_import("tracetool.format." + format
,
84 raise AttributeError("format has no 'generate': %s" % format
)
85 func(events
, backend
, group
)