123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- 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
|