1 # -*- coding: utf-8 -*-
10 A new format named 'foo-bar' corresponds to Python module
11 'tracetool/format/foo_bar.py'.
13 A format module should provide a docstring, whose first non-empty line will be
14 considered its short description.
16 All formats must generate their contents through the 'tracetool.out' routine.
22 ======== ==================================================================
24 ======== ==================================================================
25 generate Called to generate a format-specific file.
26 ======== ==================================================================
32 __license__ = "GPL version 2 or (at your option) any later version"
34 __maintainer__ = "Stefan Hajnoczi"
44 """Get a list of (name, description) pairs."""
47 for filename in os.listdir(tracetool.format.__path__[0]):
48 if filename.endswith('.py') and filename != '__init__.py':
49 modnames.append(filename.rsplit('.', 1)[0])
50 for modname in sorted(modnames):
51 module = tracetool.try_import("tracetool.format." + modname)
53 # just in case; should never fail unless non-module files are put there
61 doc = doc.strip().split("\n")[0]
63 name = modname.replace("_", "-")
64 res.append((name, doc))
69 """Return whether the given format exists."""
72 name = name.replace("-", "_")
73 return tracetool.try_import("tracetool.format." + name)[1]
76 def generate(events, format, backend, group):
77 if not exists(format):
78 raise ValueError("unknown format: %s" % format)
79 format = format.replace("-", "_")
80 func = tracetool.try_import("tracetool.format." + format,
83 raise AttributeError("format has no 'generate': %s" % format)
84 func(events, backend, group)