Update to DIMA package path resolution from file.

This commit is contained in:
2024-11-24 19:45:18 +01:00
parent 1b2b319295
commit 5c61e2391a

View File

@ -1,7 +1,18 @@
import sys
import os
root_dir = os.path.abspath(os.curdir)
sys.path.append(root_dir)
try:
thisFilePath = os.path.abspath(__file__)
except NameError:
print("Error: __file__ is not available. Ensure the script is being run from a file.")
print("[Notice] Path to DIMA package may not be resolved properly.")
thisFilePath = os.getcwd() # Use current directory or specify a default
dimaPath = os.path.normpath(os.path.join(thisFilePath, "..",'..')) # Move up to project root
if dimaPath not in sys.path: # Avoid duplicate entries
sys.path.append(dimaPath)
import h5py
import pandas as pd
@ -12,7 +23,6 @@ import src.hdf5_writer as hdf5_lib
import logging
import datetime
import os
import h5py
import yaml
@ -640,17 +650,20 @@ def read_mtable_as_dataframe(filename):
return output_dataframe
if __name__ == "__main__":
if len(sys.argv) < 4:
print("Usage: python hdf5_ops.py serialize <path/to/target_file.hdf5> <format=json|yaml>")
if len(sys.argv) < 5:
print("Usage: python hdf5_ops.py serialize <path/to/target_file.hdf5> <folder_depth : int = 2> <format=json|yaml>")
sys.exit(1)
if sys.argv[1] == 'serialize':
input_hdf5_file = sys.argv[2]
file_format = sys.argv[3]
folder_depth = int(sys.argv[3])
file_format = sys.argv[4]
try:
# Call the serialize_metadata function and capture the output path
path_to_file = serialize_metadata(input_hdf5_file, output_format=file_format)
path_to_file = serialize_metadata(input_hdf5_file,
folder_depth = folder_depth,
output_format=file_format)
print(f"Metadata serialized to {path_to_file}")
except Exception as e:
print(f"An error occurred during serialization: {e}")