diff --git a/dist/tools/mkconstfs/mkconstfs.py b/dist/tools/mkconstfs/mkconstfs.py index bda89c76d888ac18f67530d918165302d80abd04..1b56492546ee0dbe7f97682e15349263b9579b47 100755 --- a/dist/tools/mkconstfs/mkconstfs.py +++ b/dist/tools/mkconstfs/mkconstfs.py @@ -5,6 +5,8 @@ import os import sys FILE_TYPE = "static const uint8_t" +FILES = [] + def mkconstfs(root_path, mount_point, constfs_name): print("/* This file was automatically generated by mkconstfs */") @@ -20,7 +22,7 @@ def mkconstfs(root_path, mount_point, constfs_name): print("\nstatic const constfs_file_t _files[] = {") - for mangled_name, target_name, _ in files: + for mangled_name, target_name, _ in FILES: print(" {") print(" .path = \"%s\"," % target_name) print(" .data = %s," % mangled_name) @@ -41,12 +43,14 @@ vfs_mount_t %s = { }; """ % (constfs_name, mount_point)) + def mangle_name(fname): fname = fname.replace("/", "__") fname = fname.replace(".", "__") return fname + def print_file_data(local_fname, target_fname): mangled_name = mangle_name(target_fname) print(FILE_TYPE, mangled_name, "[] = {", end="") @@ -63,17 +67,16 @@ def print_file_data(local_fname, target_fname): else: print(", ", end="") nread += 1 - print ("0x" + codecs.encode(byte, 'hex').decode('ascii'), end="") + print("0x" + codecs.encode(byte, 'hex').decode('ascii'), end="") # Do stuff with byte. byte = f.read(1) print("\n};") - files.append((mangled_name, target_fname, nread)) + FILES.append((mangled_name, target_fname, nread)) -files = [] -if __name__=="__main__": +if __name__ == "__main__": mountpoint = "/" constfs_name = "_constfs"