diff options
Diffstat (limited to 'scripts/pybootchartgui/pybootchartgui/batch.py')
-rw-r--r-- | scripts/pybootchartgui/pybootchartgui/batch.py | 53 |
1 files changed, 38 insertions, 15 deletions
diff --git a/scripts/pybootchartgui/pybootchartgui/batch.py b/scripts/pybootchartgui/pybootchartgui/batch.py index 3c1dbf8416..05c714e95e 100644 --- a/scripts/pybootchartgui/pybootchartgui/batch.py +++ b/scripts/pybootchartgui/pybootchartgui/batch.py | |||
@@ -1,23 +1,46 @@ | |||
1 | import cairo | 1 | # This file is part of pybootchartgui. |
2 | |||
3 | # pybootchartgui is free software: you can redistribute it and/or modify | ||
4 | # it under the terms of the GNU General Public License as published by | ||
5 | # the Free Software Foundation, either version 3 of the License, or | ||
6 | # (at your option) any later version. | ||
7 | |||
8 | # pybootchartgui is distributed in the hope that it will be useful, | ||
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | # GNU General Public License for more details. | ||
2 | 12 | ||
3 | import draw | 13 | # You should have received a copy of the GNU General Public License |
14 | # along with pybootchartgui. If not, see <http://www.gnu.org/licenses/>. | ||
4 | 15 | ||
5 | def render(res, format, filename): | 16 | import cairo |
17 | from . import draw | ||
18 | from .draw import RenderOptions | ||
19 | |||
20 | def render(writer, trace, app_options, filename): | ||
6 | handlers = { | 21 | handlers = { |
7 | "png": (lambda w,h: cairo.ImageSurface(cairo.FORMAT_ARGB32,w,h), lambda sfc: sfc.write_to_png(filename)), | 22 | "png": (lambda w, h: cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h), \ |
8 | "pdf": (lambda w,h: cairo.PDFSurface(filename, w, h), lambda sfc: 0), | 23 | lambda sfc: sfc.write_to_png(filename)), |
9 | "svg": (lambda w,h: cairo.SVGSurface(filename, w, h), lambda sfc: 0) | 24 | "pdf": (lambda w, h: cairo.PDFSurface(filename, w, h), lambda sfc: 0), |
25 | "svg": (lambda w, h: cairo.SVGSurface(filename, w, h), lambda sfc: 0) | ||
10 | } | 26 | } |
11 | 27 | ||
12 | if not(handlers.has_key(format)): | 28 | if app_options.format is None: |
13 | print "Unknown format '%s'." % format | 29 | fmt = filename.rsplit('.', 1)[1] |
30 | else: | ||
31 | fmt = app_options.format | ||
32 | |||
33 | if not (fmt in handlers): | ||
34 | writer.error ("Unknown format '%s'." % fmt) | ||
14 | return 10 | 35 | return 10 |
15 | 36 | ||
16 | make_surface, write_surface = handlers[format] | 37 | make_surface, write_surface = handlers[fmt] |
17 | w,h = draw.extents(res) | 38 | options = RenderOptions (app_options) |
18 | w = max(w, draw.MIN_IMG_W) | 39 | (w, h) = draw.extents (options, 1.0, trace) |
19 | surface = make_surface(w,h) | 40 | w = max (w, draw.MIN_IMG_W) |
20 | ctx = cairo.Context(surface) | 41 | surface = make_surface (w, h) |
21 | draw.render(ctx, res) | 42 | ctx = cairo.Context (surface) |
22 | write_surface(surface) | 43 | draw.render (ctx, options, 1.0, trace) |
44 | write_surface (surface) | ||
45 | writer.status ("bootchart written to '%s'" % filename) | ||
23 | 46 | ||