Better handling of memfs

This commit is contained in:
Baudouin Raoult 2021-08-30 08:34:39 +01:00
parent 44518bee3d
commit 2b84a6d527
2 changed files with 67 additions and 22 deletions

View File

@ -1,12 +1,54 @@
#!/usr/bin/env python
from __future__ import print_function
import argparse
import binascii
import os
import re
import sys
import binascii
import time
assert len(sys.argv) > 2
parser = argparse.ArgumentParser()
parser.add_argument(
"-n",
"--count",
type=int,
default=10,
help="Number of files to generate",
)
parser.add_argument(
"-C",
"--chunk",
type=int,
default=16,
help="Chunk size (MB)",
)
parser.add_argument(
"-o",
"--output",
type=str,
default="memfs_gen",
help="Name of C file to generate",
)
parser.add_argument(
"-e",
"--exclude",
help="Exclude packages",
)
parser.add_argument(
"dirs",
type=str,
nargs="+",
help="The list of directories to process",
)
args = parser.parse_args()
start = time.time()
print("MEMFS: starting")
@ -15,25 +57,23 @@ print("MEMFS: starting")
# The BUFR codetables is not used in the engine
EXCLUDED = ["grib3", "codetables", "taf", "stations"]
pos = 1
if sys.argv[1] == "-exclude":
product = sys.argv[2]
if product == "bufr":
EXCLUDED.append(product)
elif product == "grib":
EXCLUDED.extend(["grib1", "grib2"])
else:
assert False, "Invalid product %s" % product
pos = 3
EXCLUDE = {
None: [],
"bufr": ["bufr"],
"grib": ["grib1", "grib2"],
}
dirs = [os.path.realpath(x) for x in sys.argv[pos:-1]]
EXCLUDED.extend(EXCLUDE[args.exclude])
dirs = [os.path.realpath(x) for x in args.dirs]
print("Directories: ", dirs)
print("Excluding: ", EXCLUDED)
FILES = {}
SIZES = {}
NAMES = []
CHUNK = 14 * 1024 * 1024 # chunk size in bytes
CHUNK = args.chunk * 1024 * 1024 # chunk size in bytes
# Binary to ASCII function. Different in Python 2 and 3
try:
@ -48,11 +88,11 @@ def get_outfile_name(base, count):
# The last argument is the base name of the generated C file(s)
output_file_base = sys.argv[-1]
output_file_base = args.output
buffer = None
fcount = 0
MAX_FCOUNT = 10
MAX_FCOUNT = args.count
for directory in dirs:

View File

@ -1,3 +1,8 @@
list( APPEND memfs_args
--count 10
--output ${CMAKE_CURRENT_BINARY_DIR}/memfs_gen
)
set( generated_c_files
${CMAKE_CURRENT_BINARY_DIR}/memfs_gen_000.c
${CMAKE_CURRENT_BINARY_DIR}/memfs_gen_001.c
@ -11,21 +16,21 @@ set( generated_c_files
${CMAKE_CURRENT_BINARY_DIR}/memfs_gen_009.c
${CMAKE_CURRENT_BINARY_DIR}/memfs_gen_final.c)
set( exclude "" )
if( NOT HAVE_PRODUCT_BUFR )
set( exclude -exclude bufr )
elseif( NOT HAVE_PRODUCT_GRIB )
set( exclude -exclude grib )
list( APPEND memfs_args --exclude bufr)
endif()
if( NOT HAVE_PRODUCT_GRIB )
list( APPEND memfs_args --exclude grib)
endif()
add_custom_command(
OUTPUT ${generated_c_files}
COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/memfs.py
${exclude}
${memfs_args}
${PROJECT_SOURCE_DIR}/definitions
${PROJECT_SOURCE_DIR}/samples
${PROJECT_SOURCE_DIR}/ifs_samples
${CMAKE_CURRENT_BINARY_DIR}/memfs_gen
DEPENDS ${PROJECT_SOURCE_DIR}/memfs.py)
set_source_files_properties(