Skip to content

Commit

Permalink
remove try excepts
Browse files Browse the repository at this point in the history
  • Loading branch information
Anis SMAIL committed Jan 16, 2025
1 parent b0d243c commit 97dc0f2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 44 deletions.
22 changes: 14 additions & 8 deletions antarest/study/storage/explorer_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,21 @@ def list_dir(
children = list(directory_path.iterdir())
for child in children:
# if we can't acess one child we skip it
if is_non_study_folder(child, workspace.filter_in, workspace.filter_out):
# we don't want to expose the full absolute path on the server
child_rel_path = child.relative_to(workspace.path)
has_children = has_non_study_folder(child, workspace.filter_in, workspace.filter_out)
directories.append(
NonStudyFolderDTO(
path=child_rel_path, workspace=workspace_name, name=child.name, has_children=has_children
try:
if is_non_study_folder(child, workspace.filter_in, workspace.filter_out):
# we don't want to expose the full absolute path on the server
child_rel_path = child.relative_to(workspace.path)
has_children = has_non_study_folder(child, workspace.filter_in, workspace.filter_out)
directories.append(
NonStudyFolderDTO(
path=child_rel_path,
workspace=workspace_name,
name=child.name,
has_children=has_children,
)
)
)
except PermissionError as e:
logger.warning(f"Permission error while accessing {child} or one of its children: {e}")
except PermissionError as e:
logger.warning(f"Permission error while listing {directory_path}: {e}")
return directories
Expand Down
60 changes: 24 additions & 36 deletions antarest/study/storage/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,49 +478,37 @@ def is_ts_gen_tmp_dir(path: Path) -> bool:


def should_ignore_folder_for_scan(path: Path, filter_in: t.List[str], filter_out: t.List[str]) -> bool:
try:
if is_aw_no_scan(path):
logger.info(f"No scan directive file found. Will skip further scan of folder {path}")
return True

if is_temporary_upgrade_dir(path):
logger.info(f"Upgrade temporary folder found. Will skip further scan of folder {path}")
return True
if is_aw_no_scan(path):
logger.info(f"No scan directive file found. Will skip further scan of folder {path}")
return True

if is_ts_gen_tmp_dir(path):
logger.info(f"TS generation temporary folder found. Will skip further scan of folder {path}")
return True
if is_temporary_upgrade_dir(path):
logger.info(f"Upgrade temporary folder found. Will skip further scan of folder {path}")
return True

return not (
path.is_dir()
and any(re.search(regex, path.name) for regex in filter_in)
and not any(re.search(regex, path.name) for regex in filter_out)
)
except PermissionError as e:
logger.warning(f"Permission error while accessing {path}: {e}")
if is_ts_gen_tmp_dir(path):
logger.info(f"TS generation temporary folder found. Will skip further scan of folder {path}")
return True

return not (
path.is_dir()
and any(re.search(regex, path.name) for regex in filter_in)
and not any(re.search(regex, path.name) for regex in filter_out)
)


def has_non_study_folder(path: Path, filter_in: t.List[str], filter_out: t.List[str]) -> bool:
try:
for sub_path in path.iterdir():
if is_non_study_folder(sub_path, filter_in, filter_out):
return True
return False
except PermissionError as e:
logger.warning(f"Permission error while accessing {path}: {e}")
return False
for sub_path in path.iterdir():
if is_non_study_folder(sub_path, filter_in, filter_out):
return True
return False


def is_non_study_folder(path: Path, filter_in: t.List[str], filter_out: t.List[str]) -> bool:
try:
if not path.is_dir():
return False
if is_study_folder(path):
return False
if should_ignore_folder_for_scan(path, filter_in, filter_out):
return False
return True
except PermissionError as e:
logger.warning(f"Permission error while accessing {path}: {e}")
if not path.is_dir():
return False
if is_study_folder(path):
return False
if should_ignore_folder_for_scan(path, filter_in, filter_out):
return False
return True

0 comments on commit 97dc0f2

Please sign in to comment.