[MNT] add read learnware info from storagetags/v0.3.2
| @@ -105,7 +105,13 @@ def filter_nonexist_conda_packages(packages: list) -> Tuple[List[str], List[str] | |||||
| command = f"conda env create --name env_test --file {test_yaml_file} --dry-run --json" | command = f"conda env create --name env_test --file {test_yaml_file} --dry-run --json" | ||||
| result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) | result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) | ||||
| output = json.loads(result.stdout.strip()).get("bad_deps", []) | |||||
| stdout = result.stdout.strip() | |||||
| last_bracket = stdout.rfind("\n{") | |||||
| if last_bracket != -1: | |||||
| stdout = stdout[last_bracket:] | |||||
| pass | |||||
| print(stdout) | |||||
| output = json.loads(stdout).get("bad_deps", []) | |||||
| if len(output) > 0: | if len(output) > 0: | ||||
| exist_packages = [] | exist_packages = [] | ||||
| @@ -167,6 +167,21 @@ class DatabaseOperations(object): | |||||
| pass | pass | ||||
| pass | pass | ||||
| def get_learnware_info(self, id: str): | |||||
| with self.engine.connect() as conn: | |||||
| r = conn.execute(text("SELECT semantic_spec, zip_path, folder_path, use_flag FROM tb_learnware WHERE id=:id;"), dict(id=id)) | |||||
| row = r.fetchone() | |||||
| if row is None: | |||||
| return None | |||||
| else: | |||||
| semantic_spec = json.loads(row[0]) | |||||
| zip_path = row[1] | |||||
| folder_path = row[2] | |||||
| use_flag = int(row[3]) | |||||
| return {'semantic_spec': semantic_spec, 'zip_path': zip_path, 'folder_path': folder_path, 'use_flag': use_flag} | |||||
| pass | |||||
| pass | |||||
| def load_market(self): | def load_market(self): | ||||
| with self.engine.connect() as conn: | with self.engine.connect() as conn: | ||||
| cursor = conn.execute(text("SELECT id, semantic_spec, zip_path, folder_path, use_flag FROM tb_learnware;")) | cursor = conn.execute(text("SELECT id, semantic_spec, zip_path, folder_path, use_flag FROM tb_learnware;")) | ||||
| @@ -3,7 +3,7 @@ import copy | |||||
| import zipfile | import zipfile | ||||
| import tempfile | import tempfile | ||||
| from shutil import copyfile, rmtree | from shutil import copyfile, rmtree | ||||
| from typing import Tuple, List, Union | |||||
| from typing import Tuple, List, Union, Dict | |||||
| from .database_ops import DatabaseOperations | from .database_ops import DatabaseOperations | ||||
| from ..base import BaseOrganizer, BaseChecker | from ..base import BaseOrganizer, BaseChecker | ||||
| @@ -392,5 +392,23 @@ class EasyOrganizer(BaseOrganizer): | |||||
| self.use_flags[learnware_id] = self.dbops.get_learnware_use_flag(learnware_id) | self.use_flags[learnware_id] = self.dbops.get_learnware_use_flag(learnware_id) | ||||
| pass | pass | ||||
| def get_learnware_info_from_storage(self, learnware_id: str) -> Dict: | |||||
| """return learnware zip path and semantic_specification from storage | |||||
| Parameters | |||||
| ---------- | |||||
| learnware_id : str | |||||
| learnware id | |||||
| Returns | |||||
| ------- | |||||
| Dict | |||||
| - semantic_spec: semantic_specification | |||||
| - zip_path: zip_path | |||||
| - folder_path: folder_path | |||||
| - use_flag: use_flag | |||||
| """ | |||||
| return self.dbops.get_learnware_info(learnware_id) | |||||
| def __len__(self): | def __len__(self): | ||||
| return len(self.learnware_list) | return len(self.learnware_list) | ||||