代码拉取完成,页面将自动刷新
#!/usr/bin/python3
# Copyright (c) 2023 DoubleByte.
# This is licensed under Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
#
# http://license.coscl.org.cn/MulanPSL2
#
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.
import lzma
import os
import sys
import tarfile
import urllib.request
from core.util.path import PREBUILD_PATH, BIN_PATH, CORE_PATH
sys.path.append(CORE_PATH)
from core.util.color import Color
from core.util.log_util import LogUtil
URL = "https://chengxuya.top/share/" + sys.platform
OPT_PATH = PREBUILD_PATH + "/opt"
def download_gn():
gn = BIN_PATH + "/gn"
if os.path.exists(gn):
return
gn_xz = BIN_PATH + "/gn.xz"
if not os.path.exists(gn_xz):
LogUtil.info("downloading gn")
file = URL + "/gn.xz"
response = urllib.request.urlopen(file)
with open(gn_xz, "wb") as xz:
xz.write(response.read())
with lzma.open(gn_xz, "rb") as xz, open(gn, "wb") as exe:
LogUtil.info("decompressing gn")
exe.write(xz.read())
os.chmod(gn, 0o777)
if os.path.exists(gn_xz):
os.remove(gn_xz)
def download_ninja():
ninja = BIN_PATH + "/ninja"
if os.path.exists(ninja):
return
ninja_xz = BIN_PATH + "/ninja.xz"
if not os.path.exists(ninja_xz):
LogUtil.info("downloading ninja")
file = URL + "/ninja.xz"
response = urllib.request.urlopen(file)
with open(ninja_xz, "wb") as xz:
xz.write(response.read())
with lzma.open(ninja_xz, "rb") as xz, open(ninja, "wb") as exe:
LogUtil.info("decompressing ninja")
exe.write(xz.read())
os.chmod(ninja, 0o777)
if os.path.exists(ninja_xz):
os.remove(ninja_xz)
def download_python():
python = BIN_PATH + "/python"
if os.path.exists(python):
return
file = URL + "/python.tar.xz"
python_tar_xz = OPT_PATH + "/python.tar.xz"
if not os.path.exists(python_tar_xz):
response = urllib.request.urlopen(file)
LogUtil.info("downloading python")
with open(python_tar_xz, "wb") as xz:
xz.write(response.read())
if not os.path.exists(OPT_PATH + "/python"):
with tarfile.open(python_tar_xz, "r") as tar:
LogUtil.info("decompressing python")
tar.extractall(OPT_PATH)
os.symlink(OPT_PATH + "/python/bin/python3", python)
def prebuild():
download_gn()
download_ninja()
download_python()
def main():
if not os.path.exists(PREBUILD_PATH):
os.makedirs(PREBUILD_PATH)
if not os.path.exists(OPT_PATH):
os.makedirs(OPT_PATH)
if not os.path.exists(BIN_PATH):
os.makedirs(BIN_PATH)
prebuild()
result: str = Color.info + "prebuild successful" + Color.end
LogUtil.info(result)
if __name__ == '__main__':
main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。