[libvirt] [libvirt-python 0/3] Python 3 support mixed with Dan's patches

Turns out Dan and I both started working on Python 3 support and we talked about some changes to his patchset and these are the result of that conversation. This really belongs in the middle of his patchset but he's pushed the first part already so this is on top of master. Doug Goldstein (3): setup: Drop unused exception variable generator: Support exceptions in Python 2 and 3 Update exception catching in generated code generator.py | 18 ++++++++++++------ setup.py | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) -- 1.8.3.2

Drop the unused exception variable in setup.py. This has the benefit of dropping syntax that is not valid with Python 3. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 561157c..24d4cf2 100755 --- a/setup.py +++ b/setup.py @@ -40,7 +40,7 @@ try: spawn([pkgcfg, "--atleast-version=%s" % MIN_LIBVIRT_LXC, "libvirt"]) -except DistutilsExecError,e: +except DistutilsExecError: have_libvirt_lxc=False def get_pkgconfig_data(args, mod, required=True): -- 1.8.3.2

On Wed, Dec 04, 2013 at 02:34:06PM -0600, Doug Goldstein wrote:
Drop the unused exception variable in setup.py. This has the benefit of dropping syntax that is not valid with Python 3. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/setup.py b/setup.py index 561157c..24d4cf2 100755 --- a/setup.py +++ b/setup.py @@ -40,7 +40,7 @@ try: spawn([pkgcfg, "--atleast-version=%s" % MIN_LIBVIRT_LXC, "libvirt"]) -except DistutilsExecError,e: +except DistutilsExecError: have_libvirt_lxc=False
def get_pkgconfig_data(args, mod, required=True):
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

Use a syntax for exception handling that works in both Python 2 and Python 3 --- generator.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/generator.py b/generator.py index 0717624..009d3e1 100755 --- a/generator.py +++ b/generator.py @@ -818,7 +818,8 @@ def buildStubs(module, api_xml): (parser, target) = getparser() parser.feed(data) parser.close() - except IOError, msg: + except IOError: + msg = sys.exc_info()[1] print(file, ":", msg) sys.exit(1) @@ -837,7 +838,8 @@ def buildStubs(module, api_xml): (parser, target) = getparser() parser.feed(data) parser.close() - except IOError, msg: + except IOError: + msg = sys.exc_info()[1] print(file, ":", msg) if not quiet: -- 1.8.3.2

Use a syntax for exception handling that works in both Python 2 and Python 3. The new syntax is 'except Exception as e:' but this does not work in older Pythons so we use the most compatible way by just catching the exception and getting the type and the exception value after the fact. --- generator.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/generator.py b/generator.py index 009d3e1..214abed 100755 --- a/generator.py +++ b/generator.py @@ -1822,10 +1822,12 @@ def qemuBuildWrappers(module): fd.write("try:\n") fd.write(" import libvirtmod_qemu\n") - fd.write("except ImportError, lib_e:\n") + fd.write("except ImportError:\n") + fd.write(" lib_e = sys.exc_info()[1]\n") fd.write(" try:\n") fd.write(" import cygvirtmod_qemu as libvirtmod_qemu\n") - fd.write(" except ImportError, cyg_e:\n") + fd.write(" except ImportError:\n") + fd.write(" cyg_e = sys.exc_info()[1]\n") fd.write(" if str(cyg_e).count(\"No module named\"):\n") fd.write(" raise lib_e\n\n") @@ -1933,10 +1935,12 @@ def lxcBuildWrappers(module): fd.write("try:\n") fd.write(" import libvirtmod_lxc\n") - fd.write("except ImportError, lib_e:\n") + fd.write("except ImportError:\n") + fd.write(" lib_e = sys.exc_info()[1]\n") fd.write(" try:\n") fd.write(" import cygvirtmod_lxc as libvirtmod_lxc\n") - fd.write(" except ImportError, cyg_e:\n") + fd.write(" except ImportError:\n") + fd.write(" cyg_e = sys.exc_info()[1]\n") fd.write(" if str(cyg_e).count(\"No module named\"):\n") fd.write(" raise lib_e\n\n") -- 1.8.3.2

On Wed, Dec 04, 2013 at 02:34:05PM -0600, Doug Goldstein wrote:
Turns out Dan and I both started working on Python 3 support and we talked about some changes to his patchset and these are the result of that conversation. This really belongs in the middle of his patchset but he's pushed the first part already so this is on top of master.
Doug Goldstein (3): setup: Drop unused exception variable generator: Support exceptions in Python 2 and 3 Update exception catching in generated code
ACK to all three. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On Thu, Dec 05, 2013 at 11:28:38AM +0000, Daniel P. Berrange wrote:
On Wed, Dec 04, 2013 at 02:34:05PM -0600, Doug Goldstein wrote:
Turns out Dan and I both started working on Python 3 support and we talked about some changes to his patchset and these are the result of that conversation. This really belongs in the middle of his patchset but he's pushed the first part already so this is on top of master.
Doug Goldstein (3): setup: Drop unused exception variable generator: Support exceptions in Python 2 and 3 Update exception catching in generated code
ACK to all three.
FYI, I pushed them to git so I could continue rebasing my own on top. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
participants (2)
-
Daniel P. Berrange
-
Doug Goldstein