2
1

libglib2-make-codegen-python2-python3-compliant.patch 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. Fetch from http://git.gnome.org/browse/glib/patch/?id=03611f7c0670ea14eedbc121972aed7ce60bb9ee
  2. This patch is already included upstream, from the glib-2.32.4 release.
  3. Signed-off-by: Samuel Martin <s.martin49@gmail.com>
  4. ---
  5. From 03611f7c0670ea14eedbc121972aed7ce60bb9ee Mon Sep 17 00:00:00 2001
  6. From: Simon Feltman <s.feltman@gmail.com>
  7. Date: Thu, 14 Jun 2012 06:20:17 +0000
  8. Subject: Updated codegen to work with python3.
  9. Most changes were just replacing usage of "has_key" with "in".
  10. Also updated the sorting function which was simplified and
  11. changed to a "key" function instead of "cmp" (which is no longer
  12. supported in python3. Verified everything builds with
  13. python 2.7 and 3.
  14. https://bugzilla.gnome.org/show_bug.cgi?id=678066
  15. ---
  16. diff --git a/gio/gdbus-2.0/codegen/codegen.py b/gio/gdbus-2.0/codegen/codegen.py
  17. index 41ea8fa..bca3490 100644
  18. --- a/gio/gdbus-2.0/codegen/codegen.py
  19. +++ b/gio/gdbus-2.0/codegen/codegen.py
  20. @@ -304,11 +304,8 @@ class CodeGenerator:
  21. #
  22. # See https://bugzilla.gnome.org/show_bug.cgi?id=647577#c5
  23. # for discussion
  24. - keys = function_pointers.keys()
  25. - if len(keys) > 0:
  26. - keys.sort(cmp=utils.my_version_cmp)
  27. - for key in keys:
  28. - self.h.write('%s'%function_pointers[key])
  29. + for key in sorted(function_pointers.keys(), key=utils.version_cmp_key):
  30. + self.h.write('%s'%function_pointers[key])
  31. self.h.write('};\n')
  32. self.h.write('\n')
  33. @@ -1022,11 +1019,9 @@ class CodeGenerator:
  34. value = '@get_%s: '%(p.name_lower)
  35. value += 'Getter for the #%s:%s property.'%(i.camel_name, p.name_hyphen)
  36. doc_bits[key] = value
  37. - keys = doc_bits.keys()
  38. - if len(keys) > 0:
  39. - keys.sort(cmp=utils.my_version_cmp)
  40. - for key in keys:
  41. - self.c.write(' * %s\n'%doc_bits[key])
  42. + for key in sorted(doc_bits.keys(), key=utils.version_cmp_key):
  43. + self.c.write(' * %s\n'%doc_bits[key])
  44. +
  45. self.c.write(self.docbook_gen.expand(
  46. ' *\n'
  47. ' * Virtual table for the D-Bus interface #%s.\n'
  48. diff --git a/gio/gdbus-2.0/codegen/codegen_docbook.py b/gio/gdbus-2.0/codegen/codegen_docbook.py
  49. index 4ceef57..00581f1 100644
  50. --- a/gio/gdbus-2.0/codegen/codegen_docbook.py
  51. +++ b/gio/gdbus-2.0/codegen/codegen_docbook.py
  52. @@ -259,14 +259,12 @@ class DocbookCodeGenerator:
  53. self.expand_member_dict[key] = value
  54. # Make sure to expand the keys in reverse order so e.g. #org.foo.Iface:MediaCompat
  55. # is evaluated before #org.foo.Iface:Media ...
  56. - self.expand_member_dict_keys = self.expand_member_dict.keys()
  57. - self.expand_member_dict_keys.sort(reverse=True)
  58. - self.expand_iface_dict_keys = self.expand_iface_dict.keys()
  59. - self.expand_iface_dict_keys.sort(reverse=True)
  60. + self.expand_member_dict_keys = sorted(self.expand_member_dict.keys(), reverse=True)
  61. + self.expand_iface_dict_keys = sorted(self.expand_iface_dict.keys(), reverse=True)
  62. def generate(self):
  63. for i in self.ifaces:
  64. - self.out = file('%s-%s.xml'%(self.docbook, i.name), 'w')
  65. + self.out = open('%s-%s.xml'%(self.docbook, i.name), 'w')
  66. self.out.write(''%())
  67. self.out.write('<?xml version="1.0" encoding="utf-8"?>\n'%())
  68. self.out.write('<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"\n'%())
  69. diff --git a/gio/gdbus-2.0/codegen/codegen_main.py b/gio/gdbus-2.0/codegen/codegen_main.py
  70. index 76c838c..735cc1f 100755
  71. --- a/gio/gdbus-2.0/codegen/codegen_main.py
  72. +++ b/gio/gdbus-2.0/codegen/codegen_main.py
  73. @@ -184,8 +184,8 @@ def codegen_main():
  74. c_code = opts.generate_c_code
  75. if c_code:
  76. - h = file(c_code + '.h', 'w')
  77. - c = file(c_code + '.c', 'w')
  78. + h = open(c_code + '.h', 'w')
  79. + c = open(c_code + '.c', 'w')
  80. gen = codegen.CodeGenerator(all_ifaces,
  81. opts.c_namespace,
  82. opts.interface_prefix,
  83. diff --git a/gio/gdbus-2.0/codegen/parser.py b/gio/gdbus-2.0/codegen/parser.py
  84. index 5fabd44..7b9d216 100644
  85. --- a/gio/gdbus-2.0/codegen/parser.py
  86. +++ b/gio/gdbus-2.0/codegen/parser.py
  87. @@ -152,12 +152,12 @@ class DBusXMLParser:
  88. self.state = DBusXMLParser.STATE_IGNORED
  89. # assign docs, if any
  90. - if attrs.has_key('name') and self.doc_comment_last_symbol == attrs['name']:
  91. + if 'name' in attrs and self.doc_comment_last_symbol == attrs['name']:
  92. self._cur_object.doc_string = self.doc_comment_body
  93. - if self.doc_comment_params.has_key('short_description'):
  94. + if 'short_description' in self.doc_comment_params:
  95. short_description = self.doc_comment_params['short_description']
  96. self._cur_object.doc_string_brief = short_description
  97. - if self.doc_comment_params.has_key('since'):
  98. + if 'since' in self.doc_comment_params:
  99. self._cur_object.since = self.doc_comment_params['since']
  100. elif self.state == DBusXMLParser.STATE_INTERFACE:
  101. @@ -185,16 +185,16 @@ class DBusXMLParser:
  102. self.state = DBusXMLParser.STATE_IGNORED
  103. # assign docs, if any
  104. - if attrs.has_key('name') and self.doc_comment_last_symbol == attrs['name']:
  105. + if 'name' in attrs and self.doc_comment_last_symbol == attrs['name']:
  106. self._cur_object.doc_string = self.doc_comment_body
  107. - if self.doc_comment_params.has_key('since'):
  108. + if 'since' in self.doc_comment_params:
  109. self._cur_object.since = self.doc_comment_params['since']
  110. elif self.state == DBusXMLParser.STATE_METHOD:
  111. if name == DBusXMLParser.STATE_ARG:
  112. self.state = DBusXMLParser.STATE_ARG
  113. arg_name = None
  114. - if attrs.has_key('name'):
  115. + if 'name' in attrs:
  116. arg_name = attrs['name']
  117. arg = dbustypes.Arg(arg_name, attrs['type'])
  118. direction = attrs['direction']
  119. @@ -215,18 +215,18 @@ class DBusXMLParser:
  120. # assign docs, if any
  121. if self.doc_comment_last_symbol == old_cur_object.name:
  122. - if attrs.has_key('name') and self.doc_comment_params.has_key(attrs['name']):
  123. + if 'name' in attrs and attrs['name'] in self.doc_comment_params:
  124. doc_string = self.doc_comment_params[attrs['name']]
  125. if doc_string != None:
  126. self._cur_object.doc_string = doc_string
  127. - if self.doc_comment_params.has_key('since'):
  128. + if 'since' in self.doc_comment_params:
  129. self._cur_object.since = self.doc_comment_params['since']
  130. elif self.state == DBusXMLParser.STATE_SIGNAL:
  131. if name == DBusXMLParser.STATE_ARG:
  132. self.state = DBusXMLParser.STATE_ARG
  133. arg_name = None
  134. - if attrs.has_key('name'):
  135. + if 'name' in attrs:
  136. arg_name = attrs['name']
  137. arg = dbustypes.Arg(arg_name, attrs['type'])
  138. self._cur_object.args.append(arg)
  139. @@ -241,11 +241,11 @@ class DBusXMLParser:
  140. # assign docs, if any
  141. if self.doc_comment_last_symbol == old_cur_object.name:
  142. - if attrs.has_key('name') and self.doc_comment_params.has_key(attrs['name']):
  143. + if 'name' in attrs and attrs['name'] in self.doc_comment_params:
  144. doc_string = self.doc_comment_params[attrs['name']]
  145. if doc_string != None:
  146. self._cur_object.doc_string = doc_string
  147. - if self.doc_comment_params.has_key('since'):
  148. + if 'since' in self.doc_comment_params:
  149. self._cur_object.since = self.doc_comment_params['since']
  150. elif self.state == DBusXMLParser.STATE_PROPERTY:
  151. diff --git a/gio/gdbus-2.0/codegen/utils.py b/gio/gdbus-2.0/codegen/utils.py
  152. index 94bd05c..239b64e 100644
  153. --- a/gio/gdbus-2.0/codegen/utils.py
  154. +++ b/gio/gdbus-2.0/codegen/utils.py
  155. @@ -97,15 +97,8 @@ def lookup_brief_docs(annotations):
  156. else:
  157. return s
  158. -# I'm sure this could be a lot more elegant if I was
  159. -# more fluent in python...
  160. -def my_version_cmp(a, b):
  161. - if len(a[0]) > 0 and len(b[0]) > 0:
  162. - va = distutils.version.LooseVersion(a[0])
  163. - vb = distutils.version.LooseVersion(b[0])
  164. - ret = va.__cmp__(vb)
  165. - else:
  166. - ret = cmp(a[0], b[0])
  167. - if ret != 0:
  168. - return ret
  169. - return cmp(a[1], b[1])
  170. +def version_cmp_key(key):
  171. + # If the 'since' version is empty put a 0 in its place as this will
  172. + # allow LooseVersion to work and will always compare lower.
  173. + v = key[0] if key[0] else '0'
  174. + return (distutils.version.LooseVersion(v), key[1])
  175. --
  176. cgit v0.9.0.2