diff --git a/aiida/backends/general/migrations/utils.py b/aiida/backends/general/migrations/utils.py index 0c310a6b5f..0bcfe75329 100644 --- a/aiida/backends/general/migrations/utils.py +++ b/aiida/backends/general/migrations/utils.py @@ -69,11 +69,11 @@ def get_node_repository_sub_folder(uuid): :param uuid: UUID of the node :return: absolute path to node repository folder, i.e `/some/path/repository/node/12/ab/c123134-a123/path` """ - from aiida.common.utils import get_repository_folder + from aiida.manage.configuration import get_profile uuid = str(uuid) - repo_dirpath = get_repository_folder('repository') + repo_dirpath = os.path.join(get_profile().repository_path, 'repository') node_dirpath = os.path.join(repo_dirpath, 'node', uuid[:2], uuid[2:4], uuid[4:], 'path') return node_dirpath diff --git a/aiida/cmdline/commands/cmd_status.py b/aiida/cmdline/commands/cmd_status.py index d3d33ac865..312e8d2b9b 100644 --- a/aiida/cmdline/commands/cmd_status.py +++ b/aiida/cmdline/commands/cmd_status.py @@ -8,10 +8,9 @@ # For further information please visit http://www.aiida.net # ########################################################################### """`verdi status` command.""" - import sys -from enum import IntEnum +import enum import click from aiida.cmdline.commands.cmd_verdi import verdi @@ -19,7 +18,7 @@ from ..utils.echo import ExitCode -class ServiceStatus(IntEnum): +class ServiceStatus(enum.IntEnum): """Describe status of services for 'verdi status' command.""" UP = 0 # pylint: disable=invalid-name ERROR = 1 @@ -47,7 +46,7 @@ def verdi_status(): """Print status of AiiDA services.""" # pylint: disable=broad-except,too-many-statements from aiida.cmdline.utils.daemon import get_daemon_status, delete_stale_pid_file - from aiida.common.utils import Capturing, get_repository_folder + from aiida.common.utils import Capturing from aiida.manage.external.rmq import get_rmq_url from aiida.manage.manager import get_manager @@ -67,7 +66,7 @@ def verdi_status(): # getting the repository repo_folder = 'undefined' try: - repo_folder = get_repository_folder() + repo_folder = profile.repository_path except Exception as exc: print_status(ServiceStatus.ERROR, 'repository', 'Error with repo folder', exception=exc) exit_code = ExitCode.CRITICAL diff --git a/aiida/common/folders.py b/aiida/common/folders.py index 0eae11c5d3..a9ff0e8c6c 100644 --- a/aiida/common/folders.py +++ b/aiida/common/folders.py @@ -8,7 +8,6 @@ # For further information please visit http://www.aiida.net # ########################################################################### """Utility functions to operate on filesystem folders.""" - import errno import fnmatch import io @@ -16,8 +15,8 @@ import shutil import tempfile +from aiida.manage.configuration import get_profile from . import timezone -from .utils import get_repository_folder # If True, tries to make everything (dirs, files) group-writable. # Otherwise, tries to make everything only readable and writable by the user. @@ -430,7 +429,7 @@ def __init__(self, sandbox_in_repo=True): """ # First check if the sandbox folder already exists if sandbox_in_repo: - sandbox = get_repository_folder('sandbox') + sandbox = os.path.join(get_profile().repository_path, 'sandbox') if not os.path.exists(sandbox): os.makedirs(sandbox) abspath = tempfile.mkdtemp(dir=sandbox) @@ -533,7 +532,7 @@ def __init__(self, section, uuid, subfolder=os.curdir): # normpath, that may be slow): this is done abywat by the super # class. entity_dir = os.path.join( - get_repository_folder('repository'), str(section), + get_profile().repository_path, 'repository', str(section), str(uuid)[:2], str(uuid)[2:4], str(uuid)[4:] diff --git a/aiida/common/utils.py b/aiida/common/utils.py index 0500ec08d6..ef9092a4fa 100644 --- a/aiida/common/utils.py +++ b/aiida/common/utils.py @@ -28,34 +28,6 @@ def get_new_uuid(): return str(uuid.uuid4()) -# To speed up the process (os.path.abspath calls are slow) -_repository_folder_cache = {} # pylint: disable=invalid-name - - -def get_repository_folder(subfolder=None): - """ - Return the top folder of the local repository. - """ - try: - return _repository_folder_cache[subfolder] - except KeyError: - from aiida.manage.configuration import get_profile - repository_path = get_profile().repository_path - - if not os.path.isdir(repository_path): - raise ImportError - if subfolder is None: - retval = os.path.abspath(repository_path) - elif subfolder == 'sandbox': - retval = os.path.abspath(os.path.join(repository_path, 'sandbox')) - elif subfolder == 'repository': - retval = os.path.abspath(os.path.join(repository_path, 'repository')) - else: - raise ValueError("Invalid 'subfolder' passed to get_repository_folder: {}".format(subfolder)) - _repository_folder_cache[subfolder] = retval - return retval - - def validate_list_of_string_tuples(val, tuple_length): """ Check that: