Exemplo n.º 1
0
 def get_storage_alias_list(self):
     """
     :return: list of available storages
     :raises NoResponseFromSearchException: if Search is not reachable
     """
     storage_aliases = [s.alias for s in Storage.get_storages()]
     return dict(storages=storage_aliases)
Exemplo n.º 2
0
def get_directory_list(usernames: [str], storage_alias: str = None):
    """Searches given Storage for all Data created by users with given usernames and returns a dictionary where keys are storage aliases and values are lists with relative adresses of directories.

    :param storage_alias: the unique string Alias of the Storage to be searched (default = None).
    :param usernames: a List of usernames.

    :raises StorageAliasNotFoundException: if storage_alias is not found.
    :raises StorageNotMountedException: if a Storage to be worked on is not currently mounted.
    """
    storage_list = []
    #  We search all the Storages
    if storage_alias is None:
        storage_list = Storage.get_storages()
    #  We search only the specified Storage
    else:
        storage_list.append(Storage.get_storage_by_name(storage_alias))

    #  search for directories in selected storages
    directories = dict()
    for storage in storage_list:
        #  assure the storage is accessible
        if not (check_storage_mount(storage)):
            raise(StorageNotMountedException("The Storage with the alias >>" + storage.alias +
                                             "<< is currently not mounted under " + storage.mountpoint))
        abs_paths = search_for_directories(storage, usernames)
        rel_paths = []
        for abs_path in abs_paths:
            rel_paths.append(resolve_abs_address(abs_path)[1])
       # Eliminate storages without directories to show only if storage_alias is None
       #if storage_alias is None and len(abs_paths) == 0:
        #    pass
        #else:
        directories[storage.alias] = rel_paths
    return directories
Exemplo n.º 3
0
def resolve_abs_address(source_path: str):
    """Searches a Storage with same mountpoint as source_paths beginning and returns a List
    [storage_alias, source_rel_path].
    If there is a conflict (storage1.mountpoint being substring of storage2.mountpoint) the storage with longest
    mountpoint will be selected.

    :param source_path: The path to be split into storage_alias and relative_path.

    :raises SourcePathNotValidException: if no matching Storage is found.
    """
    if not os.path.exists(source_path):
        raise(SourcePathNotValidException("The path " + source_path +
                                          " does not exist on the system."))
    match_list = []
    for storage in Storage.get_storages():
        #  test if both start with same path
        if source_path.startswith(storage.mountpoint):
            match_list.append(storage)
    if len(match_list) == 0:
        #  executed only if we found no matching storage
        raise(SourcePathNotValidException("The path " + source_path +
                                          " does not match any registered Storages mountpath."))
    else:
        #  select storage with longest mountpoint
        maxlen = 0
        match_storage = None
        for storage in match_list:
            if len(storage.mountpoint) > maxlen:
                maxlen = len(storage.mountpoint)
                match_storage = storage
        # strip the mount point
        source_rel_path = source_path[len(match_storage.mountpoint):]
        return [match_storage.alias, source_rel_path]
Exemplo n.º 4
0
 def get_storages(self):
     return build_storages(Storage.get_storages())
Exemplo n.º 5
0
def initialize_storage_db():
    initialize_storages_from_config()
    check_storages_mount(Storage.get_storages())