Included additional directory path validation based on dir keywords
This commit is contained in:
@ -232,6 +232,21 @@ import shutil
|
||||
# select_dir_keywords = [],
|
||||
# select_file_keywords =[],
|
||||
# top_sub_dir_mask : bool = True):
|
||||
|
||||
def is_valid_directory_path(dirpath,select_dir_keywords):
|
||||
|
||||
activated_keywords = []
|
||||
for item in select_dir_keywords:
|
||||
if len(item.split(os.sep))>1:
|
||||
is_sublist = all([x in dirpath.split(os.sep) for x in item.split(os.sep)])
|
||||
activated_keywords.append(is_sublist)
|
||||
else:
|
||||
activated_keywords.append(item in dirpath)
|
||||
|
||||
return any(activated_keywords)
|
||||
|
||||
|
||||
|
||||
def create_hdf5_file_from_filesystem_path(output_filename : str,
|
||||
input_file_system_path : str,
|
||||
select_dir_keywords = [],
|
||||
@ -352,16 +367,18 @@ def create_hdf5_file_from_filesystem_path(output_filename : str,
|
||||
#if (dirpath.count(os.sep) > offset) and not any([item in dirpath for item in select_dir_keywords]):
|
||||
#tail, dirname = os.path.split(dirpath)
|
||||
#if not any([item in dirname for item in select_dir_keywords]):
|
||||
if not any([item in dirpath for item in select_dir_keywords]):
|
||||
#if not any([item in dirpath for item in select_dir_keywords]):
|
||||
if not is_valid_directory_path(dirpath,select_dir_keywords):
|
||||
continue
|
||||
|
||||
group_name = dirpath.replace(os.sep,'/')
|
||||
group_name = group_name.replace(root_dir.replace(os.sep,'/') + '/', '/')
|
||||
|
||||
# flatten group name to one level
|
||||
offset = sum([len(i.split(os.sep)) if i in dirpath else 0 for i in select_dir_keywords])
|
||||
tmp_list = group_name.split('/')
|
||||
if len(tmp_list)>2:
|
||||
group_name = '/'.join([tmp_list[0],tmp_list[1]])
|
||||
if len(tmp_list) > offset+1:
|
||||
group_name = '/'.join([tmp_list[i] for i in range(offset+1)])
|
||||
|
||||
# Group hierarchy is implicitly defined by the forward slashes
|
||||
if not group_name in h5file.keys():
|
||||
|
Reference in New Issue
Block a user