Included additional directory path validation based on dir keywords
This commit is contained in:
@ -232,6 +232,21 @@ import shutil
|
|||||||
# select_dir_keywords = [],
|
# select_dir_keywords = [],
|
||||||
# select_file_keywords =[],
|
# select_file_keywords =[],
|
||||||
# top_sub_dir_mask : bool = True):
|
# 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,
|
def create_hdf5_file_from_filesystem_path(output_filename : str,
|
||||||
input_file_system_path : str,
|
input_file_system_path : str,
|
||||||
select_dir_keywords = [],
|
select_dir_keywords = [],
|
||||||
@ -320,7 +335,7 @@ def create_hdf5_file_from_filesystem_path(output_filename : str,
|
|||||||
# continue
|
# continue
|
||||||
|
|
||||||
# Add files with name, that contains any of the file_keywords
|
# Add files with name, that contains any of the file_keywords
|
||||||
if any([keyword in filename for keyword in select_file_keywords]):
|
if any([keyword in filename for keyword in select_file_keywords]):
|
||||||
file_paths_dict[dirpath].append(filename)
|
file_paths_dict[dirpath].append(filename)
|
||||||
else:
|
else:
|
||||||
file_paths_dict[dirpath] = admissible_filenames
|
file_paths_dict[dirpath] = admissible_filenames
|
||||||
@ -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]):
|
#if (dirpath.count(os.sep) > offset) and not any([item in dirpath for item in select_dir_keywords]):
|
||||||
#tail, dirname = os.path.split(dirpath)
|
#tail, dirname = os.path.split(dirpath)
|
||||||
#if not any([item in dirname for item in select_dir_keywords]):
|
#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
|
continue
|
||||||
|
|
||||||
group_name = dirpath.replace(os.sep,'/')
|
group_name = dirpath.replace(os.sep,'/')
|
||||||
group_name = group_name.replace(root_dir.replace(os.sep,'/') + '/', '/')
|
group_name = group_name.replace(root_dir.replace(os.sep,'/') + '/', '/')
|
||||||
|
|
||||||
# flatten group name to one level
|
# 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('/')
|
tmp_list = group_name.split('/')
|
||||||
if len(tmp_list)>2:
|
if len(tmp_list) > offset+1:
|
||||||
group_name = '/'.join([tmp_list[0],tmp_list[1]])
|
group_name = '/'.join([tmp_list[i] for i in range(offset+1)])
|
||||||
|
|
||||||
# Group hierarchy is implicitly defined by the forward slashes
|
# Group hierarchy is implicitly defined by the forward slashes
|
||||||
if not group_name in h5file.keys():
|
if not group_name in h5file.keys():
|
||||||
|
Reference in New Issue
Block a user