Browse Source

[MNT] add get_learnware_dir_path_by_ids in organizer

tags/v0.3.2
Gene 2 years ago
parent
commit
64891ecd23
2 changed files with 53 additions and 0 deletions
  1. +21
    -0
      learnware/market/base.py
  2. +32
    -0
      learnware/market/easy2/organizer.py

+ 21
- 0
learnware/market/base.py View File

@@ -226,6 +226,9 @@ class LearnwareMarket:
def get_learnware_zip_path_by_ids(self, ids: Union[str, List[str]], **kwargs) -> Union[Learnware, List[Learnware]]:
return self.learnware_organizer.get_learnware_zip_path_by_ids(ids, **kwargs)

def get_learnware_dir_path_by_ids(self, ids: Union[str, List[str]], **kwargs) -> Union[Learnware, List[Learnware]]:
return self.learnware_organizer.get_learnware_dir_path_by_ids(ids, **kwargs)

def get_learnware_by_ids(self, id: Union[str, List[str]], **kwargs) -> Union[Learnware, List[Learnware]]:
return self.learnware_organizer.get_learnware_by_ids(id, **kwargs)

@@ -349,6 +352,24 @@ class BaseOrganizer:
"""
raise NotImplementedError("get_learnware_zip_path_by_ids is not implemented in BaseOrganizer")

def get_learnware_dir_path_by_ids(self, ids: Union[str, List[str]]) -> Union[Learnware, List[Learnware]]:
"""Get Learnware dir path by id

Parameters
----------
ids : Union[str, List[str]]
Give a id or a list of ids
str: id of targer learware
List[str]: A list of ids of target learnwares

Returns
-------
Union[Learnware, List[Learnware]]
Return the dir path for target learnware or list of path.
None for Learnware NOT Found.
"""
raise NotImplementedError("get_learnware_dir_path_by_ids is not implemented in BaseOrganizer")

def get_learnware_ids(self, top: int = None, check_status: int = None) -> List[str]:
"""get the list of learnware ids



+ 32
- 0
learnware/market/easy2/organizer.py View File

@@ -288,6 +288,38 @@ class EasyOrganizer(BaseOrganizer):
logger.warning("Learnware ID '%s' NOT Found!" % (ids))
return None

def get_learnware_dir_path_by_ids(self, ids: Union[str, List[str]]) -> Union[Learnware, List[Learnware]]:
"""Get Learnware dir path by id

Parameters
----------
ids : Union[str, List[str]]
Give a id or a list of ids
str: id of targer learware
List[str]: A list of ids of target learnwares

Returns
-------
Union[Learnware, List[Learnware]]
Return the dir path for target learnware or list of path.
None for Learnware NOT Found.
"""
if isinstance(ids, list):
ret = []
for id in ids:
if id in self.learnware_folder_list:
ret.append(self.learnware_folder_list[id])
else:
logger.warning("Learnware ID '%s' NOT Found!" % (id))
ret.append(None)
return ret
else:
try:
return self.learnware_folder_list[ids]
except:
logger.warning("Learnware ID '%s' NOT Found!" % (ids))
return None

def get_learnware_ids(self, top: int = None, check_status: int = None) -> List[str]:
"""Get learnware ids



Loading…
Cancel
Save