mirror of https://github.com/ecmwf/eccodes.git
Better handling of memfs
This commit is contained in:
parent
44518bee3d
commit
2b84a6d527
72
memfs.py
72
memfs.py
|
@ -1,12 +1,54 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import binascii
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import binascii
|
|
||||||
import time
|
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()
|
start = time.time()
|
||||||
print("MEMFS: starting")
|
print("MEMFS: starting")
|
||||||
|
@ -15,25 +57,23 @@ print("MEMFS: starting")
|
||||||
# The BUFR codetables is not used in the engine
|
# The BUFR codetables is not used in the engine
|
||||||
EXCLUDED = ["grib3", "codetables", "taf", "stations"]
|
EXCLUDED = ["grib3", "codetables", "taf", "stations"]
|
||||||
|
|
||||||
pos = 1
|
EXCLUDE = {
|
||||||
if sys.argv[1] == "-exclude":
|
None: [],
|
||||||
product = sys.argv[2]
|
"bufr": ["bufr"],
|
||||||
if product == "bufr":
|
"grib": ["grib1", "grib2"],
|
||||||
EXCLUDED.append(product)
|
}
|
||||||
elif product == "grib":
|
|
||||||
EXCLUDED.extend(["grib1", "grib2"])
|
|
||||||
else:
|
|
||||||
assert False, "Invalid product %s" % product
|
|
||||||
pos = 3
|
|
||||||
|
|
||||||
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("Directories: ", dirs)
|
||||||
print("Excluding: ", EXCLUDED)
|
print("Excluding: ", EXCLUDED)
|
||||||
|
|
||||||
FILES = {}
|
FILES = {}
|
||||||
SIZES = {}
|
SIZES = {}
|
||||||
NAMES = []
|
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
|
# Binary to ASCII function. Different in Python 2 and 3
|
||||||
try:
|
try:
|
||||||
|
@ -48,11 +88,11 @@ def get_outfile_name(base, count):
|
||||||
|
|
||||||
|
|
||||||
# The last argument is the base name of the generated C file(s)
|
# 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
|
buffer = None
|
||||||
fcount = 0
|
fcount = 0
|
||||||
MAX_FCOUNT = 10
|
MAX_FCOUNT = args.count
|
||||||
|
|
||||||
for directory in dirs:
|
for directory in dirs:
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
list( APPEND memfs_args
|
||||||
|
--count 10
|
||||||
|
--output ${CMAKE_CURRENT_BINARY_DIR}/memfs_gen
|
||||||
|
)
|
||||||
|
|
||||||
set( generated_c_files
|
set( generated_c_files
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/memfs_gen_000.c
|
${CMAKE_CURRENT_BINARY_DIR}/memfs_gen_000.c
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/memfs_gen_001.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_009.c
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/memfs_gen_final.c)
|
${CMAKE_CURRENT_BINARY_DIR}/memfs_gen_final.c)
|
||||||
|
|
||||||
set( exclude "" )
|
|
||||||
if( NOT HAVE_PRODUCT_BUFR )
|
if( NOT HAVE_PRODUCT_BUFR )
|
||||||
set( exclude -exclude bufr )
|
list( APPEND memfs_args --exclude bufr)
|
||||||
elseif( NOT HAVE_PRODUCT_GRIB )
|
endif()
|
||||||
set( exclude -exclude grib )
|
|
||||||
|
if( NOT HAVE_PRODUCT_GRIB )
|
||||||
|
list( APPEND memfs_args --exclude grib)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${generated_c_files}
|
OUTPUT ${generated_c_files}
|
||||||
COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/memfs.py
|
COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/memfs.py
|
||||||
${exclude}
|
${memfs_args}
|
||||||
${PROJECT_SOURCE_DIR}/definitions
|
${PROJECT_SOURCE_DIR}/definitions
|
||||||
${PROJECT_SOURCE_DIR}/samples
|
${PROJECT_SOURCE_DIR}/samples
|
||||||
${PROJECT_SOURCE_DIR}/ifs_samples
|
${PROJECT_SOURCE_DIR}/ifs_samples
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/memfs_gen
|
|
||||||
DEPENDS ${PROJECT_SOURCE_DIR}/memfs.py)
|
DEPENDS ${PROJECT_SOURCE_DIR}/memfs.py)
|
||||||
|
|
||||||
set_source_files_properties(
|
set_source_files_properties(
|
||||||
|
|
Loading…
Reference in New Issue