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
6 Content-Type: text/plain; charset=utf-8
7 Content-Transfer-Encoding: 8bit
9 Python scripts are now compatible with both version of python, 2 and 3.
11 Helped-by: Damien Riegel <damien.riegel@savoirfairelinux.com>
12 Helped-by: Alexandre Leblanc <alexandre.leblanc@savoirfairelinux.com>
13 Signed-off-by: Gaƫl PORTAY <gael.portay@savoirfairelinux.com>
15 maketables | 135 ++++++++++++++++++++++++++++++-----------------------------
17 2 files changed, 73 insertions(+), 70 deletions(-)
19 diff --git a/maketables b/maketables
20 index 0726485..f74f2b1 100755
23 @@ -51,6 +51,7 @@ value. (This is for consistency with C array bounds.)
28 from templatefile import TemplateFile
31 @@ -58,74 +59,74 @@ class DataType:
33 def __init__(self, path):
34 """read the first line of path, then make tuples of the rest"""
36 - definition = source.readline().rstrip()
37 - self.name, qualifiers = string.split(definition, ': ', 2)
38 - if '; ' in qualifiers:
39 - self.prefix, columns = string.split(qualifiers, '; ')
41 - self.prefix = qualifiers
46 - columns = string.split(columns, ', ')
49 - if col.startswith("FLAGS"):
50 - print("Flags: set for %s" % self.name)
52 + with open(path,'r') as source:
53 + definition = source.readline().rstrip()
54 + self.name, qualifiers = definition.split(': ', 2)
55 + if '; ' in qualifiers:
56 + self.prefix, columns = qualifiers.split('; ')
58 + self.prefix = qualifiers
63 + columns = columns.split(', ')
66 + if col.startswith("FLAGS"):
67 + print("Flags: set for %s" % self.name)
70 + if col.startswith("INDEXED "):
74 + name, default = col.split(' = ')
76 + name, default = col, ""
78 + words = name.split(' ')
81 + type = ' '.join(words)
84 + self.columns.append({"indexed":indexed, "type":type, "name":name, "value":default})
90 + for line in source.readlines():
92 + if line.startswith('#'):
93 + self.comments.append(line.rstrip().replace('#', ''))
95 - if col.startswith("INDEXED "):
99 - name, default = string.split(col, ' = ')
101 - name, default = col, ""
103 - words = string.split(name, ' ')
106 - type = ' '.join(words)
109 - self.columns.append({"indexed":indexed, "type":type, "name":name, "value":default})
115 - for line in source.readlines():
117 - if line.startswith('#'):
118 - self.comments.append(line.rstrip().replace('#', ''))
120 - # first entry on the line is the "real" name/id, following hunks
121 - # are additional columns
122 - cols = string.split(line.rstrip(), ', ')
123 - item["name"] = cols.pop(0)
124 - item["upper"] = item["name"].replace('-', '_').upper()
126 - for col in self.columns:
128 - value = cols.pop(0)
130 - if not "max" in col:
132 - if value > col["max"]:
134 - if not "min" in col:
136 - if value < col["min"]:
138 - column_list.append({"name":col["name"], "value":value})
140 - column_list.append({"name":col["name"], "value":col["value"]})
141 - item["cols"] = column_list
142 - item["index"] = index
144 - self.data.append(item)
145 + # first entry on the line is the "real" name/id, following hunks
146 + # are additional columns
147 + cols = line.rstrip().split(', ')
148 + item["name"] = cols.pop(0)
149 + item["upper"] = item["name"].replace('-', '_').upper()
151 + for col in self.columns:
153 + value = cols.pop(0)
155 + if not "max" in col:
157 + if value > col["max"]:
159 + if not "min" in col:
161 + if value < col["min"]:
163 + column_list.append({"name":col["name"], "value":value})
165 + column_list.append({"name":col["name"], "value":col["value"]})
166 + item["cols"] = column_list
167 + item["index"] = index
169 + self.data.append(item)
171 def __getitem__(self, key):
172 """Make this object look like a dict for Templates to use"""
173 diff --git a/makewrappers b/makewrappers
174 index bac856b..ff08ba0 100755
177 @@ -453,6 +453,8 @@ additional ports to include.
180 def __init__(self, port, sources):
181 + if type(port) is not str:
182 + port = str(port, encoding="ascii")
186 @@ -483,7 +485,7 @@ additional ports to include.
188 raise Exception("preports script failed for port %s" % self.name)
190 - for preport in string.split(portlist):
191 + for preport in portlist.split():
192 next = Port(preport, sources)
193 self.preports.append(next)
195 @@ -494,7 +496,7 @@ additional ports to include.
197 raise Exception("subports script failed for port %s" % self.name)
199 - for subport in string.split(portlist):
200 + for subport in portlist.split():
201 next = Port(subport, sources)
202 self.subports.append(next)
204 @@ -519,7 +521,7 @@ additional ports to include.
208 - return '#define PSEUDO_PORT_%s 1' % string.upper(self.name).replace('/', '_')
209 + return '#define PSEUDO_PORT_%s 1' % self.name.upper().replace('/', '_')