]> git.0d.be Git - empathy.git/blob - tools/glib-errors-str-gen.py
Updated gujarati file
[empathy.git] / tools / glib-errors-str-gen.py
1 #!/usr/bin/python
2
3 import sys
4 import xml.dom.minidom
5
6 from libtpcodegen import file_set_contents
7 from libglibcodegen import NS_TP, get_docstring, xml_escape
8
9 class Generator(object):
10     def __init__(self, dom, basename):
11         self.dom = dom
12         self.errors = self.dom.getElementsByTagNameNS(NS_TP, 'errors')[0]
13         self.basename = basename
14
15         self.__header = []
16         self.__body = []
17         self.__docs = []
18
19     def h(self, s):
20         if isinstance(s, unicode):
21             s = s.encode('utf-8')
22         self.__header.append(s)
23
24     def b(self, s):
25         if isinstance(s, unicode):
26             s = s.encode('utf-8')
27         self.__body.append(s)
28
29     def d(self, s):
30         if isinstance(s, unicode):
31             s = s.encode('utf-8')
32         self.__docs.append(s)
33
34     def __call__(self):
35         errors = self.errors.getElementsByTagNameNS(NS_TP, 'error')
36
37         self.b('#include <telepathy-glib/errors.h>')
38         self.b('')
39         self.b('const gchar *')
40         self.b('tp_error_get_dbus_name (TpError error)')
41         self.b('{')
42         self.b('  switch (error)')
43         self.b('    {')
44
45         for error in errors:
46             ns = error.parentNode.getAttribute('namespace')
47             nick = error.getAttribute('name').replace(' ', '')
48             uc_nick = error.getAttribute('name').replace(' ', '_').replace('.', '_').upper()
49             name = 'TP_ERROR_STR_' + uc_nick
50             error_name = '%s.%s' % (ns, nick)
51
52             self.d('/**')
53             self.d(' * %s:' % name)
54             self.d(' *')
55             self.d(' * The D-Bus error name %s' % error_name)
56             self.d(' *')
57             self.d(' * %s' % xml_escape(get_docstring(error)))
58             self.d(' */')
59             self.d('')
60
61             self.h('#define %s "%s"' % (name, error_name))
62
63             self.b('      case TP_ERROR_%s:' % uc_nick)
64             self.b('        return %s;' % name)
65
66         self.b('      default:')
67         self.b('        g_return_val_if_reached (NULL);')
68         self.b('    }')
69         self.b('}')
70
71         # make both files end with a newline
72         self.h('')
73         self.b('')
74
75         file_set_contents(self.basename + '.h', '\n'.join(self.__header))
76         file_set_contents(self.basename + '.c', '\n'.join(self.__body))
77         file_set_contents(self.basename + '-gtk-doc.h', '\n'.join(self.__docs))
78
79 if __name__ == '__main__':
80     argv = sys.argv[1:]
81     basename = argv[0]
82
83     Generator(xml.dom.minidom.parse(argv[1]), basename)()