Re: [libvirt] [RFC PATCH 5/5] docs: Port apibuild.py to Python 3

2018-03-15 Thread Andrea Bolognani
On Wed, 2018-03-14 at 09:59 +, Daniel P. Berrangé wrote:
> On Tue, Mar 13, 2018 at 07:42:47PM +0100, Andrea Bolognani wrote:
> > A lot of tweaks needed.
> > 
> > The generated files are bit by bit identical to those produced
> > before when the script is invoked using Python 2, but using
> > Python 3 results in some errors being reported and the build
> > step to be considered failed. The output files are mostly the
> > same, except ,  and  are missing
> > in *-api.xml files and  are missing from *-refs.xml
> > files.
> 
> FWIW, I would find these changes easier to review if instead of
> converting one file per patch, it had one type of change per
> patch. ie find the print_function in all files, then fix the
> sorted() usage in all files, then iteritems(), etc.

That would probably make a bunch of patches mergeable right away,
thus paving the way for someone with better Python knowledge to
jump in and take care of the tricky compatibility issues without
having to worry about the trivial stuff.

I'll work on it.

-- 
Andrea Bolognani / Red Hat / Virtualization

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [RFC PATCH 5/5] docs: Port apibuild.py to Python 3

2018-03-15 Thread Daniel P . Berrangé
On Tue, Mar 13, 2018 at 07:42:47PM +0100, Andrea Bolognani wrote:
> A lot of tweaks needed.
> 
> The generated files are bit by bit identical to those produced
> before when the script is invoked using Python 2, but using
> Python 3 results in some errors being reported and the build
> step to be considered failed. The output files are mostly the
> same, except ,  and  are missing
> in *-api.xml files and  are missing from *-refs.xml
> files.

FWIW, I would find these changes easier to review if instead of
converting one file per patch, it had one type of change per
patch. ie find the print_function in all files, then fix the
sorted() usage in all files, then iteritems(), etc.

> 
> Signed-off-by: Andrea Bolognani 
> ---
>  docs/apibuild.py | 379 
> ++-
>  1 file changed, 181 insertions(+), 198 deletions(-)
> 
> diff --git a/docs/apibuild.py b/docs/apibuild.py
> index a788086a65..2209b4b942 100755
> --- a/docs/apibuild.py
> +++ b/docs/apibuild.py
> @@ -7,6 +7,9 @@
>  #
>  # dan...@veillard.com
>  #
> +
> +from __future__ import print_function
> +
>  import os, sys
>  import string
>  import glob
> @@ -119,19 +122,18 @@ hidden_macros = {
>  }
>  
>  def escape(raw):
> -raw = string.replace(raw, '&', '')
> -raw = string.replace(raw, '<', '')
> -raw = string.replace(raw, '>', '')
> -raw = string.replace(raw, "'", '')
> -raw = string.replace(raw, '"', '')
> +raw = raw.replace('&', '')
> +raw = raw.replace('<', '')
> +raw = raw.replace('>', '')
> +raw = raw.replace("'", '')
> +raw = raw.replace('"', '')
>  return raw
>  
>  def uniq(items):
>  d = {}
>  for item in items:
>  d[item]=1
> -k = d.keys()
> -k.sort()
> +k = sorted(d.keys())
>  return k
>  
>  class identifier:
> @@ -150,8 +152,8 @@ class identifier:
>  else:
>  self.conditionals = conditionals[:]
>  if self.name == debugsym and not quiet:
> -print "=> define %s : %s" % (debugsym, (module, type, info,
> - extra, conditionals))
> +print("=> define %s : %s" % (debugsym, (module, type, info,
> + extra, conditionals)))
>  
>  def __repr__(self):
>  r = "%s %s:" % (self.type, self.name)
> @@ -160,11 +162,11 @@ class identifier:
>  if self.module is not None:
>  r = r + " from %s" % (self.module)
>  if self.info is not None:
> -r = r + " " +  `self.info`
> +r = r + " " + repr(self.info)
>  if self.extra is not None:
> -r = r + " " + `self.extra`
> +r = r + " " + repr(self.extra)
>  if self.conditionals is not None:
> -r = r + " " + `self.conditionals`
> +r = r + " " + repr(self.conditionals)
>  return r
>  
>  
> @@ -210,8 +212,8 @@ class identifier:
>  def update(self, header, module, type = None, info = None, extra=None,
> conditionals=None):
>  if self.name == debugsym and not quiet:
> -print "=> update %s : %s" % (debugsym, (module, type, info,
> - extra, conditionals))
> +print("=> update %s : %s" % (debugsym, (module, type, info,
> + extra, conditionals)))
>  if header is not None and self.header is None:
>  self.set_header(module)
>  if module is not None and (self.module is None or self.header == 
> self.module):
> @@ -243,7 +245,7 @@ class index:
>  def warning(self, msg):
>  global warnings
>  warnings = warnings + 1
> -print msg
> +print(msg)
>  
>  def add_ref(self, name, header, module, static, type, lineno, info=None, 
> extra=None, conditionals = None):
>  if name[0:2] == '__':
> @@ -263,7 +265,7 @@ class index:
>  self.references[name] = d
>  
>  if name == debugsym and not quiet:
> -print "New ref: %s" % (d)
> +print("New ref: %s" % (d))
>  
>  return d
>  
> @@ -304,7 +306,7 @@ class index:
>  self.warning("Unable to register type ", type)
>  
>  if name == debugsym and not quiet:
> -print "New symbol: %s" % (d)
> +print("New symbol: %s" % (d))
>  
>  return d
>  
> @@ -314,9 +316,9 @@ class index:
># macro might be used to override functions or variables
># definitions
>#
> - if self.macros.has_key(id):
> + if id in self.macros:
>   del self.macros[id]
> - if self.functions.has_key(id):
> + if id in self.functions:
>   self.warning("function %s from %s redeclared in %s" % (
>  id, self.functions[id].header, idx.functions[id].header))
>   else:
> @@ -327,30 

[libvirt] [RFC PATCH 5/5] docs: Port apibuild.py to Python 3

2018-03-13 Thread Andrea Bolognani
A lot of tweaks needed.

The generated files are bit by bit identical to those produced
before when the script is invoked using Python 2, but using
Python 3 results in some errors being reported and the build
step to be considered failed. The output files are mostly the
same, except ,  and  are missing
in *-api.xml files and  are missing from *-refs.xml
files.

Signed-off-by: Andrea Bolognani 
---
 docs/apibuild.py | 379 ++-
 1 file changed, 181 insertions(+), 198 deletions(-)

diff --git a/docs/apibuild.py b/docs/apibuild.py
index a788086a65..2209b4b942 100755
--- a/docs/apibuild.py
+++ b/docs/apibuild.py
@@ -7,6 +7,9 @@
 #
 # dan...@veillard.com
 #
+
+from __future__ import print_function
+
 import os, sys
 import string
 import glob
@@ -119,19 +122,18 @@ hidden_macros = {
 }
 
 def escape(raw):
-raw = string.replace(raw, '&', '')
-raw = string.replace(raw, '<', '')
-raw = string.replace(raw, '>', '')
-raw = string.replace(raw, "'", '')
-raw = string.replace(raw, '"', '')
+raw = raw.replace('&', '')
+raw = raw.replace('<', '')
+raw = raw.replace('>', '')
+raw = raw.replace("'", '')
+raw = raw.replace('"', '')
 return raw
 
 def uniq(items):
 d = {}
 for item in items:
 d[item]=1
-k = d.keys()
-k.sort()
+k = sorted(d.keys())
 return k
 
 class identifier:
@@ -150,8 +152,8 @@ class identifier:
 else:
 self.conditionals = conditionals[:]
 if self.name == debugsym and not quiet:
-print "=> define %s : %s" % (debugsym, (module, type, info,
- extra, conditionals))
+print("=> define %s : %s" % (debugsym, (module, type, info,
+ extra, conditionals)))
 
 def __repr__(self):
 r = "%s %s:" % (self.type, self.name)
@@ -160,11 +162,11 @@ class identifier:
 if self.module is not None:
 r = r + " from %s" % (self.module)
 if self.info is not None:
-r = r + " " +  `self.info`
+r = r + " " + repr(self.info)
 if self.extra is not None:
-r = r + " " + `self.extra`
+r = r + " " + repr(self.extra)
 if self.conditionals is not None:
-r = r + " " + `self.conditionals`
+r = r + " " + repr(self.conditionals)
 return r
 
 
@@ -210,8 +212,8 @@ class identifier:
 def update(self, header, module, type = None, info = None, extra=None,
conditionals=None):
 if self.name == debugsym and not quiet:
-print "=> update %s : %s" % (debugsym, (module, type, info,
- extra, conditionals))
+print("=> update %s : %s" % (debugsym, (module, type, info,
+ extra, conditionals)))
 if header is not None and self.header is None:
 self.set_header(module)
 if module is not None and (self.module is None or self.header == 
self.module):
@@ -243,7 +245,7 @@ class index:
 def warning(self, msg):
 global warnings
 warnings = warnings + 1
-print msg
+print(msg)
 
 def add_ref(self, name, header, module, static, type, lineno, info=None, 
extra=None, conditionals = None):
 if name[0:2] == '__':
@@ -263,7 +265,7 @@ class index:
 self.references[name] = d
 
 if name == debugsym and not quiet:
-print "New ref: %s" % (d)
+print("New ref: %s" % (d))
 
 return d
 
@@ -304,7 +306,7 @@ class index:
 self.warning("Unable to register type ", type)
 
 if name == debugsym and not quiet:
-print "New symbol: %s" % (d)
+print("New symbol: %s" % (d))
 
 return d
 
@@ -314,9 +316,9 @@ class index:
   # macro might be used to override functions or variables
   # definitions
   #
- if self.macros.has_key(id):
+ if id in self.macros:
  del self.macros[id]
- if self.functions.has_key(id):
+ if id in self.functions:
  self.warning("function %s from %s redeclared in %s" % (
 id, self.functions[id].header, idx.functions[id].header))
  else:
@@ -327,30 +329,30 @@ class index:
   # macro might be used to override functions or variables
   # definitions
   #
- if self.macros.has_key(id):
+ if id in self.macros:
  del self.macros[id]
- if self.variables.has_key(id):
+ if id in self.variables:
  self.warning("variable %s from %s redeclared in %s" % (
 id, self.variables[id].header, idx.variables[id].header))
  else:
  self.variables[id] = idx.variables[id]