Musicreater/nmcsup/vers.py

87 lines
2.8 KiB
Python
Raw Normal View History

2021-11-21 00:59:15 +08:00
"""音创系列版本号和版本操作函数"""
2022-01-19 17:48:47 +08:00
# 统计致命三级错误0个警告二级错误0个语法一级错误24个
2021-11-21 00:59:15 +08:00
2021-11-21 11:38:01 +08:00
from msctspt.bugReporter import version
2022-01-19 17:48:47 +08:00
import os
2021-11-21 00:59:15 +08:00
2022-01-19 17:48:47 +08:00
# 以下下两个值请在 msctspt/bugReporter 的version类中修改
2021-11-21 11:38:01 +08:00
VER = version.version
2022-01-19 17:48:47 +08:00
"""当前版本"""
2021-11-21 00:59:15 +08:00
2021-11-21 11:38:01 +08:00
LIBS = version.libraries
2022-01-19 17:48:47 +08:00
"""当前所需库"""
2021-11-21 00:59:15 +08:00
2022-01-19 17:48:47 +08:00
# 判断版本、临时文件与补全库
2021-11-21 00:59:15 +08:00
def compver(ver1, ver2):
"""
传入不带英文的版本号,特殊情况"10.12.2.6.5">"10.12.2.6"
:param ver1: 版本号1
:param ver2: 版本号2
:return: ver1< = >ver2返回-1/0/1
"""
list1 = str(ver1).split(".")
list2 = str(ver2).split(".")
# 循环次数为短的列表的len
for i in range(len(list1)) if len(list1) < len(list2) else range(len(list2)):
if int(list1[i]) == int(list2[i]):
pass
elif int(list1[i]) < int(list2[i]):
return -1
else:
return 1
# 循环结束,哪个列表长哪个版本号高
if len(list1) == len(list2):
return 0
elif len(list1) < len(list2):
return -1
else:
return 1
2022-01-19 17:48:47 +08:00
2021-11-21 00:59:15 +08:00
#
# ————————————————
# 版权声明上面的函数compver为CSDN博主「基友死得早」的原创文章中的函数遵循CC 4.0 BY-SA版权协议转载请附上原文出处链接及本声明。
# 原文链接https://blog.csdn.net/tinyjm/article/details/93514261
# ————————————————
#
2022-01-19 17:48:47 +08:00
def InstallLibs(now, LIBS1):
"""比对库信息并安装库"""
2021-11-21 11:38:01 +08:00
from os import system as run
2022-01-19 17:48:47 +08:00
for i in LIBS1:
if i not in now:
print("安装库:" + i)
run("python -m pip install " + i + " -i https://pypi.tuna.tsinghua.edu.cn/simple")
2021-11-21 00:59:15 +08:00
2022-01-19 17:48:47 +08:00
def chkver(ver=VER, libs=LIBS):
"""通过文件比对版本信息并安装库"""
if not os.path.exists(os.getenv('APPDATA') + '\\Musicreater\\msct.ActiveDatas.msct'):
2021-11-21 00:59:15 +08:00
print("新安装库")
2022-01-19 17:48:47 +08:00
os.makedirs(os.getenv('APPDATA') + '\\Musicreater\\')
with open(os.getenv('APPDATA') + '\\Musicreater\\msct.ActiveDatas.msct', 'w') as f:
f.write(ver[0] + '\n')
2021-11-21 00:59:15 +08:00
for i in libs:
2022-01-19 17:48:47 +08:00
f.write(i + '\n')
InstallLibs([], libs)
2021-11-21 00:59:15 +08:00
else:
2022-01-19 17:48:47 +08:00
with open(os.getenv('APPDATA') + '\\Musicreater\\msct.ActiveDatas.msct', 'r') as f:
2021-11-21 00:59:15 +08:00
v = f.readlines()
cp = compver(ver[0], v[0])
if cp != 0:
2022-01-19 17:48:47 +08:00
InstallLibs(v[1:], libs)
with open(os.getenv('APPDATA') + '\\Musicreater\\msct.ActiveDatas.msct', 'w') as f:
f.write(ver[0] + '\n')
2021-11-21 00:59:15 +08:00
for i in libs:
2022-01-19 17:48:47 +08:00
f.write(i + '\n')
2021-11-21 00:59:15 +08:00
del cp
def resetver():
2022-01-19 17:48:47 +08:00
"""重置版本信息"""
2021-11-21 00:59:15 +08:00
import shutil
2022-01-19 17:48:47 +08:00
shutil.rmtree(os.getenv('APPDATA') + '\\Musicreater\\')