Make-gtk-builder-convert-compatible-with-Python-3.patch 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. From: Petr Viktorin <encukou@gmail.com>
  2. Date: Tue, 3 Sep 2019 13:54:49 +0200
  3. Subject: Make gtk-builder-convert compatible with Python 3
  4. - Convert tabs to spaces
  5. - Use print as a function, even on Python 2
  6. - Output a binary file, or decode for stdout
  7. Origin: upstream, 2.24.33, commit:3ff8f70b9686205f0618d7a479fd42a457b90165
  8. ---
  9. gtk/gtk-builder-convert | 25 ++++++++++++++-----------
  10. 1 file changed, 14 insertions(+), 11 deletions(-)
  11. diff --git a/gtk/gtk-builder-convert b/gtk/gtk-builder-convert
  12. index ea737de..41f7a8c 100755
  13. --- a/gtk/gtk-builder-convert
  14. +++ b/gtk/gtk-builder-convert
  15. @@ -36,6 +36,7 @@ Examples:
  16. Report bugs to http://bugzilla.gnome.org/."""
  17. +from __future__ import print_function
  18. import getopt
  19. import os
  20. import sys
  21. @@ -259,7 +260,7 @@ class GtkBuilderConverter(object):
  22. for node in objects:
  23. self._convert(node.getAttribute("class"), node)
  24. if self._get_object(node.getAttribute('id')) is not None:
  25. - print "WARNING: duplicate id \"" + node.getAttribute('id') + "\""
  26. + print("WARNING: duplicate id \"" + node.getAttribute('id') + "\"")
  27. self.objects[node.getAttribute('id')] = node
  28. # Convert Gazpachos UI tag
  29. @@ -277,8 +278,7 @@ class GtkBuilderConverter(object):
  30. # reverse=True):
  31. # when we can depend on python 2.4 or higher
  32. root_objects = self.root_objects[:]
  33. - root_objects.sort(lambda a, b: cmp(b.getAttribute('id'),
  34. - a.getAttribute('id')))
  35. + root_objects.sort(key=lambda a: a.getAttribute('id'), reverse=True)
  36. for obj in root_objects:
  37. self._interface.childNodes.insert(0, obj)
  38. @@ -461,8 +461,8 @@ class GtkBuilderConverter(object):
  39. if signal_name in ['activate', 'toggled']:
  40. action.appendChild(signal)
  41. else:
  42. - print 'Unhandled signal %s::%s' % (node.getAttribute('class'),
  43. - signal_name)
  44. + print('Unhandled signal %s::%s' % (node.getAttribute('class'),
  45. + signal_name))
  46. if not uimgr.childNodes:
  47. child = self._dom.createElement('child')
  48. @@ -481,8 +481,8 @@ class GtkBuilderConverter(object):
  49. for accelerator in get_accelerator_nodes(node):
  50. signal_name = accelerator.getAttribute('signal')
  51. if signal_name != 'activate':
  52. - print 'Unhandled accelerator signal for %s::%s' % (
  53. - node.getAttribute('class'), signal_name)
  54. + print('Unhandled accelerator signal for %s::%s' % (
  55. + node.getAttribute('class'), signal_name))
  56. continue
  57. accelerator.removeAttribute('signal')
  58. child.appendChild(accelerator)
  59. @@ -747,7 +747,7 @@ def _indent(output):
  60. return s.stdout.read()
  61. def usage():
  62. - print __doc__
  63. + print(__doc__)
  64. def main(args):
  65. try:
  66. @@ -788,10 +788,13 @@ def main(args):
  67. xml = _indent(conv.to_xml())
  68. if output_filename == "-":
  69. - print xml
  70. + if isinstance(xml, str):
  71. + print(xml)
  72. + else:
  73. + print(xml.decode(sys.stdout.encoding))
  74. else:
  75. - open(output_filename, 'w').write(xml)
  76. - print "Wrote", output_filename
  77. + open(output_filename, 'wb').write(xml)
  78. + print("Wrote", output_filename)
  79. return 0