[libvirt] [PATCH 0/2] apibuild: fix with python3

These patches fix apibuild.py to work with python3 and generate identical output to python2, at least in my testing. Someone else should confirm though Thanks, Cole Cole Robinson (2): apibuild: Fix errors on python3 apibuild: Fix -refs.xml building docs/apibuild.py | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) -- 2.14.3

Module 'string' function lower doesn't exist in python3. The canonical way is to call .lower() on a str instance. Do that, and make the exception handling more specific, which would have made this issue obvious. Signed-off-by: Cole Robinson <crobinso@redhat.com> --- docs/apibuild.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/apibuild.py b/docs/apibuild.py index 67b7eed1e..e81980e3c 100755 --- a/docs/apibuild.py +++ b/docs/apibuild.py @@ -2326,10 +2326,10 @@ class docBuilder: for data in ('Summary', 'Description', 'Author'): try: output.write(" <%s>%s</%s>\n" % ( - string.lower(data), + data.lower(), escape(dict.info[data]), - string.lower(data))) - except: + data.lower())) + except KeyError: self.warning("Header %s lacks a %s description" % (module, data)) if 'Description' in dict.info: desc = dict.info['Description'] -- 2.14.3

On Fri, Mar 16, 2018 at 02:05:11PM -0400, Cole Robinson wrote:
Module 'string' function lower doesn't exist in python3. The canonical way is to call .lower() on a str instance. Do that, and make the exception handling more specific, which would have made this issue obvious.
Signed-off-by: Cole Robinson <crobinso@redhat.com> --- docs/apibuild.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
diff --git a/docs/apibuild.py b/docs/apibuild.py index 67b7eed1e..e81980e3c 100755 --- a/docs/apibuild.py +++ b/docs/apibuild.py @@ -2326,10 +2326,10 @@ class docBuilder: for data in ('Summary', 'Description', 'Author'): try: output.write(" <%s>%s</%s>\n" % ( - string.lower(data), + data.lower(), escape(dict.info[data]), - string.lower(data))) - except: + data.lower())) + except KeyError: self.warning("Header %s lacks a %s description" % (module, data)) if 'Description' in dict.info: desc = dict.info['Description'] -- 2.14.3
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

Another usage of deprecated 'string' functions. We are just trying to match ascii letters here, so use a simple regex. And again drop the aggressive exception handling, it doesn't seem to trigger for anything in libvirt code. Signed-off-by: Cole Robinson <crobinso@redhat.com> --- docs/apibuild.py | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/docs/apibuild.py b/docs/apibuild.py index e81980e3c..51abf8383 100755 --- a/docs/apibuild.py +++ b/docs/apibuild.py @@ -11,7 +11,6 @@ from __future__ import print_function import os, sys -import string import glob import re @@ -2092,23 +2091,20 @@ class docBuilder: str = str.replace(';', ' ') tokens = str.split() for token in tokens: - try: - c = token[0] - if string.letters.find(c) < 0: - pass - elif len(token) < 3: + c = token[0] + if not re.match(r"[a-zA-Z]", c): + pass + elif len(token) < 3: + pass + else: + lower = token.lower() + # TODO: generalize this a bit + if lower == 'and' or lower == 'the': pass + elif token in self.xref: + self.xref[token].append(id) else: - lower = string.lower(token) - # TODO: generalize this a bit - if lower == 'and' or lower == 'the': - pass - elif token in self.xref: - self.xref[token].append(id) - else: - self.xref[token] = [id] - except: - pass + self.xref[token] = [id] def analyze(self): if not quiet: -- 2.14.3

On Fri, Mar 16, 2018 at 02:05:12PM -0400, Cole Robinson wrote:
Another usage of deprecated 'string' functions. We are just trying to match ascii letters here, so use a simple regex. And again drop the aggressive exception handling, it doesn't seem to trigger for anything in libvirt code.
Signed-off-by: Cole Robinson <crobinso@redhat.com> --- docs/apibuild.py | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
participants (2)
-
Cole Robinson
-
Daniel P. Berrangé