diff options
author | Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk> | 2011-02-01 21:47:58 +0800 |
---|---|---|
committer | Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk> | 2011-03-24 04:52:21 +0800 |
commit | 97167291ee0e9436dd9282d0d8d673f6ed2d10cf (patch) | |
tree | d080dce966735abcaee3bc6b9319a693bd00d28f /tools/glib-errors-check-gen.py | |
parent | 2bddc2dae8b00f034164096d7a981015d8690cf7 (diff) | |
download | gsoc2013-empathy-97167291ee0e9436dd9282d0d8d673f6ed2d10cf.tar gsoc2013-empathy-97167291ee0e9436dd9282d0d8d673f6ed2d10cf.tar.gz gsoc2013-empathy-97167291ee0e9436dd9282d0d8d673f6ed2d10cf.tar.bz2 gsoc2013-empathy-97167291ee0e9436dd9282d0d8d673f6ed2d10cf.tar.lz gsoc2013-empathy-97167291ee0e9436dd9282d0d8d673f6ed2d10cf.tar.xz gsoc2013-empathy-97167291ee0e9436dd9282d0d8d673f6ed2d10cf.tar.zst gsoc2013-empathy-97167291ee0e9436dd9282d0d8d673f6ed2d10cf.zip |
Update tools from telepathy-glib
Diffstat (limited to 'tools/glib-errors-check-gen.py')
-rw-r--r-- | tools/glib-errors-check-gen.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tools/glib-errors-check-gen.py b/tools/glib-errors-check-gen.py new file mode 100644 index 000000000..553fc9caf --- /dev/null +++ b/tools/glib-errors-check-gen.py @@ -0,0 +1,58 @@ +#!/usr/bin/python + +import sys +import xml.dom.minidom + +from libglibcodegen import NS_TP, get_docstring, get_descendant_text + +class Generator(object): + def __init__(self, dom): + self.dom = dom + self.errors = self.dom.getElementsByTagNameNS(NS_TP, 'errors')[0] + + def __call__(self): + + print '{' + print ' GEnumClass *klass;' + print ' GEnumValue *value_by_name;' + print ' GEnumValue *value_by_nick;' + print '' + print ' g_type_init ();' + print ' klass = g_type_class_ref (TP_TYPE_ERROR);' + + for error in self.errors.getElementsByTagNameNS(NS_TP, 'error'): + ns = error.parentNode.getAttribute('namespace') + nick = error.getAttribute('name').replace(' ', '') + enum = ('TP_ERROR_' + + error.getAttribute('name').replace(' ', '_').replace('.', '_').upper()) + s = ('TP_ERROR_STR_' + + error.getAttribute('name').replace(' ', '_').replace('.', '_').upper()) + + print '' + print ' /* %s.%s */' % (ns, nick) + print (' value_by_name = g_enum_get_value_by_name (klass, "%s");' + % enum) + print (' value_by_nick = g_enum_get_value_by_nick (klass, "%s");' + % nick) + print (' g_assert (value_by_name != NULL);') + print (' g_assert (value_by_nick != NULL);') + print (' g_assert_cmpint (value_by_name->value, ==, %s);' + % enum) + print (' g_assert_cmpint (value_by_nick->value, ==, %s);' + % enum) + print (' g_assert_cmpstr (value_by_name->value_name, ==, "%s");' + % enum) + print (' g_assert_cmpstr (value_by_nick->value_name, ==, "%s");' + % enum) + print (' g_assert_cmpstr (value_by_name->value_nick, ==, "%s");' + % nick) + print (' g_assert_cmpstr (value_by_nick->value_nick, ==, "%s");' + % nick) + print (' g_assert_cmpstr (%s, ==, TP_ERROR_PREFIX ".%s");' + % (s, nick)) + + print '}' + +if __name__ == '__main__': + argv = sys.argv[1:] + Generator(xml.dom.minidom.parse(argv[0]))() |