MCPcopy Create free account
hub / github.com/aaPanel/BaoTa / PythonVersion

Class PythonVersion

class/projectModel/btpyvm.py:115–332  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

113
114
115class PythonVersion:
116
117 def __init__(self, v: str, is_pypy: bool = False, filename: str = None):
118 self.version = v
119 self.is_pypy = is_pypy
120 self.bt_python_path = "/www/server/pyporject_evn/versions"
121 self.bt_pypy_path = "/www/server/pyporject_evn/pypy_versions"
122 self._file_name = filename.strip() if isinstance(filename, str) else None
123
124 self._ver_t = None
125 if not os.path.exists(self.bt_python_path):
126 os.makedirs(self.bt_python_path)
127
128 if not os.path.exists(self.bt_pypy_path):
129 os.makedirs(self.bt_pypy_path)
130
131 @property
132 def ver_t(self) -> Tuple[int, int, int]:
133 if self._ver_t is not None:
134 return self._ver_t
135 self._ver_t = parse_version_to_list(self.version)
136 return self._ver_t
137
138 @property
139 def installed(self) -> bool:
140 if self.is_pypy:
141 return os.path.exists(self.bt_pypy_path + "/" + self.version)
142 return os.path.exists(self.bt_python_path + "/" + self.version)
143
144 @staticmethod
145 def check(file) -> bool:
146 print("[2/3] 验证源码文件......", file=_vm_std.out, flush=True)
147 if not os.path.exists(file):
148 print("文件不存在,无法验证", file=_vm_std.out, flush=True)
149 return False
150 if os.path.getsize(file) < 1024 * 1024 * 10:
151 print("文件内容缺失", file=_vm_std.out, flush=True)
152 os.remove(file)
153 return False
154 return True
155
156 @property
157 def file_name(self) -> str:
158 if self._file_name:
159 return self._file_name
160 if self.is_pypy and not self._file_name:
161 raise Exception("没有文件名称")
162 return "Python-{}.tar.xz".format(self.version)
163
164 @staticmethod
165 def _download_file(dst, url):
166 print(url, file=_vm_std.out, flush=True)
167 response = requests.get(url, stream=True, headers={
168 "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0"
169 })
170 total_size = int(response.headers.get('content-length', 0))
171 print("需要下载的源码文件大小: %.2fM" % (total_size / (1024 * 1024)), file=_vm_std.out, flush=True)
172 if total_size == 0:

Callers 4

get_py_versionMethod · 0.85
__parser_xmlMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected