deep-wine-runner/package-script/package.py

221 lines
8.8 KiB
Python
Raw Normal View History

2022-07-18 20:32:01 +08:00
#!/usr/bin/env python3
# 使用系统默认的 python3 运行
###########################################################################################
# 作者gfdgd xi、为什么您不喜欢熊出没和阿布呢
# 版本2.2.0
# 更新时间2022年09月11日
2022-07-18 20:32:01 +08:00
# 感谢:感谢 wine 以及 deepin-wine 团队,提供了 wine 和 deepin-wine 给大家使用,让我能做这个程序
# 基于 Python3 的 tkinter 构建
###########################################################################################
#################
# 引入所需的库
#################
import os
import sys
import json
import subprocess
import PyQt5.QtGui as QtGui
import PyQt5.QtCore as QtCore
import PyQt5.QtWidgets as QtWidgets
###################
# 程序所需事件
###################
# 读取文本文档
def readtxt(path):
f = open(path, "r") # 设置文件对象
str = f.read() # 获取内容
f.close() # 关闭文本对象
return str # 返回结果
# 获取用户主目录
def get_home():
return os.path.expanduser('~')
# 写入文本文档
def WriteTXT(path, things):
file = open(path, 'w', encoding='UTF-8') # 设置文件对象
file.write(things) # 写入文本
file.close() # 关闭文本对象
def DisbledOrEnabled(choose: bool):
chineseName.setDisabled(choose)
englishName.setDisabled(choose),
debDescription.setDisabled(choose)
typeName.setDisabled(choose)
exePath.setDisabled(choose)
packageName.setDisabled(choose)
versionName.setDisabled(choose)
2022-07-27 22:40:05 +08:00
buildDeb.setDisabled(choose)
2022-07-18 20:32:01 +08:00
class PackageDebThread(QtCore.QThread):
signal = QtCore.pyqtSignal(str)
2022-09-20 21:53:37 +08:00
info = QtCore.pyqtSignal(str)
2022-07-18 20:32:01 +08:00
def __init__(self) -> None:
super().__init__()
def run(self):
startupWMClassName = os.path.basename(exePath.text().replace("\\", "/"))
print(startupWMClassName)
WriteTXT(f"{programPath}/package-hshw.sh", f"""#!/bin/bash
#最终生成的包的描述
export app_description="{debDescription.text()}"
#应用程序英文名
export app_name="{englishName.text()}"
#应用程序中文名
export app_name_zh_cn="{chineseName.text()}"
#desktop文件中的分类
export desktop_file_categories="{typeName.currentText()};"
#desktop文件中StartupWMClass字段。用于让桌面组件将窗口类名与desktop文件相对应。这个值为实际运行的主程序EXE的文件名wine/crossover在程序运行后会将文件名设置为窗口类名
export desktop_file_main_exe="{startupWMClassName}"
export exec_path="{exePath.text()}"
#最终生成的包的包名,包名的命名规则以deepin开头加官网域名需要前后对调位置如还不能区分再加上应用名
export deb_package_name="{packageName.text()}"
#最终生成的包的版本号,版本号命名规则:应用版本号+deepin+数字
export deb_version_string="{versionName.text()}"
export package_depends="deepin-wine6-stable:amd64 (>= 6.0.0.12-1), spark-dwine-helper | store.spark-app.spark-dwine-helper"
2022-07-18 20:32:01 +08:00
export apprun_cmd="deepin-wine6-stable"
#export package_depends="deepin-wine5-stable:amd64 (>= 5.0.29-1), spark-dwine-helper | store.spark-app.spark-dwine-helper"
2022-07-18 20:32:01 +08:00
#export apprun_cmd="deepin-wine5-stable"
# rm -fr final.dir/
# rm -fr icons/
# rm -fr staging.dir/
./script-packager.sh $@
""")
os.chdir(programPath)
res = subprocess.Popen(["./package-hshw.sh"], shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
# 实时读取程序返回
while res.poll() is None:
try:
text = res.stdout.readline().decode("utf8")
except:
text = ""
self.signal.emit(text)
print(text, end="")
2022-09-20 21:53:37 +08:00
self.info.emit("打包完成!")
2022-07-18 20:32:01 +08:00
DisbledOrEnabled(False)
class QT:
run = None
2022-09-20 21:53:37 +08:00
def MessageBoxInformation(text):
QtWidgets.QMessageBox.information(window, "提示", text)
2022-07-18 20:32:01 +08:00
def PackageDeb():
DisbledOrEnabled(True)
for i in [chineseName.text(), englishName.text(), debDescription.text(), typeName.currentText(), exePath.text(), packageName.text(), versionName.text()]:
if i == "":
QtWidgets.QMessageBox.information(widget, "提示", "您未填完所有信息,无法继续")
DisbledOrEnabled(False)
return
commandReturn.setText("")
QT.run = PackageDebThread()
QT.run.signal.connect(RunCommand)
QT.info.signal.connect(MessageBoxInformation)
2022-07-18 20:32:01 +08:00
QT.run.start()
def RunCommand(command):
2022-08-11 21:54:20 +08:00
if command.replace("\n", "").replace(" ", "") != "":
commandReturn.append(command.replace("\n", ""))
2022-07-18 20:32:01 +08:00
def ShowHelp():
QtWidgets.QMessageBox.information(widget, "帮助", f"下面是有关打包器的各个输入框的意义以及有关的 UOS 填写标准\n{tips}")
def OpenPackageFolder():
os.system(f"xdg-open '{programPath}/package_save/uos'")
###########################
# 程序信息
###########################
programPath = os.path.split(os.path.realpath(__file__))[0] # 返回 string
information = json.loads(readtxt(f"{programPath}/information.json"))
version = information["Version"]
2022-07-27 22:40:05 +08:00
iconPath = "{}/deepin-wine-runner.svg".format(programPath)
2022-07-18 20:32:01 +08:00
tips = """第一个文本框是应用程序中文名
第二个文本框是应用程序英文名
第三个文本框是最终生成的包的描述
第四个选择框是desktop文件中的分类
第五个输入框是程序在 Wine 容器的位置 c:\\XXX 的形式盘符必须小写用反斜杠如果路径带用户名的话会自动替换为$USER
StartupWMClass 字段将会由程序自动生成作用如下
desktop文件中StartupWMClass字段用于让桌面组件将窗口类名与desktop文件相对应这个值为实际运行的主程序EXE的文件名wine/crossover在程序运行后会将文件名设置为窗口类名
第六个输入框是最终生成的包的包名,包名的命名规则以deepin开头加官网域名需要前后对调位置如还不能区分再加上应用名
最后一个是最终生成的包的版本号版本号命名规则应用版本号+deepin+数字
提示包名和容器名相同无法设置为不相同如果需要设置为不相同需要用另一个非基于生态适配脚本的打包器
2022-07-18 20:32:01 +08:00
"""
###########################
# 窗口创建
###########################
app = QtWidgets.QApplication(sys.argv)
window = QtWidgets.QMainWindow()
widget = QtWidgets.QWidget()
widgetLayout = QtWidgets.QGridLayout()
size = QtWidgets.QSizePolicy()
size.setHorizontalPolicy(0)
chineseName = QtWidgets.QLineEdit()
englishName = QtWidgets.QLineEdit()
debDescription = QtWidgets.QLineEdit()
typeName = QtWidgets.QComboBox()
exePath = QtWidgets.QLineEdit()
packageName = QtWidgets.QLineEdit()
versionName = QtWidgets.QLineEdit()
controlFrame = QtWidgets.QHBoxLayout()
buildDeb = QtWidgets.QPushButton("打包")
debPath = QtWidgets.QPushButton("deb 包生成目录")
buildDeb.setSizePolicy(size)
debPath.setSizePolicy(size)
commandReturn = QtWidgets.QTextBrowser()
typeName.addItems(["Network", "Chat", "Audio", "Video", "Graphics", "Office", "Translation", "Development", "Utility", "System"])
controlFrame.addWidget(buildDeb)
controlFrame.addWidget(debPath)
widgetLayout.addWidget(QtWidgets.QLabel("程序中文名:"), 0, 0, 1, 1)
widgetLayout.addWidget(QtWidgets.QLabel("程序英文名:"), 1, 0, 1, 1)
widgetLayout.addWidget(QtWidgets.QLabel("包描述:"), 2, 0, 1, 1)
widgetLayout.addWidget(QtWidgets.QLabel("程序分类:"), 3, 0, 1, 1)
widgetLayout.addWidget(QtWidgets.QLabel("程序在 Wine 容器的位置:"), 4, 0, 1, 1)
widgetLayout.addWidget(QtWidgets.QLabel("包名:"), 5, 0, 1, 1)
widgetLayout.addWidget(QtWidgets.QLabel("版本号:"), 6, 0, 1, 1)
widgetLayout.addWidget(chineseName, 0, 1, 1, 1)
widgetLayout.addWidget(englishName, 1, 1, 1, 1)
widgetLayout.addWidget(debDescription, 2, 1, 1, 1)
widgetLayout.addWidget(typeName, 3, 1, 1, 1)
widgetLayout.addWidget(exePath, 4, 1, 1, 1)
widgetLayout.addWidget(packageName, 5, 1, 1, 1)
widgetLayout.addWidget(versionName, 6, 1, 1, 1)
widgetLayout.addLayout(controlFrame, 7, 0, 1, 2)
widgetLayout.addWidget(commandReturn, 8, 0, 1, 2)
buildDeb.clicked.connect(PackageDeb)
debPath.clicked.connect(OpenPackageFolder)
widget.setLayout(widgetLayout)
window.setCentralWidget(widget)
2022-09-20 21:53:37 +08:00
window.resize(int(window.frameGeometry().width() * 1.5), int(window.frameGeometry().height()))
2022-07-18 20:32:01 +08:00
window.setWindowIcon(QtGui.QIcon(iconPath))
menu = window.menuBar()
programMenu = menu.addMenu("程序")
exit = QtWidgets.QAction("退出")
exit.triggered.connect(window.close)
2022-08-01 16:11:46 +08:00
helpMenu = menu.addMenu("帮助")
2022-07-18 20:32:01 +08:00
help = QtWidgets.QAction("帮助")
help.triggered.connect(ShowHelp)
2022-08-01 16:11:46 +08:00
helpMenu.addAction(help)
2022-07-18 20:32:01 +08:00
programMenu.addAction(exit)
print(iconPath)
window.show()
window.setWindowTitle(f"Wine 打包器 {version}——基于统信 Wine 生态活动打包脚本制作")
windowFrameInputValueList = [
chineseName,
englishName,
debDescription,
typeName,
exePath,
packageName,
versionName
]
sys.exit(app.exec_())