mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-12 23:46:17 +01:00
Updated codegen to work with python3.
Most changes were just replacing usage of "has_key" with "in". Also updated the sorting function which was simplified and changed to a "key" function instead of "cmp" (which is no longer supported in python3. Verified everything builds with python 2.7 and 3. https://bugzilla.gnome.org/show_bug.cgi?id=678066
This commit is contained in:
parent
6d5484b296
commit
03611f7c06
@ -304,11 +304,8 @@ class CodeGenerator:
|
|||||||
#
|
#
|
||||||
# See https://bugzilla.gnome.org/show_bug.cgi?id=647577#c5
|
# See https://bugzilla.gnome.org/show_bug.cgi?id=647577#c5
|
||||||
# for discussion
|
# for discussion
|
||||||
keys = function_pointers.keys()
|
for key in sorted(function_pointers.keys(), key=utils.version_cmp_key):
|
||||||
if len(keys) > 0:
|
self.h.write('%s'%function_pointers[key])
|
||||||
keys.sort(cmp=utils.my_version_cmp)
|
|
||||||
for key in keys:
|
|
||||||
self.h.write('%s'%function_pointers[key])
|
|
||||||
|
|
||||||
self.h.write('};\n')
|
self.h.write('};\n')
|
||||||
self.h.write('\n')
|
self.h.write('\n')
|
||||||
@ -1022,11 +1019,9 @@ class CodeGenerator:
|
|||||||
value = '@get_%s: '%(p.name_lower)
|
value = '@get_%s: '%(p.name_lower)
|
||||||
value += 'Getter for the #%s:%s property.'%(i.camel_name, p.name_hyphen)
|
value += 'Getter for the #%s:%s property.'%(i.camel_name, p.name_hyphen)
|
||||||
doc_bits[key] = value
|
doc_bits[key] = value
|
||||||
keys = doc_bits.keys()
|
for key in sorted(doc_bits.keys(), key=utils.version_cmp_key):
|
||||||
if len(keys) > 0:
|
self.c.write(' * %s\n'%doc_bits[key])
|
||||||
keys.sort(cmp=utils.my_version_cmp)
|
|
||||||
for key in keys:
|
|
||||||
self.c.write(' * %s\n'%doc_bits[key])
|
|
||||||
self.c.write(self.docbook_gen.expand(
|
self.c.write(self.docbook_gen.expand(
|
||||||
' *\n'
|
' *\n'
|
||||||
' * Virtual table for the D-Bus interface #%s.\n'
|
' * Virtual table for the D-Bus interface #%s.\n'
|
||||||
|
@ -259,14 +259,12 @@ class DocbookCodeGenerator:
|
|||||||
self.expand_member_dict[key] = value
|
self.expand_member_dict[key] = value
|
||||||
# Make sure to expand the keys in reverse order so e.g. #org.foo.Iface:MediaCompat
|
# Make sure to expand the keys in reverse order so e.g. #org.foo.Iface:MediaCompat
|
||||||
# is evaluated before #org.foo.Iface:Media ...
|
# is evaluated before #org.foo.Iface:Media ...
|
||||||
self.expand_member_dict_keys = self.expand_member_dict.keys()
|
self.expand_member_dict_keys = sorted(self.expand_member_dict.keys(), reverse=True)
|
||||||
self.expand_member_dict_keys.sort(reverse=True)
|
self.expand_iface_dict_keys = sorted(self.expand_iface_dict.keys(), reverse=True)
|
||||||
self.expand_iface_dict_keys = self.expand_iface_dict.keys()
|
|
||||||
self.expand_iface_dict_keys.sort(reverse=True)
|
|
||||||
|
|
||||||
def generate(self):
|
def generate(self):
|
||||||
for i in self.ifaces:
|
for i in self.ifaces:
|
||||||
self.out = file('%s-%s.xml'%(self.docbook, i.name), 'w')
|
self.out = open('%s-%s.xml'%(self.docbook, i.name), 'w')
|
||||||
self.out.write(''%())
|
self.out.write(''%())
|
||||||
self.out.write('<?xml version="1.0" encoding="utf-8"?>\n'%())
|
self.out.write('<?xml version="1.0" encoding="utf-8"?>\n'%())
|
||||||
self.out.write('<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"\n'%())
|
self.out.write('<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"\n'%())
|
||||||
|
@ -184,8 +184,8 @@ def codegen_main():
|
|||||||
|
|
||||||
c_code = opts.generate_c_code
|
c_code = opts.generate_c_code
|
||||||
if c_code:
|
if c_code:
|
||||||
h = file(c_code + '.h', 'w')
|
h = open(c_code + '.h', 'w')
|
||||||
c = file(c_code + '.c', 'w')
|
c = open(c_code + '.c', 'w')
|
||||||
gen = codegen.CodeGenerator(all_ifaces,
|
gen = codegen.CodeGenerator(all_ifaces,
|
||||||
opts.c_namespace,
|
opts.c_namespace,
|
||||||
opts.interface_prefix,
|
opts.interface_prefix,
|
||||||
|
@ -152,12 +152,12 @@ class DBusXMLParser:
|
|||||||
self.state = DBusXMLParser.STATE_IGNORED
|
self.state = DBusXMLParser.STATE_IGNORED
|
||||||
|
|
||||||
# assign docs, if any
|
# assign docs, if any
|
||||||
if attrs.has_key('name') and self.doc_comment_last_symbol == attrs['name']:
|
if 'name' in attrs and self.doc_comment_last_symbol == attrs['name']:
|
||||||
self._cur_object.doc_string = self.doc_comment_body
|
self._cur_object.doc_string = self.doc_comment_body
|
||||||
if self.doc_comment_params.has_key('short_description'):
|
if 'short_description' in self.doc_comment_params:
|
||||||
short_description = self.doc_comment_params['short_description']
|
short_description = self.doc_comment_params['short_description']
|
||||||
self._cur_object.doc_string_brief = short_description
|
self._cur_object.doc_string_brief = short_description
|
||||||
if self.doc_comment_params.has_key('since'):
|
if 'since' in self.doc_comment_params:
|
||||||
self._cur_object.since = self.doc_comment_params['since']
|
self._cur_object.since = self.doc_comment_params['since']
|
||||||
|
|
||||||
elif self.state == DBusXMLParser.STATE_INTERFACE:
|
elif self.state == DBusXMLParser.STATE_INTERFACE:
|
||||||
@ -185,16 +185,16 @@ class DBusXMLParser:
|
|||||||
self.state = DBusXMLParser.STATE_IGNORED
|
self.state = DBusXMLParser.STATE_IGNORED
|
||||||
|
|
||||||
# assign docs, if any
|
# assign docs, if any
|
||||||
if attrs.has_key('name') and self.doc_comment_last_symbol == attrs['name']:
|
if 'name' in attrs and self.doc_comment_last_symbol == attrs['name']:
|
||||||
self._cur_object.doc_string = self.doc_comment_body
|
self._cur_object.doc_string = self.doc_comment_body
|
||||||
if self.doc_comment_params.has_key('since'):
|
if 'since' in self.doc_comment_params:
|
||||||
self._cur_object.since = self.doc_comment_params['since']
|
self._cur_object.since = self.doc_comment_params['since']
|
||||||
|
|
||||||
elif self.state == DBusXMLParser.STATE_METHOD:
|
elif self.state == DBusXMLParser.STATE_METHOD:
|
||||||
if name == DBusXMLParser.STATE_ARG:
|
if name == DBusXMLParser.STATE_ARG:
|
||||||
self.state = DBusXMLParser.STATE_ARG
|
self.state = DBusXMLParser.STATE_ARG
|
||||||
arg_name = None
|
arg_name = None
|
||||||
if attrs.has_key('name'):
|
if 'name' in attrs:
|
||||||
arg_name = attrs['name']
|
arg_name = attrs['name']
|
||||||
arg = dbustypes.Arg(arg_name, attrs['type'])
|
arg = dbustypes.Arg(arg_name, attrs['type'])
|
||||||
direction = attrs['direction']
|
direction = attrs['direction']
|
||||||
@ -215,18 +215,18 @@ class DBusXMLParser:
|
|||||||
|
|
||||||
# assign docs, if any
|
# assign docs, if any
|
||||||
if self.doc_comment_last_symbol == old_cur_object.name:
|
if self.doc_comment_last_symbol == old_cur_object.name:
|
||||||
if attrs.has_key('name') and self.doc_comment_params.has_key(attrs['name']):
|
if 'name' in attrs and attrs['name'] in self.doc_comment_params:
|
||||||
doc_string = self.doc_comment_params[attrs['name']]
|
doc_string = self.doc_comment_params[attrs['name']]
|
||||||
if doc_string != None:
|
if doc_string != None:
|
||||||
self._cur_object.doc_string = doc_string
|
self._cur_object.doc_string = doc_string
|
||||||
if self.doc_comment_params.has_key('since'):
|
if 'since' in self.doc_comment_params:
|
||||||
self._cur_object.since = self.doc_comment_params['since']
|
self._cur_object.since = self.doc_comment_params['since']
|
||||||
|
|
||||||
elif self.state == DBusXMLParser.STATE_SIGNAL:
|
elif self.state == DBusXMLParser.STATE_SIGNAL:
|
||||||
if name == DBusXMLParser.STATE_ARG:
|
if name == DBusXMLParser.STATE_ARG:
|
||||||
self.state = DBusXMLParser.STATE_ARG
|
self.state = DBusXMLParser.STATE_ARG
|
||||||
arg_name = None
|
arg_name = None
|
||||||
if attrs.has_key('name'):
|
if 'name' in attrs:
|
||||||
arg_name = attrs['name']
|
arg_name = attrs['name']
|
||||||
arg = dbustypes.Arg(arg_name, attrs['type'])
|
arg = dbustypes.Arg(arg_name, attrs['type'])
|
||||||
self._cur_object.args.append(arg)
|
self._cur_object.args.append(arg)
|
||||||
@ -241,11 +241,11 @@ class DBusXMLParser:
|
|||||||
|
|
||||||
# assign docs, if any
|
# assign docs, if any
|
||||||
if self.doc_comment_last_symbol == old_cur_object.name:
|
if self.doc_comment_last_symbol == old_cur_object.name:
|
||||||
if attrs.has_key('name') and self.doc_comment_params.has_key(attrs['name']):
|
if 'name' in attrs and attrs['name'] in self.doc_comment_params:
|
||||||
doc_string = self.doc_comment_params[attrs['name']]
|
doc_string = self.doc_comment_params[attrs['name']]
|
||||||
if doc_string != None:
|
if doc_string != None:
|
||||||
self._cur_object.doc_string = doc_string
|
self._cur_object.doc_string = doc_string
|
||||||
if self.doc_comment_params.has_key('since'):
|
if 'since' in self.doc_comment_params:
|
||||||
self._cur_object.since = self.doc_comment_params['since']
|
self._cur_object.since = self.doc_comment_params['since']
|
||||||
|
|
||||||
elif self.state == DBusXMLParser.STATE_PROPERTY:
|
elif self.state == DBusXMLParser.STATE_PROPERTY:
|
||||||
|
@ -97,15 +97,8 @@ def lookup_brief_docs(annotations):
|
|||||||
else:
|
else:
|
||||||
return s
|
return s
|
||||||
|
|
||||||
# I'm sure this could be a lot more elegant if I was
|
def version_cmp_key(key):
|
||||||
# more fluent in python...
|
# If the 'since' version is empty put a 0 in its place as this will
|
||||||
def my_version_cmp(a, b):
|
# allow LooseVersion to work and will always compare lower.
|
||||||
if len(a[0]) > 0 and len(b[0]) > 0:
|
v = key[0] if key[0] else '0'
|
||||||
va = distutils.version.LooseVersion(a[0])
|
return (distutils.version.LooseVersion(v), key[1])
|
||||||
vb = distutils.version.LooseVersion(b[0])
|
|
||||||
ret = va.__cmp__(vb)
|
|
||||||
else:
|
|
||||||
ret = cmp(a[0], b[0])
|
|
||||||
if ret != 0:
|
|
||||||
return ret
|
|
||||||
return cmp(a[1], b[1])
|
|
||||||
|
Loading…
Reference in New Issue
Block a user