0003-Make-it-compatible-with-python3.patch 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. From fcc10b1f4a9968af5cda1adb9e449df92939d5f2 Mon Sep 17 00:00:00 2001
  2. From: =?utf-8?q?Ga=C3=ABl=20PORTAY?= <gael.portay@savoirfairelinux.com>
  3. Date: Fri, 4 Nov 2016 15:58:46 -0400
  4. Subject: [PATCH 3/3] Make it compatible with python3
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=utf-8
  7. Content-Transfer-Encoding: 8bit
  8. Python scripts are now compatible with both version of python, 2 and 3.
  9. Helped-by: Damien Riegel <damien.riegel@savoirfairelinux.com>
  10. Helped-by: Alexandre Leblanc <alexandre.leblanc@savoirfairelinux.com>
  11. Signed-off-by: Gaël PORTAY <gael.portay@savoirfairelinux.com>
  12. ---
  13. maketables | 135 ++++++++++++++++++++++++++++++-----------------------------
  14. makewrappers | 8 ++--
  15. 2 files changed, 73 insertions(+), 70 deletions(-)
  16. diff --git a/maketables b/maketables
  17. index 0726485..f74f2b1 100755
  18. --- a/maketables
  19. +++ b/maketables
  20. @@ -51,6 +51,7 @@ value. (This is for consistency with C array bounds.)
  21. import glob
  22. import sys
  23. import string
  24. +import os
  25. from templatefile import TemplateFile
  26. class DataType:
  27. @@ -58,74 +59,74 @@ class DataType:
  28. def __init__(self, path):
  29. """read the first line of path, then make tuples of the rest"""
  30. - source = file(path)
  31. - definition = source.readline().rstrip()
  32. - self.name, qualifiers = string.split(definition, ': ', 2)
  33. - if '; ' in qualifiers:
  34. - self.prefix, columns = string.split(qualifiers, '; ')
  35. - else:
  36. - self.prefix = qualifiers
  37. - columns = []
  38. - self.flags = False
  39. - if len(columns):
  40. - self.columns = []
  41. - columns = string.split(columns, ', ')
  42. - for col in columns:
  43. - indexed = False
  44. - if col.startswith("FLAGS"):
  45. - print("Flags: set for %s" % self.name)
  46. - self.flags = True
  47. + with open(path,'r') as source:
  48. + definition = source.readline().rstrip()
  49. + self.name, qualifiers = definition.split(': ', 2)
  50. + if '; ' in qualifiers:
  51. + self.prefix, columns = qualifiers.split('; ')
  52. + else:
  53. + self.prefix = qualifiers
  54. + columns = []
  55. + self.flags = False
  56. + if len(columns):
  57. + self.columns = []
  58. + columns = columns.split(', ')
  59. + for col in columns:
  60. + indexed = False
  61. + if col.startswith("FLAGS"):
  62. + print("Flags: set for %s" % self.name)
  63. + self.flags = True
  64. + continue
  65. + if col.startswith("INDEXED "):
  66. + col = col[8:]
  67. + indexed = True
  68. + if "=" in col:
  69. + name, default = col.split(' = ')
  70. + else:
  71. + name, default = col, ""
  72. + if " " in name:
  73. + words = name.split(' ')
  74. + name = words[-1]
  75. + del words[-1]
  76. + type = ' '.join(words)
  77. + else:
  78. + type = "char *"
  79. + self.columns.append({"indexed":indexed, "type":type, "name":name, "value":default})
  80. + else:
  81. + self.columns = []
  82. + self.data = []
  83. + self.comments = []
  84. + index = 1
  85. + for line in source.readlines():
  86. + item = {}
  87. + if line.startswith('#'):
  88. + self.comments.append(line.rstrip().replace('#', ''))
  89. continue
  90. - if col.startswith("INDEXED "):
  91. - col = col[8:]
  92. - indexed = True
  93. - if "=" in col:
  94. - name, default = string.split(col, ' = ')
  95. - else:
  96. - name, default = col, ""
  97. - if " " in name:
  98. - words = string.split(name, ' ')
  99. - name = words[-1]
  100. - del words[-1]
  101. - type = ' '.join(words)
  102. - else:
  103. - type = "char *"
  104. - self.columns.append({"indexed":indexed, "type":type, "name":name, "value":default})
  105. - else:
  106. - self.columns = []
  107. - self.data = []
  108. - self.comments = []
  109. - index = 1
  110. - for line in source.readlines():
  111. - item = {}
  112. - if line.startswith('#'):
  113. - self.comments.append(line.rstrip().replace('#', ''))
  114. - continue
  115. - # first entry on the line is the "real" name/id, following hunks
  116. - # are additional columns
  117. - cols = string.split(line.rstrip(), ', ')
  118. - item["name"] = cols.pop(0)
  119. - item["upper"] = item["name"].replace('-', '_').upper()
  120. - column_list = []
  121. - for col in self.columns:
  122. - if len(cols) > 0:
  123. - value = cols.pop(0)
  124. - if col["indexed"]:
  125. - if not "max" in col:
  126. - col["max"] = value
  127. - if value > col["max"]:
  128. - col["max"] = value
  129. - if not "min" in col:
  130. - col["min"] = value
  131. - if value < col["min"]:
  132. - col["min"] = value
  133. - column_list.append({"name":col["name"], "value":value})
  134. - else:
  135. - column_list.append({"name":col["name"], "value":col["value"]})
  136. - item["cols"] = column_list
  137. - item["index"] = index
  138. - index = index + 1
  139. - self.data.append(item)
  140. + # first entry on the line is the "real" name/id, following hunks
  141. + # are additional columns
  142. + cols = line.rstrip().split(', ')
  143. + item["name"] = cols.pop(0)
  144. + item["upper"] = item["name"].replace('-', '_').upper()
  145. + column_list = []
  146. + for col in self.columns:
  147. + if len(cols) > 0:
  148. + value = cols.pop(0)
  149. + if col["indexed"]:
  150. + if not "max" in col:
  151. + col["max"] = value
  152. + if value > col["max"]:
  153. + col["max"] = value
  154. + if not "min" in col:
  155. + col["min"] = value
  156. + if value < col["min"]:
  157. + col["min"] = value
  158. + column_list.append({"name":col["name"], "value":value})
  159. + else:
  160. + column_list.append({"name":col["name"], "value":col["value"]})
  161. + item["cols"] = column_list
  162. + item["index"] = index
  163. + index = index + 1
  164. + self.data.append(item)
  165. def __getitem__(self, key):
  166. """Make this object look like a dict for Templates to use"""
  167. diff --git a/makewrappers b/makewrappers
  168. index bac856b..ff08ba0 100755
  169. --- a/makewrappers
  170. +++ b/makewrappers
  171. @@ -453,6 +453,8 @@ additional ports to include.
  172. """
  173. def __init__(self, port, sources):
  174. + if type(port) is not str:
  175. + port = str(port, encoding="ascii")
  176. self.name = port
  177. self.subports = []
  178. self.preports = []
  179. @@ -483,7 +485,7 @@ additional ports to include.
  180. if retcode:
  181. raise Exception("preports script failed for port %s" % self.name)
  182. - for preport in string.split(portlist):
  183. + for preport in portlist.split():
  184. next = Port(preport, sources)
  185. self.preports.append(next)
  186. @@ -494,7 +496,7 @@ additional ports to include.
  187. if retcode:
  188. raise Exception("subports script failed for port %s" % self.name)
  189. - for subport in string.split(portlist):
  190. + for subport in portlist.split():
  191. next = Port(subport, sources)
  192. self.subports.append(next)
  193. @@ -519,7 +521,7 @@ additional ports to include.
  194. return mergedfuncs
  195. def define(self):
  196. - return '#define PSEUDO_PORT_%s 1' % string.upper(self.name).replace('/', '_')
  197. + return '#define PSEUDO_PORT_%s 1' % self.name.upper().replace('/', '_')
  198. def portdeps(self):
  199. deps = []
  200. --
  201. 2.10.1