qapi: convert to use python print function instead of statement

Python 3 no longer supports the bare "print" statement, it must be
called as a normal function with round brackets. It is possible to
opt-in to this new syntax with Python 2.6 onwards by importing the
"print_function" from the "__future__" module, making it easy to
support Python 2 and 3 in parallel.

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Message-Id: <20180116134217.8725-2-berrange@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
This commit is contained in:
Daniel P. Berrange 2018-01-16 13:42:04 +00:00 committed by Eduardo Habkost
parent f24ee107a0
commit ef9d910891
3 changed files with 32 additions and 30 deletions

View file

@ -11,6 +11,7 @@
# This work is licensed under the terms of the GNU GPL, version 2.
# See the COPYING file in the top-level directory.
from __future__ import print_function
import errno
import getopt
import os
@ -1467,7 +1468,7 @@ class QAPISchema(object):
self._def_exprs()
self.check()
except QAPIError as err:
print >>sys.stderr, err
print(err, file=sys.stderr)
exit(1)
def _def_entity(self, ent):
@ -1931,7 +1932,7 @@ def parse_command_line(extra_options='', extra_long_options=[]):
['source', 'header', 'prefix=',
'output-dir='] + extra_long_options)
except getopt.GetoptError as err:
print >>sys.stderr, "%s: %s" % (sys.argv[0], str(err))
print("%s: %s" % (sys.argv[0], str(err)), file=sys.stderr)
sys.exit(1)
output_dir = ''
@ -1945,9 +1946,8 @@ def parse_command_line(extra_options='', extra_long_options=[]):
if o in ('-p', '--prefix'):
match = re.match(r'([A-Za-z_.-][A-Za-z0-9_.-]*)?', a)
if match.end() != len(a):
print >>sys.stderr, \
"%s: 'funny character '%s' in argument of --prefix" \
% (sys.argv[0], a[match.end()])
print("%s: 'funny character '%s' in argument of --prefix" \
% (sys.argv[0], a[match.end()]), file=sys.stderr)
sys.exit(1)
prefix = a
elif o in ('-o', '--output-dir'):
@ -1964,7 +1964,7 @@ def parse_command_line(extra_options='', extra_long_options=[]):
do_h = True
if len(args) != 1:
print >>sys.stderr, "%s: need exactly one argument" % sys.argv[0]
print("%s: need exactly one argument" % sys.argv[0], file=sys.stderr)
sys.exit(1)
fname = args[0]

View file

@ -4,6 +4,7 @@
# This work is licensed under the terms of the GNU LGPL, version 2+.
# See the COPYING file in the top-level directory.
"""This script produces the documentation of a qapi schema in texinfo format"""
from __future__ import print_function
import re
import sys
@ -274,15 +275,15 @@ def texi_schema(schema):
def main(argv):
"""Takes schema argument, prints result to stdout"""
if len(argv) != 2:
print >>sys.stderr, "%s: need exactly 1 argument: SCHEMA" % argv[0]
print("%s: need exactly 1 argument: SCHEMA" % argv[0], file=sys.stderr)
sys.exit(1)
schema = qapi.QAPISchema(argv[1])
if not qapi.doc_required:
print >>sys.stderr, ("%s: need pragma 'doc-required' "
"to generate documentation" % argv[0])
print("%s: need pragma 'doc-required' "
"to generate documentation" % argv[0], file=sys.stderr)
sys.exit(1)
print texi_schema(schema)
print(texi_schema(schema))
if __name__ == '__main__':