新增自动安装器

This commit is contained in:
EillesWan 2022-03-21 19:05:27 +08:00
parent e70fc806be
commit 245e2fa1ec
9 changed files with 252 additions and 60 deletions

4
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,4 @@
{
"esbonio.sphinx.confDir": "",
"python.formatting.provider": "autopep8"
}

Binary file not shown.

View File

@ -0,0 +1,198 @@
# -*- coding: utf-8 -*-
# W-YI 金羿
# QQ 2647547478
# 音·创 开发交流群 861684859
# Email EillesWan2006@163.com W-YI_DoctorYI@outlook.com EillesWan@outlook.com
# 版权所有 Team-Ryoun 金羿("Eilles Wan")
# 若需转载或借鉴 请附作者
"""
·创自动安装器 (Musicreater Auto Installer)
对音·创的自动安装提供支持的独立软件
Musicreater Auto Installer (·创自动安装器)
A software that used for installing Musicreater automatically
Copyright 2022 Team-Ryoun
Licensed under the Apache License, Version 2.0 (the 'License');
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an 'AS IS' BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
# 代码写的并非十分的漂亮还请大佬多多包涵本软件源代码依照Apache软件协议公开
# 下面为正文
from sys import platform
from platform import architecture
import urllib.request
import zipfile
from os import system as srun
from os import walk, rename, remove, path, chdir, listdir
from shutil import rmtree, move
if platform == "win32":
nowpath = __file__[:len(__file__) - __file__[len(__file__)::-1].index('\\')]
print('\033[0{}\033[0m'.format("正在下载python\nDownloading Python"))
try:
urllib.request.urlretrieve(
"https://www.python.org/ftp/python/3.8.10/python-3.8.10.exe"
if architecture()[0] == "32bit"
else "https://www.python.org/ftp/python/3.8.10/python-3.8.10-amd64.exe",
"./pythonInstaller.exe",
)
# urllib.request.urlretrieve("https://www.python.org/ftp/python/3.8.10/python-3.8.10.exe","./pythonInstaller.exe")
except Exception as E:
input(str(E) + "\n自动下载失败,按下回车取消")
exit()
print('\033[0{}\033[0m'.format('正在安装python\nInstalling Python'+f'\n{nowpath}python38\\'))
# open('install.bat','w').write(f'.\\pythonInstaller.exe /passive InstallAllUsers=0 TargetDir="{nowpath}python38" DefaultJustForMeTargetDir="{nowpath}python38" AssociateFiles=0 CompileAll=1 PrependPath=0 Shortcuts=0 Include_doc=0 Include_launcher=0 InstallLauncherAllUsers=0 Include_test=0 Include_tools=0')
srun(f'.\\pythonInstaller.exe /passive InstallAllUsers=0 TargetDir="{nowpath}python38" DefaultJustForMeTargetDir="{nowpath}python38" AssociateFiles=0 CompileAll=1 PrependPath=0 Shortcuts=0 Include_doc=0 Include_launcher=0 InstallLauncherAllUsers=0 Include_test=0 Include_tools=0')
# print('\033[0{}\033[0m'.format("正在下载pip安装工具\nDownloading get-pip tool"))
# try:
# urllib.request.urlretrieve(
# "https://bootstrap.pypa.io/get-pip.py", "./python38/get-pip.py"
# )
# except Exception as E:
# input(str(E) + "\n自动下载失败按下回车取消")
# exit()
# print('\033[0{}\033[0m'.format("正在下载pip\nDownloading pip"))
# chdir('./python38')
# srun(r'".\python.exe get-pip.py')
# print('\033[0{}\033[0m'.format('正在安装pip\nInstalling pip'))
# for dire in listdir('./Lib/site-packages/'):
# move('./Lib/site-packages/'+dire,'./'+dire)
# print('\033[0{}\033[0m'.format("完成!"))
# chdir('../')
try:
choseurl = int(input('\033[0{}\033[0m'.format("""请选择 音·创 下载源,默认为0
Please choose a download source of Musicreater(default 0)
[0] 私有服务器<暂无> | Private Server<Haven't been built>
[1] Gitee
[2] Github\n:""")))
except Exception as E:
print('\033[0{}\033[0m'.format(str(E) + "\n将使用默认源\nUsing default source"))
choseurl = 0
myurl = ""
Giteeurl = "https://gitee.com/EillesWan/Musicreater/repository/blazearchive/master.zip?Expires=1647771436&Signature=%2BkqLHwmvzScCd4cPQDP0LHLpqeZUxOrOv17QpRy%2FTzs%3D"
Githuburl = "https://codeload.github.com/EillesWan/Musicreater/zip/refs/heads/master"
url = (
myurl
if choseurl == 0
else Giteeurl
if choseurl == 1
else Githuburl
if choseurl == 2
else myurl
)
print('\033[0{}\033[0m'.format("正在下载音·创\nDownloading Musicreater"))
try:
urllib.request.urlretrieve(url, "./master.zip")
except Exception as E:
input('\033[0{}\033[0m'.format(str(E) + "\n自动下载失败,按下回车取消"))
exit()
print('\033[0{}\033[0m'.format("安装音·创\nInstalling Musicreater"))
zipfile.ZipFile("./master.zip", "r").extractall()
remove("./master.zip")
remove('./pythonInstaller.exe')
try:
rmtree("./Musicreater")
except:
pass
rename("./Musicreater-master/", "./Musicreater/")
elif platform == 'linux':
srun("sudo apt-get install python3")
srun("sudo apt-get install python3-pip")
srun("sudo apt-get install git")
try:
choseurl = int(input('\033[0{}\033[0m'.format("""请选择 音·创 下载源,默认为1
Please choose a download source of Musicreater(default 1)
[1] Gitee
[2] Github\n:""")))
except Exception as E:
print(str(E) + "\n将使用默认源\nUsing default source")
choseurl = 1
url = (
"https://gitee.com/EillesWan/Musicreater.git"
if choseurl == 1
else "https://github.com/EillesWan/Musicreater.git"
if choseurl == 2
else "https://gitee.com/EillesWan/Musicreater.git"
)
srun(f"sudo git clone {url}")
print('\033[0{}\033[0m'.format("编译音·创\nCompiling Musicreater"))
if platform == "linux":
srun("python3 -O -m compileall -b ./Musicreater/")
open('./Musicreater.sh','w',encoding='utf-8').write("cd ./Musicreater/\npython3 Musicreater.pyc")
elif platform == "win32":
chdir('./python38/')
srun("python.exe -O -m compileall -b ../Musicreater/")
chdir('../')
open('./Musicreater.bat','w').write('"./python38/python.exe" "./Musicreater/Musicreater.pyc"')
for parent, dirnames, filenames in walk("./Musicreater"):
for filename in filenames:
if filename[-3:] == ".py":
fn = path.join(parent, filename)
remove(fn)
print('\033[0{}\033[0m'.format(f"删除文件 {fn}"))
for dirname in dirnames:
if dirname == "__pycache__":
pn = path.join(parent, dirname)
rmtree(pn)
print('\033[0{}\033[0m'.format(f"删除目录 {pn}"))
print('\033[0{}\033[0m'.format("您可以开始使用音·创了\n我们将在后台为您安装各项支持库"))
if platform == "linux":
srun("python3 ./Musicreater/补全库.pyc")
elif platform == "win32":
chdir('./python38/')
srun(".\\python.exe ../Musicreater/补全库.pyc")
chdir('../')

View File

@ -3,6 +3,8 @@
[![Licence: Apache (shields.io)](https://img.shields.io/badge/Licence-Apache-blueviolet)](https://choosealicense.com/licenses/apache-2.0/)
[![Bilibili: 凌云金羿 (shields.io)]( https://img.shields.io/badge/Bilibili-%E5%87%8C%E4%BA%91%E9%87%91%E7%BE%BF-blueviolet)](https://space.bilibili.com/397369002/)
[![Bilibili: 诸葛亮与八卦阵 (shields.io)](https://img.shields.io/badge/Bilibili-%E8%AF%B8%E8%91%9B%E4%BA%AE%E4%B8%8E%E5%85%AB%E5%8D%A6%E9%98%B5-blueviolet)](https://space.bilibili.com/604072474)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
### 介绍
@ -22,7 +24,7 @@ bgArray “诸葛亮与八卦阵”修复bug改进代码美观度增加
支持 Windows7+ 以及各个支持 Python3.8 的 Linux
***各位开发人员注意!!!多语言支持请使用`READABLETEXT`常量输出文字!!!如需补充,请在简体中文的语言文件(zhCN.py)中补充!!!***
***各位开发人员注意!!!多语言支持请使用函数`_`加载文字!!!如需补充,请在简体中文的语言文件(zh-CN.lang)中补充!!!***
### 安装教程

View File

@ -20,10 +20,6 @@ WHITE = (242, 244, 246)
BLACK = (18, 17, 16)
backgroundColor = WHITE
frontgroundColor = BLACK
loadingColor = DEFAULTBLUE
@ -32,8 +28,7 @@ okColor = GREEN
tipsColor = PURPLE
# 注UI界面字体、代码字体
fontPattern = ('DengXian Light','Fira Code')
fontPattern = ('DengXian Light', 'Fira Code')
class disp:
@ -68,49 +63,47 @@ class disp:
self.root = root
self.setTitle(title,debug)
self.setGeometry(geometry,debug)
self.setIcon(*iconbitmap,debug=debug)
self.setTitle(title, debug)
self.setGeometry(geometry, debug)
self.setIcon(*iconbitmap, debug=debug)
self.setMenu(menuWidget)
self.initWidget(wordView,buttons,settingBox,notemap)
self.initWidget(wordView, buttons, settingBox, notemap)
def setTitle(self,title:str = '',debug : bool = False) -> None:
def setTitle(self, title: str = '', debug: bool = False) -> None:
'''设置窗口标题'''
self.root.title = title
if debug:
log(f"设置窗口标题{title}")
def setGeometry(self,geometry:str = '0x0',debug:bool = False) -> None:
def setGeometry(self, geometry: str = '0x0', debug: bool = False) -> None:
'''设置窗口大小'''
self.root.geometry(geometry)
if debug:
log(f"设置窗口大小{geometry}")
def setIcon(self,bitmap:str = './musicreater.ico',default:str = '',debug:bool = False) -> None:
def setIcon(self, bitmap: str = './musicreater.ico', default: str = '', debug: bool = False) -> None:
'''设置窗口图标
注意default参数仅在Windows下有效其意为将所有没有图标的窗口设置默认图标
如果在非Windows环境使用default参数一个Error将被升起'''
if not debug:
try:
if default:
self.root.iconbitmap(bitmap,default)
self.root.iconbitmap(bitmap, default)
log(f'设置图标为{bitmap},默认为{default}')
else:
self.root.iconbitmap(bitmap)
log(f'设置图标为{bitmap}')
return True
except Exception as e:
log(str(e),'ERROR')
log(str(e), 'ERROR')
return False
else:
self.root.iconbitmap(bitmap,default)
return
def setMenu(self,menuWidgets: dict = {}) -> None:
self.root.iconbitmap(bitmap, default)
return
def setMenu(self, menuWidgets: dict = {}) -> None:
'''设置根菜单'''
if not menuWidgets:
# 如果传入空参数则返回当前菜单
@ -118,19 +111,19 @@ class disp:
# 如果不是空参数则新建菜单
self.RootMenu = {}
self.mainMenuBar = tk.Menu(self.root)
for menuName,menuCmd in menuWidgets.items():
for menuName, menuCmd in menuWidgets.items():
# 取得一个菜单名和一堆菜单函数及其显示名称
menu = tk.Menu(self.mainMenuBar,tearoff=0)
for cmdName,cmdFunc in menuCmd.items():
menu = tk.Menu(self.mainMenuBar, tearoff=0)
for cmdName, cmdFunc in menuCmd.items():
if cmdName:
menu.add_command(label = cmdName, command = cmdFunc)
menu.add_command(label=cmdName, command=cmdFunc)
else:
menu.add_separator()
self.mainMenuBar.add_cascade(label=menuName,menu=menu)
self.mainMenuBar.add_cascade(label=menuName, menu=menu)
self.RootMenu[menuName] = menu
self.root.config(menu=self.mainMenuBar)
def addMenu(self,menuRoot:str = '',menuLabel:str = '',menuCommand:function = None):
def addMenu(self, menuRoot: str = '', menuLabel: str = '', menuCommand: function = None):
'''增加一个菜单项
:param menuRoot : str
菜单的根菜单即所属的菜单上的文字
@ -142,21 +135,21 @@ class disp:
# 如果已经有父菜单
if menuLabel:
# 增加菜单指令
self.RootMenu[menuRoot].add_command(label = menuLabel, command = menuCommand)
self.RootMenu[menuRoot].add_command(
label=menuLabel, command=menuCommand)
else:
# 增加分隔栏
self.RootMenu[menuRoot].add_separator()
else:
# 没有父菜单则新增一个父菜单
menu = tk.Menu(self.mainMenuBar,tearoff=False)
menu = tk.Menu(self.mainMenuBar, tearoff=False)
if menuLabel:
menu.add_command(label = menuLabel, command = menuCommand)
menu.add_command(label=menuLabel, command=menuCommand)
else:
menu.add_separator()
self.mainMenuBar.add_cascade(label=menuRoot,menu=menu)
self.mainMenuBar.add_cascade(label=menuRoot, menu=menu)
self.RootMenu[menuRoot] = menu
def initWidget(self, wordView: str = '音·创 Musicreater', buttons: list = [],
settingBox: list = [], notemap: list = []) -> None:
'''设置窗口小部件,分为:
@ -167,25 +160,25 @@ class disp:
:各个音轨的显示框 TrackFrame
:信息显示版 InfoBar
'''
self._wordviewBar = tk.Label(self.root,bg=frontgroundColor,fg=backgroundColor,text = wordView)
self._wordviewBar = tk.Label(
self.root, bg=frontgroundColor, fg=backgroundColor, text=wordView)
self.setWordView(wordView)
def setWordView(self, text:str) -> None:
def setWordView(self, text: str) -> None:
self._wordviewBar['text'] = text
def authorMenu(authors:tuple = (('金羿','EillesWan@outlook.com'),('诸葛亮与八卦阵','474037765'))):
def authorMenu(authors: tuple = (('金羿', 'EillesWan@outlook.com'), ('诸葛亮与八卦阵', '474037765'))):
'''自定义作者界面'''
from languages.lang import
from languages.lang import _
aabw = tk.Tk()
aabw.title(READABLETEXT[9])
aabw.title(_('关于'))
aabw.geometry('550x600') # 像素
tk.Label(aabw, text='', font=('', 15)).pack()
tk.Label(aabw, text=READABLETEXT[10], font=('', 35)).pack()
tk.Label(aabw, text=READABLETEXT[11].format(VER[1] + VER[0]), font=('', 15)).pack()
tk.Label(aabw, text=READABLETEXT[11].format(
VER[1] + VER[0]), font=('', 15)).pack()
# pack 的side可以赋值为LEFT RTGHT TOP BOTTOM
# grid 的row 是列数、column是行排注意这是针对空间控件本身大小来的即是指向当前控件的第几个。
# place的 x、y是(x,y)坐标
@ -196,12 +189,14 @@ def authorMenu(authors:tuple = (('金羿','EillesWan@outlook.com'),('诸葛亮
tk.Label(aabw, text=READABLETEXT[12], font=('', 20)).pack()
tk.Label(aabw, text='', font=('', 15)).pack()
for i in READABLETEXT[15]:
tk.Label(aabw, text=i[0], font=('', 17 if i[1] else 15, 'bold' if i[1] else '')).pack()
tk.Label(aabw, text=i[0], font=('', 17 if i[1]
else 15, 'bold' if i[1] else '')).pack()
tk.Label(aabw, text='', font=('', 5)).pack()
if DEFAULTLANGUAGE != 'zh-CN':
tk.Label(aabw, text=READABLETEXT[16], font=('', 15)).pack()
for i in READABLETEXT['Translator']:
tk.Label(aabw, text=i[0], font=('', 17 if i[1] else 15, 'bold' if i[1] else '')).pack()
tk.Label(aabw, text=i[0], font=(
'', 17 if i[1] else 15, 'bold' if i[1] else '')).pack()
def exitAboutWindow():
aabw.destroy()
@ -211,17 +206,10 @@ def authorMenu(authors:tuple = (('金羿','EillesWan@outlook.com'),('诸葛亮
aabw.mainloop()
class ProgressBar:
def __init__(self,root:tk.Tk = tk.Tk(),style:tuple = (DEFAULTBLUE,BLACK,WHITE),
type : bool = False, info : str = '', debug:bool = False) -> None:
def __init__(self, root: tk.Tk = tk.Tk(), style: tuple = (DEFAULTBLUE, BLACK, WHITE),
type: bool = False, info: str = '', debug: bool = False) -> None:
'''建立一个进度条或者加载等待界面
:param root : tk.Tk
建立进度条的根窗口
@ -233,4 +221,4 @@ class ProgressBar:
显示的附加信息
:param debug : bool
是否输出日志到控制台'''
self.root = root
self.root = root

View File

@ -4,10 +4,10 @@
# 诸葛亮与八卦阵帮忙修改语法 日期:---2022年1月19日
# 统计致命三级错误0个警告二级错误1个语法一级错误72个
import os
import zipfile
def makeZip(sourceDir, outFilename, compression=8, exceptFile=None):
import zipfile
"""使用compression指定的算法打包目录为zip文件\n
默认算法为DEFLATED(8),可用算法如下\n
STORED = 0\n
@ -93,9 +93,9 @@ class report:
class version:
libraries = (
'mido', 'amulet', 'amulet-core', 'amulet-nbt', 'piano_transcription_inference', 'pypinyin',
'pyinstaller','py7zr','websockets', 'torch','requests'
'pyinstaller', 'py7zr','websockets', 'torch', 'requests'
)
"""当前所需库,有一些是开发用的,用户不需要安装"""
"""当前所需库"""
version = ('0.2.0', 'Delta',)
"""当前版本"""
@ -103,7 +103,7 @@ class version:
def __init__(self) -> None:
self.libraries = version.libraries
"""当前所需库,有一些是开发用的,用户不需要安装"""
"""当前所需库"""
self.version = version.version
"""当前版本"""