summaryrefslogtreecommitdiffstats
path: root/package/pseudo/0003-Make-it-compatible-with-python3.patch
blob: 3bb74deacf94802aaccd7db4e5ba63a259d7a5aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
From fcc10b1f4a9968af5cda1adb9e449df92939d5f2 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Ga=C3=ABl=20PORTAY?= <gael.portay@savoirfairelinux.com>
Date: Fri, 4 Nov 2016 15:58:46 -0400
Subject: [PATCH 3/3] Make it compatible with python3
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

Python scripts are now compatible with both version of python, 2 and 3.

Helped-by: Damien Riegel <damien.riegel@savoirfairelinux.com>
Helped-by: Alexandre Leblanc <alexandre.leblanc@savoirfairelinux.com>
Signed-off-by: Gaƫl PORTAY <gael.portay@savoirfairelinux.com>
---
 maketables   | 135 ++++++++++++++++++++++++++++++-----------------------------
 makewrappers |   8 ++--
 2 files changed, 73 insertions(+), 70 deletions(-)

diff --git a/maketables b/maketables
index 0726485..f74f2b1 100755
--- a/maketables
+++ b/maketables
@@ -51,6 +51,7 @@ value.  (This is for consistency with C array bounds.)
 import glob
 import sys
 import string
+import os
 from templatefile import TemplateFile
 
 class DataType:
@@ -58,74 +59,74 @@ class DataType:
 
     def __init__(self, path):
         """read the first line of path, then make tuples of the rest"""
-        source = file(path)
-        definition = source.readline().rstrip()
-        self.name, qualifiers = string.split(definition, ': ', 2)
-        if '; ' in qualifiers:
-            self.prefix, columns = string.split(qualifiers, '; ')
-        else:
-            self.prefix = qualifiers
-            columns = []
-        self.flags = False
-        if len(columns):
-            self.columns = []
-            columns = string.split(columns, ', ')
-            for col in columns:
-                indexed = False
-                if col.startswith("FLAGS"):
-                    print("Flags: set for %s" % self.name)
-                    self.flags = True
+        with open(path,'r') as source:
+            definition = source.readline().rstrip()
+            self.name, qualifiers = definition.split(': ', 2)
+            if '; ' in qualifiers:
+                self.prefix, columns = qualifiers.split('; ')
+            else:
+                self.prefix = qualifiers
+                columns = []
+            self.flags = False
+            if len(columns):
+                self.columns = []
+                columns = columns.split(', ')
+                for col in columns:
+                    indexed = False
+                    if col.startswith("FLAGS"):
+                        print("Flags: set for %s" % self.name)
+                        self.flags = True
+                        continue
+                    if col.startswith("INDEXED "):
+                        col = col[8:]
+                        indexed = True
+                    if "=" in col:
+                        name, default = col.split(' = ')
+                    else:
+                        name, default = col, ""
+                    if " " in name:
+                        words = name.split(' ')
+                        name = words[-1]
+                        del words[-1]
+                        type = ' '.join(words)
+                    else:
+                        type = "char *"
+                    self.columns.append({"indexed":indexed, "type":type, "name":name, "value":default})
+            else:
+                self.columns = []
+            self.data = []
+            self.comments = []
+            index = 1
+            for line in source.readlines():
+                item = {}
+                if line.startswith('#'):
+                    self.comments.append(line.rstrip().replace('#', ''))
                     continue
-                if col.startswith("INDEXED "):
-                    col = col[8:]
-                    indexed = True
-                if "=" in col:
-                    name, default = string.split(col, ' = ')
-                else:
-                    name, default = col, ""
-                if " " in name:
-                    words = string.split(name, ' ')
-                    name = words[-1]
-                    del words[-1]
-                    type = ' '.join(words)
-                else:
-                    type = "char *"
-                self.columns.append({"indexed":indexed, "type":type, "name":name, "value":default})
-        else:
-            self.columns = []
-        self.data = []
-        self.comments = []
-        index = 1
-        for line in source.readlines():
-            item = {}
-            if line.startswith('#'):
-                self.comments.append(line.rstrip().replace('#', ''))
-                continue
-            # first entry on the line is the "real" name/id, following hunks
-            # are additional columns
-            cols = string.split(line.rstrip(), ', ')
-            item["name"] = cols.pop(0)
-            item["upper"] = item["name"].replace('-', '_').upper()
-            column_list = []
-            for col in self.columns:
-                if len(cols) > 0:
-                    value = cols.pop(0)
-                    if col["indexed"]:
-                        if not "max" in col:
-                            col["max"] = value
-                        if value > col["max"]:
-                            col["max"] = value
-                        if not "min" in col:
-                            col["min"] = value
-                        if value < col["min"]:
-                            col["min"] = value
-                    column_list.append({"name":col["name"], "value":value})
-                else:
-                    column_list.append({"name":col["name"], "value":col["value"]})
-            item["cols"] = column_list
-            item["index"] = index
-            index = index + 1
-            self.data.append(item)
+                # first entry on the line is the "real" name/id, following hunks
+                # are additional columns
+                cols = line.rstrip().split(', ')
+                item["name"] = cols.pop(0)
+                item["upper"] = item["name"].replace('-', '_').upper()
+                column_list = []
+                for col in self.columns:
+                    if len(cols) > 0:
+                        value = cols.pop(0)
+                        if col["indexed"]:
+                            if not "max" in col:
+                                col["max"] = value
+                            if value > col["max"]:
+                                col["max"] = value
+                            if not "min" in col:
+                                col["min"] = value
+                            if value < col["min"]:
+                                col["min"] = value
+                        column_list.append({"name":col["name"], "value":value})
+                    else:
+                        column_list.append({"name":col["name"], "value":col["value"]})
+                item["cols"] = column_list
+                item["index"] = index
+                index = index + 1
+                self.data.append(item)
 
     def __getitem__(self, key):
         """Make this object look like a dict for Templates to use"""
diff --git a/makewrappers b/makewrappers
index bac856b..ff08ba0 100755
--- a/makewrappers
+++ b/makewrappers
@@ -453,6 +453,8 @@ additional ports to include.
 """
 
     def __init__(self, port, sources):
+        if type(port) is not str:
+            port = str(port, encoding="ascii")
         self.name = port
         self.subports = []
         self.preports = []
@@ -483,7 +485,7 @@ additional ports to include.
             if retcode:
                 raise Exception("preports script failed for port %s" % self.name)
 
-            for preport in string.split(portlist):
+            for preport in portlist.split():
                 next = Port(preport, sources)
                 self.preports.append(next)
 
@@ -494,7 +496,7 @@ additional ports to include.
             if retcode:
                 raise Exception("subports script failed for port %s" % self.name)
 
-            for subport in string.split(portlist):
+            for subport in portlist.split():
                 next = Port(subport, sources)
                 self.subports.append(next)
 
@@ -519,7 +521,7 @@ additional ports to include.
         return mergedfuncs
 
     def define(self):
-        return '#define PSEUDO_PORT_%s 1' % string.upper(self.name).replace('/', '_')
+        return '#define PSEUDO_PORT_%s 1' % self.name.upper().replace('/', '_')
 
     def portdeps(self):
         deps = []
-- 
2.10.1

OpenPOWER on IntegriCloud