-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(watcher): add new endpoint for optimized scanning (#2193)
- Loading branch information
Showing
14 changed files
with
769 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Copyright (c) 2024, RTE (https://www.rte-france.com) | ||
# | ||
# See AUTHORS.txt | ||
# | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
# | ||
# SPDX-License-Identifier: MPL-2.0 | ||
# | ||
# This file is part of the Antares project. | ||
|
||
import logging | ||
from typing import List | ||
|
||
from antarest.core.config import Config | ||
from antarest.study.model import DEFAULT_WORKSPACE_NAME, NonStudyFolder, WorkspaceMetadata | ||
from antarest.study.storage.utils import ( | ||
get_folder_from_workspace, | ||
get_workspace_from_config, | ||
is_study_folder, | ||
should_ignore_folder_for_scan, | ||
) | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Explorer: | ||
def __init__(self, config: Config): | ||
self.config = config | ||
|
||
def list_dir( | ||
self, | ||
workspace_name: str, | ||
workspace_directory_path: str, | ||
) -> List[NonStudyFolder]: | ||
""" | ||
return a list of all directories under workspace_directory_path, that aren't studies. | ||
""" | ||
workspace = get_workspace_from_config(self.config, workspace_name, default_allowed=False) | ||
directory_path = get_folder_from_workspace(workspace, workspace_directory_path) | ||
directories = [] | ||
for child in directory_path.iterdir(): | ||
if child.is_dir() and not is_study_folder(child) and not should_ignore_folder_for_scan(child): | ||
# we don't want to expose the full absolute path on the server | ||
child_rel_path = child.relative_to(workspace.path) | ||
directories.append(NonStudyFolder(path=child_rel_path, workspace=workspace_name, name=child.name)) | ||
return directories | ||
|
||
def list_workspaces( | ||
self, | ||
) -> List[WorkspaceMetadata]: | ||
""" | ||
Return the list of all configured workspace name, except the default one. | ||
""" | ||
return [ | ||
WorkspaceMetadata(name=workspace_name) | ||
for workspace_name in self.config.storage.workspaces.keys() | ||
if workspace_name != DEFAULT_WORKSPACE_NAME | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.