mirror of https://github.com/ecmwf/eccodes.git
ECC-917: eccodes_memfs (part 1)
This commit is contained in:
parent
f0f1fec2a8
commit
4731805b7e
19
memfs.py
19
memfs.py
|
@ -28,6 +28,7 @@ print('Directories: ', dirs)
|
||||||
print('Excluding: ', EXCLUDED)
|
print('Excluding: ', EXCLUDED)
|
||||||
|
|
||||||
FILES = {}
|
FILES = {}
|
||||||
|
SIZES = {}
|
||||||
NAMES = []
|
NAMES = []
|
||||||
|
|
||||||
# Binary to ASCII function. Different in Python 2 and 3
|
# Binary to ASCII function. Different in Python 2 and 3
|
||||||
|
@ -61,28 +62,32 @@ for directory in dirs:
|
||||||
if ext not in ['.def', '.table', '.tmpl']:
|
if ext not in ['.def', '.table', '.tmpl']:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
fsize = os.path.getsize(full)
|
||||||
full = full.replace("\\","/")
|
full = full.replace("\\","/")
|
||||||
fname = full[full.find("/%s/" % (dname,)):]
|
fname = full[full.find("/%s/" % (dname,)):]
|
||||||
#print("MEMFS add", fname)
|
#print("MEMFS add", fname)
|
||||||
name = re.sub(r'\W', '_', fname)
|
name = re.sub(r'\W', '_', fname)
|
||||||
|
|
||||||
assert name not in FILES
|
assert name not in FILES
|
||||||
|
assert name not in SIZES
|
||||||
FILES[name] = fname
|
FILES[name] = fname
|
||||||
|
SIZES[name] = fsize
|
||||||
|
|
||||||
print('static const unsigned char %s[] = {' % (name,), file=g)
|
print('static const unsigned char %s[] = {' % (name,), file=g)
|
||||||
|
#print('const unsigned char %s[] = {' % (name,), file=g) #NEW
|
||||||
|
|
||||||
with open(full, 'rb') as f:
|
with open(full, 'rb') as f:
|
||||||
i = 0
|
i = 0
|
||||||
#Python 2
|
#Python 2
|
||||||
#fcont = f.read().encode("hex")
|
#contents_hex = f.read().encode("hex")
|
||||||
|
|
||||||
#Python 2 and 3
|
#Python 2 and 3
|
||||||
fcont = binascii.hexlify(f.read())
|
contents_hex = binascii.hexlify(f.read())
|
||||||
|
|
||||||
# Read two characters at a time and convert to C hex
|
# Read two characters at a time and convert to C hex
|
||||||
# e.g. 23 -> 0x23
|
# e.g. 23 -> 0x23
|
||||||
for n in range(0, len(fcont), 2):
|
for n in range(0, len(contents_hex), 2):
|
||||||
twoChars = ascii(fcont[n:n+2])
|
twoChars = ascii(contents_hex[n:n+2])
|
||||||
print("0x%s," % (twoChars,), end="", file=g)
|
print("0x%s," % (twoChars,), end="", file=g)
|
||||||
i += 1
|
i += 1
|
||||||
if (i % 20) == 0:
|
if (i % 20) == 0:
|
||||||
|
@ -101,7 +106,13 @@ print("""
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "eccodes_windef.h"
|
#include "eccodes_windef.h"
|
||||||
|
""", file=g)
|
||||||
|
|
||||||
|
# NEW
|
||||||
|
#for k, v in SIZES.items():
|
||||||
|
# print ('extern const unsigned char %s[%d];' % (k, v), file=g)
|
||||||
|
|
||||||
|
print("""
|
||||||
struct entry {
|
struct entry {
|
||||||
const char* path;
|
const char* path;
|
||||||
const unsigned char* content;
|
const unsigned char* content;
|
||||||
|
|
Loading…
Reference in New Issue