Example #1
0
def _isfile(project_path, project_id=None, object_client=None):
    """Determine if a path in a project's datasets is a file.

    Parameters
    ----------
    project_path : str
        The path in the project directory to test.
    project_id : str, optional
        The project to list files from. You need to have access to this project
        for it to work. Defaults to the project set by FACULTY_PROJECT_ID in
        your environment.
    object_client : faculty.clients.object.ObjectClient, optional
        Advanced - can be used to benefit from caching in chain interactions
        with datasets.

    Returns
    -------
    bool
    """
    if _isdir(project_path, project_id):
        return False
    matches = ls(
        project_path,
        project_id=project_id,
        show_hidden=True,
        object_client=object_client,
    )
    rationalised_path = util.rationalise_path(project_path)
    return any(match == rationalised_path for match in matches)
Example #2
0
def rmdir(project_path, project_id=None, object_client=None):
    """Remove an empty directory from the project datasets.

    Parameters
    ----------
    remote_path : str
        The path of the directory to remove.
    project_id : str, optional
        The project to get files from. You need to have access to this project
        for it to work. Defaults to the project set by FACULTY_PROJECT_ID in
        your environment.
    object_client : faculty.clients.object.ObjectClient, optional
        Advanced - can be used to benefit from caching in chain interactions
        with datasets.
    """

    contents = ls(
        prefix=project_path,
        project_id=project_id,
        show_hidden=True,
        object_client=object_client,
    )

    rationalised_path = util.rationalise_path(project_path)
    project_path_as_file = rationalised_path.rstrip("/")
    project_path_as_dir = project_path_as_file + "/"

    if contents == [project_path_as_dir]:
        rm(
            project_path_as_dir,
            project_id=project_id,
            object_client=object_client,
            recursive=True,
        )
    elif contents == [project_path_as_file]:
        raise DatasetsError("'{}' Not a directory".format(project_path))
    elif project_path_as_dir not in contents:
        raise DatasetsError(
            "'{}' No such file or directory".format(project_path)
        )
    else:
        raise DatasetsError("'{}' Directory is not empty".format(project_path))
Example #3
0
def test_rationalise_path(input_path, rationalised_path):
    assert util.rationalise_path(input_path) == rationalised_path