import json
import os
from typing import List
from .download_util import get_arch, get_specified_python
from .software_mgr import SoftwareMgr, SoftwareVersion
_PYTHON_MAPPING = {
"Python-3.7": "cp37",
"Python-3.8": "cp38",
"Python-3.9": "cp39",
"Python-3.10": "cp310",
"Python-3.11": "cp311",
"Python-3.12": "cp312"
}
CUR_DIR = os.path.dirname(os.path.realpath(__file__))
PROJECT_DIR = os.path.dirname(CUR_DIR)
class DownloadData:
def __init__(self, selected_os_list, selected_soft_list, dst=""):
self.software_mgr = SoftwareMgr()
self.selected_os_list = selected_os_list
self.selected_soft_list = selected_soft_list
self.selected_soft_ver_list = self._parse_software_list(self.software_mgr, selected_soft_list)
self.base_dir = dst if dst else PROJECT_DIR
self.resources_dir = os.path.join(self.base_dir, 'resources')
self.arch = get_arch(selected_os_list)
self.specified_python = get_specified_python()
self.py_implement_flag = self._get_py_implement_flag(self.specified_python)
@staticmethod
def _parse_software_list(software_mgr: SoftwareMgr, software_list: List[str]) -> List[SoftwareVersion]:
return [SoftwareVersion(*software_mgr.get_software_name_version(software)) for software in software_list]
@staticmethod
def _get_py_implement_flag(specified_python):
py_iter = (cp_ver for py_ver, cp_ver in _PYTHON_MAPPING.items() if py_ver in specified_python)
implement_flag = next(py_iter, "cp37")
return implement_flag