diff options
author | Stefan Hajnoczi <stefanha@redhat.com> | 2020-08-27 15:29:13 +0100 |
---|---|---|
committer | Stefan Hajnoczi <stefanha@redhat.com> | 2021-01-04 14:24:58 +0000 |
commit | 294170c1ddda454f2d8de65a4a26346fb2a7f715 (patch) | |
tree | e4e43468b40563e45a3bfcd0ef99bd0d4d1e567f /scripts | |
parent | c05012a365c2d7d42d205b1efa895bf2144bab88 (diff) | |
download | qemu-294170c1ddda454f2d8de65a4a26346fb2a7f715.zip qemu-294170c1ddda454f2d8de65a4a26346fb2a7f715.tar.gz qemu-294170c1ddda454f2d8de65a4a26346fb2a7f715.tar.bz2 |
tracetool: add out_lineno and out_next_lineno to out()
Make the output file line number and next line number available to
out().
A later patch will use this to improve error messages.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20200827142915.108730-3-stefanha@redhat.com>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/tracetool/__init__.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py index a601338..da5004e 100644 --- a/scripts/tracetool/__init__.py +++ b/scripts/tracetool/__init__.py @@ -31,6 +31,7 @@ def error(*lines): sys.exit(1) +out_lineno = 1 out_filename = '<none>' out_fobj = sys.stdout @@ -45,12 +46,19 @@ def out(*lines, **kwargs): You can use kwargs as a shorthand for mapping variables when formatting all the strings in lines. - The 'out_filename' kwarg is automatically added with the output filename. + The 'out_lineno' kwarg is automatically added to reflect the current output + file line number. The 'out_next_lineno' kwarg is also automatically added + with the next output line number. The 'out_filename' kwarg is automatically + added with the output filename. """ + global out_lineno output = [] for l in lines: + kwargs['out_lineno'] = out_lineno + kwargs['out_next_lineno'] = out_lineno + 1 kwargs['out_filename'] = out_filename output.append(l % kwargs) + out_lineno += 1 out_fobj.writelines("\n".join(output) + "\n") |