in src/loading_manifest/osdu_wellborepath_manifest.py [0:0]
def create_wellborepath_manifest_from_path(
input_path, output_path,
preload_file_path, file_source,
schema_ns_name, schema_ns_value,
acl, legal, schema_version, dict_schemas):
# check supported schema version
if schema_version not in SUPPORTED_SCHEMA_VERSIONS:
logging.error("Schema version %s is not in the supported list: %s", schema_version,
SUPPORTED_SCHEMA_VERSIONS)
logging.info("Generated 0 trajectory load manifests.")
return
# list path filenames
files = os.listdir(input_path)
files_wellborepath = fnmatch.filter(files, "*.csv")
valid_files = []
logging.info("Checking {} files".format(len(files_wellborepath)))
for file_wellborepath in sorted(files_wellborepath):
file_wellborepath = file_wellborepath.strip()
# minimum check: file and size
if cm.is_nonzero_file(input_path, file_wellborepath):
valid_files.append(file_wellborepath)
processed_files = []
logging.info("Processing {} files".format(len(valid_files)))
for valid_file in valid_files:
full_valid_file_path = os.path.join(input_path, valid_file)
# retrieve wellbore id
# osdu
wellbore_id = valid_file[:-4]
# try:
# int(wellbore_id)
# except ValueError:
# logging.warning("Skip " + valid_file)
# continue
wellborepath_file = valid_file
output_file = os.path.join(output_path,
"load_path_" + schema_version + "_"
+ wellborepath_file.replace(".", "_") + ".json")
try:
# retrieve top/base mds from csv file
top_md, base_md = read_data_from_csv_file(full_valid_file_path)
with open(output_file, "w") as f:
json.dump(
obj=create_wellborepath_manifest(
wellborepath_name=wellborepath_file,
preload_file_path=preload_file_path,
file_source=file_source,
wellbore_id=wellbore_id,
top_md=top_md,
base_md=base_md,
schema_ns_name=schema_ns_name,
schema_ns_value=schema_ns_value,
acl=acl,
legal=legal,
schema_version=schema_version,
dict_schemas=dict_schemas
),
fp=f,
indent=4
)
processed_files.append(wellborepath_file)
except Exception:
logging.exception("Unable to process wellborepath file: {}".format(wellborepath_file))
os.remove(output_file)
logging.info("Generated {} trajectory load manifests.".format(len(processed_files)))