6 from libtpcodegen
import file_set_contents
, u
7 from libglibcodegen
import NS_TP
, get_docstring
, xml_escape
9 class Generator(object):
10 def __init__(self
, dom
, basename
):
12 self
.errors
= self
.dom
.getElementsByTagNameNS(NS_TP
, 'errors')[0]
13 self
.basename
= basename
20 self
.__header
.append(s
)
29 errors
= self
.errors
.getElementsByTagNameNS(NS_TP
, 'error')
31 self
.b('#include <telepathy-glib/errors.h>')
33 self
.b('const gchar *')
34 self
.b('tp_error_get_dbus_name (TpError error)')
36 self
.b(' switch (error)')
40 ns
= error
.parentNode
.getAttribute('namespace')
41 nick
= error
.getAttribute('name').replace(' ', '')
42 uc_nick
= error
.getAttribute('name').replace(' ', '_').replace('.', '_').upper()
43 name
= 'TP_ERROR_STR_' + uc_nick
44 error_name
= '%s.%s' % (ns
, nick
)
47 self
.d(' * %s:' % name
)
49 self
.d(' * The D-Bus error name %s' % error_name
)
51 self
.d(' * %s' % xml_escape(get_docstring(error
)))
55 self
.h('#define %s "%s"' % (name
, error_name
))
57 self
.b(' case TP_ERROR_%s:' % uc_nick
)
58 self
.b(' return %s;' % name
)
61 self
.b(' g_return_val_if_reached (NULL);')
65 # make both files end with a newline
69 file_set_contents(self
.basename
+ '.h', u('\n').join(self
.__header
).encode('utf-8'))
70 file_set_contents(self
.basename
+ '.c', u('\n').join(self
.__body
).encode('utf-8'))
71 file_set_contents(self
.basename
+ '-gtk-doc.h', u('\n').join(self
.__docs
).encode('utf-8'))
73 if __name__
== '__main__':
77 Generator(xml
.dom
.minidom
.parse(argv
[1]), basename
)()