mirror of https://github.com/ecmwf/eccodes.git
Fix memfs.py to work with Python 2
This commit is contained in:
parent
bdb3321519
commit
4e2cd7e4a7
13
memfs.py
13
memfs.py
|
@ -13,6 +13,13 @@ print(dirs)
|
|||
FILES = {}
|
||||
NAMES = []
|
||||
|
||||
try:
|
||||
str("",'ascii')
|
||||
ascii = lambda x: str(x, 'ascii')
|
||||
except:
|
||||
ascii = lambda x: str(x)
|
||||
|
||||
|
||||
# The last argument is the generated C file
|
||||
g = open(sys.argv[-1], "w")
|
||||
|
||||
|
@ -30,7 +37,7 @@ for directory in dirs:
|
|||
continue
|
||||
|
||||
fname = full[full.find("/%s/" % (dname,)):]
|
||||
#print("MEMFS add", fname)
|
||||
print("MEMFS add", fname)
|
||||
name = re.sub(r'\W', '_', fname)
|
||||
|
||||
assert name not in FILES
|
||||
|
@ -49,9 +56,7 @@ for directory in dirs:
|
|||
# Read two characters at a time and convert to C hex
|
||||
# e.g. 23 -> 0x23
|
||||
for n in range(0, len(fcont), 2):
|
||||
twoChars = fcont[n:n+2]
|
||||
if sys.version_info.major > 2:
|
||||
twoChars = str(twoChars,'ascii')
|
||||
twoChars = ascii(fcont[n:n+2])
|
||||
print("0x%s," % (twoChars,), end="", file=g)
|
||||
i += 1
|
||||
if (i % 20) == 0:
|
||||
|
|
Loading…
Reference in New Issue