From 4731805b7ec3e250bf255efa01a874567b64a0a5 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Thu, 2 Apr 2020 16:46:49 +0100 Subject: [PATCH] ECC-917: eccodes_memfs (part 1) --- memfs.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/memfs.py b/memfs.py index 07d422648..fdee6af01 100755 --- a/memfs.py +++ b/memfs.py @@ -28,6 +28,7 @@ print('Directories: ', dirs) print('Excluding: ', EXCLUDED) FILES = {} +SIZES = {} NAMES = [] # 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']: continue + fsize = os.path.getsize(full) full = full.replace("\\","/") fname = full[full.find("/%s/" % (dname,)):] #print("MEMFS add", fname) name = re.sub(r'\W', '_', fname) assert name not in FILES + assert name not in SIZES FILES[name] = fname + SIZES[name] = fsize print('static const unsigned char %s[] = {' % (name,), file=g) + #print('const unsigned char %s[] = {' % (name,), file=g) #NEW with open(full, 'rb') as f: i = 0 #Python 2 - #fcont = f.read().encode("hex") + #contents_hex = f.read().encode("hex") #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 # e.g. 23 -> 0x23 - for n in range(0, len(fcont), 2): - twoChars = ascii(fcont[n:n+2]) + for n in range(0, len(contents_hex), 2): + twoChars = ascii(contents_hex[n:n+2]) print("0x%s," % (twoChars,), end="", file=g) i += 1 if (i % 20) == 0: @@ -101,7 +106,13 @@ print(""" #include #include #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 { const char* path; const unsigned char* content;