mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
* python/generator.py: Python bindings now throw exceptions
in almost all cases where an error is encountered in the underlying libvirt code.
This commit is contained in:
parent
6ec6b79669
commit
0ab7cda38c
@ -1,3 +1,9 @@
|
|||||||
|
Wed Mar 28 12:23:00 BST 2007 Richard W.M. Jones <rjones@redhat.com>
|
||||||
|
|
||||||
|
* python/generator.py: Python bindings now throw exceptions
|
||||||
|
in almost all cases where an error is encountered in the
|
||||||
|
underlying libvirt code.
|
||||||
|
|
||||||
Wed Mar 28 10:47:16 CEST 2007 Daniel Veillard <veillard@redhat.com>
|
Wed Mar 28 10:47:16 CEST 2007 Daniel Veillard <veillard@redhat.com>
|
||||||
|
|
||||||
* src/xen_internal.c: applied patch from Masayuki Sunou fixing the
|
* src/xen_internal.c: applied patch from Masayuki Sunou fixing the
|
||||||
@ -20,6 +26,7 @@ Tue Mar 27 10:39:00 EDT 2007 Daniel P. Berrange <berrange@redhat.com>
|
|||||||
* tests/xencapsdata/*: Added data files for Xen capabilities tests
|
* tests/xencapsdata/*: Added data files for Xen capabilities tests
|
||||||
* configure.ac, tests/Makefile.am: Added tests/xencapsdata/ directory
|
* configure.ac, tests/Makefile.am: Added tests/xencapsdata/ directory
|
||||||
|
|
||||||
|
>>>>>>> 1.489
|
||||||
Tue Mar 27 11:26:00 BST 2007 Richard W.M. Jones <rjones@redhat.com>
|
Tue Mar 27 11:26:00 BST 2007 Richard W.M. Jones <rjones@redhat.com>
|
||||||
|
|
||||||
* qemud/qemud.c: If using FORTIFY_SOURCE, remove warning
|
* qemud/qemud.c: If using FORTIFY_SOURCE, remove warning
|
||||||
|
@ -9,6 +9,7 @@ enums = {} # { enumType: { enumConstant: enumValue } }
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import string
|
import string
|
||||||
|
import re
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# launched as a script
|
# launched as a script
|
||||||
@ -561,6 +562,8 @@ classes_references = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
functions_noexcept = {
|
functions_noexcept = {
|
||||||
|
'virDomainGetID': True,
|
||||||
|
'virDomainGetName': True,
|
||||||
}
|
}
|
||||||
|
|
||||||
reference_keepers = {
|
reference_keepers = {
|
||||||
@ -575,6 +578,25 @@ function_post = {
|
|||||||
'virNetworkDestroy': "self._o = None",
|
'virNetworkDestroy': "self._o = None",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Functions returning an integral type which need special rules to
|
||||||
|
# check for errors and raise exceptions.
|
||||||
|
functions_int_exception_test = {
|
||||||
|
'virDomainGetMaxMemory': "%s == 0",
|
||||||
|
}
|
||||||
|
functions_int_default_test = "%s == -1"
|
||||||
|
|
||||||
|
def is_integral_type (name):
|
||||||
|
return not re.search ("^(unsigned)? ?(int|long)$", name) is None
|
||||||
|
|
||||||
|
# Functions returning lists which need special rules to check for errors
|
||||||
|
# and raise exceptions.
|
||||||
|
functions_list_exception_test = {
|
||||||
|
}
|
||||||
|
functions_list_default_test = "%s is None"
|
||||||
|
|
||||||
|
def is_list_type (name):
|
||||||
|
return name[-1:] == "*"
|
||||||
|
|
||||||
def nameFixup(name, classe, type, file):
|
def nameFixup(name, classe, type, file):
|
||||||
# avoid a desastrous clash
|
# avoid a desastrous clash
|
||||||
listname = classe + "List"
|
listname = classe + "List"
|
||||||
@ -782,7 +804,8 @@ def buildWrappers():
|
|||||||
classes.write("__o");
|
classes.write("__o");
|
||||||
n = n + 1
|
n = n + 1
|
||||||
classes.write(")\n");
|
classes.write(")\n");
|
||||||
if ret[0] != "void":
|
|
||||||
|
if ret[0] != "void":
|
||||||
if classes_type.has_key(ret[0]):
|
if classes_type.has_key(ret[0]):
|
||||||
#
|
#
|
||||||
# Raise an exception
|
# Raise an exception
|
||||||
@ -797,8 +820,35 @@ def buildWrappers():
|
|||||||
classes.write(" return ");
|
classes.write(" return ");
|
||||||
classes.write(classes_type[ret[0]][1] % ("ret"));
|
classes.write(classes_type[ret[0]][1] % ("ret"));
|
||||||
classes.write("\n");
|
classes.write("\n");
|
||||||
|
|
||||||
|
# For functions returning an integral type there are
|
||||||
|
# several things that we can do, depending on the
|
||||||
|
# contents of functions_int_*:
|
||||||
|
elif is_integral_type (ret[0]):
|
||||||
|
if not functions_noexcept.has_key (name):
|
||||||
|
if functions_int_exception_test.has_key (name):
|
||||||
|
test = functions_int_exception_test[name]
|
||||||
|
else:
|
||||||
|
test = functions_int_default_test
|
||||||
|
classes.write ((" if " + test +
|
||||||
|
": raise libvirtError ('%s() failed')\n") %
|
||||||
|
("ret", name))
|
||||||
|
classes.write(" return ret\n")
|
||||||
|
|
||||||
|
elif is_list_type (ret[0]):
|
||||||
|
if not functions_noexcept.has_key (name):
|
||||||
|
if functions_list_exception_test.has_key (name):
|
||||||
|
test = functions_list_exception_test[name]
|
||||||
|
else:
|
||||||
|
test = functions_list_default_test
|
||||||
|
classes.write ((" if " + test +
|
||||||
|
": raise libvirtError ('%s() failed')\n") %
|
||||||
|
("ret", name))
|
||||||
|
classes.write(" return ret\n")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
classes.write(" return ret\n");
|
classes.write(" return ret\n")
|
||||||
|
|
||||||
classes.write("\n");
|
classes.write("\n");
|
||||||
|
|
||||||
txt.write("\n\n#\n# Set of classes of the module\n#\n\n")
|
txt.write("\n\n#\n# Set of classes of the module\n#\n\n")
|
||||||
@ -896,9 +946,9 @@ def buildWrappers():
|
|||||||
classes.write(classes_type[arg[1]][0])
|
classes.write(classes_type[arg[1]][0])
|
||||||
n = n + 1
|
n = n + 1
|
||||||
classes.write(")\n");
|
classes.write(")\n");
|
||||||
if function_post.has_key(name):
|
|
||||||
classes.write(" %s\n" % (function_post[name]));
|
# For functions returning object types:
|
||||||
if ret[0] != "void":
|
if ret[0] != "void":
|
||||||
if classes_type.has_key(ret[0]):
|
if classes_type.has_key(ret[0]):
|
||||||
#
|
#
|
||||||
# Raise an exception
|
# Raise an exception
|
||||||
@ -911,10 +961,6 @@ def buildWrappers():
|
|||||||
classes.write(
|
classes.write(
|
||||||
" if ret is None:raise libvirtError('%s() failed', conn=self)\n" %
|
" if ret is None:raise libvirtError('%s() failed', conn=self)\n" %
|
||||||
(name))
|
(name))
|
||||||
elif classname == "virDomain":
|
|
||||||
classes.write(
|
|
||||||
" if ret is None:raise libvirtError('%s() failed')\n" %
|
|
||||||
(name))
|
|
||||||
else:
|
else:
|
||||||
classes.write(
|
classes.write(
|
||||||
" if ret is None:raise libvirtError('%s() failed')\n" %
|
" if ret is None:raise libvirtError('%s() failed')\n" %
|
||||||
@ -945,6 +991,12 @@ def buildWrappers():
|
|||||||
if pref[0] == classname:
|
if pref[0] == classname:
|
||||||
classes.write(" __tmp.%s = self\n" %
|
classes.write(" __tmp.%s = self\n" %
|
||||||
pref[1])
|
pref[1])
|
||||||
|
|
||||||
|
# Post-processing - just before we return.
|
||||||
|
if function_post.has_key(name):
|
||||||
|
classes.write(" %s\n" %
|
||||||
|
(function_post[name]));
|
||||||
|
|
||||||
#
|
#
|
||||||
# return the class
|
# return the class
|
||||||
#
|
#
|
||||||
@ -956,11 +1008,71 @@ def buildWrappers():
|
|||||||
if functions_noexcept.has_key(name):
|
if functions_noexcept.has_key(name):
|
||||||
classes.write(
|
classes.write(
|
||||||
" if ret is None:return None");
|
" if ret is None:return None");
|
||||||
|
|
||||||
|
# Post-processing - just before we return.
|
||||||
|
if function_post.has_key(name):
|
||||||
|
classes.write(" %s\n" %
|
||||||
|
(function_post[name]));
|
||||||
|
|
||||||
classes.write(" return ");
|
classes.write(" return ");
|
||||||
classes.write(converter_type[ret[0]] % ("ret"));
|
classes.write(converter_type[ret[0]] % ("ret"));
|
||||||
classes.write("\n");
|
classes.write("\n");
|
||||||
|
|
||||||
|
# For functions returning an integral type there
|
||||||
|
# are several things that we can do, depending on
|
||||||
|
# the contents of functions_int_*:
|
||||||
|
elif is_integral_type (ret[0]):
|
||||||
|
if not functions_noexcept.has_key (name):
|
||||||
|
if functions_int_exception_test.has_key (name):
|
||||||
|
test = functions_int_exception_test[name]
|
||||||
|
else:
|
||||||
|
test = functions_int_default_test
|
||||||
|
if classname == "virConnect":
|
||||||
|
classes.write ((" if " + test +
|
||||||
|
": raise libvirtError ('%s() failed', conn=self)\n") %
|
||||||
|
("ret", name))
|
||||||
|
else:
|
||||||
|
classes.write ((" if " + test +
|
||||||
|
": raise libvirtError ('%s() failed')\n") %
|
||||||
|
("ret", name))
|
||||||
|
|
||||||
|
# Post-processing - just before we return.
|
||||||
|
if function_post.has_key(name):
|
||||||
|
classes.write(" %s\n" %
|
||||||
|
(function_post[name]));
|
||||||
|
|
||||||
|
classes.write (" return ret\n")
|
||||||
|
|
||||||
|
elif is_list_type (ret[0]):
|
||||||
|
if not functions_noexcept.has_key (name):
|
||||||
|
if functions_list_exception_test.has_key (name):
|
||||||
|
test = functions_list_exception_test[name]
|
||||||
|
else:
|
||||||
|
test = functions_list_default_test
|
||||||
|
if classname == "virConnect":
|
||||||
|
classes.write ((" if " + test +
|
||||||
|
": raise libvirtError ('%s() failed', conn=self)\n") %
|
||||||
|
("ret", name))
|
||||||
|
else:
|
||||||
|
classes.write ((" if " + test +
|
||||||
|
": raise libvirtError ('%s() failed')\n") %
|
||||||
|
("ret", name))
|
||||||
|
|
||||||
|
# Post-processing - just before we return.
|
||||||
|
if function_post.has_key(name):
|
||||||
|
classes.write(" %s\n" %
|
||||||
|
(function_post[name]));
|
||||||
|
|
||||||
|
classes.write (" return ret\n")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
# Post-processing - just before we return.
|
||||||
|
if function_post.has_key(name):
|
||||||
|
classes.write(" %s\n" %
|
||||||
|
(function_post[name]));
|
||||||
|
|
||||||
classes.write(" return ret\n");
|
classes.write(" return ret\n");
|
||||||
|
|
||||||
classes.write("\n");
|
classes.write("\n");
|
||||||
|
|
||||||
#
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user