Skip to content

Commit eeaabd6

Browse files
committed
fix bugs on linux
1 parent 4ae0158 commit eeaabd6

File tree

4 files changed

+42
-13
lines changed

4 files changed

+42
-13
lines changed

modules/service/init/InitManager.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from PySide6.QtWidgets import QHeaderView, QTableWidget
44

5+
from modules.utils.SysUtils import SysUtils
56
from modules.service.base.BaseService import BaseService
67
from modules.service.manager.ConfigManager import ConfigManager, ConfigKey
78
from modules.utils.PathUtils import PathUtils
@@ -53,6 +54,9 @@ def initData(self):
5354
sysFFmpegPath = configManager.get(ConfigKey.SYS_FFMPEG_PATH)
5455
context.setSysFFmpegPath(sysFFmpegPath)
5556

57+
# 检查ffmpeg是否有执行权限
58+
SysUtils.checkFFmpegExecPermissions(sysFFmpegPath)
59+
5660
# allPath = context.getConfigPathDict()
5761
# # 检查路径是否有空格
5862
# StrUtils.isNullOrWhitespace(context, allPath)

modules/utils/FFmpegUtils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def runCommand(content, cacheInfo: CacheInfo, outputAllPath: str):
1717
if blvPathList is None:
1818
audioPath = cacheInfo.getAudioPath()
1919
videoPath = cacheInfo.getVideoPath()
20-
20+
2121
cmd = f"{ffmpegPath} -i {audioPath} -i {videoPath} -c copy -y {outputAllPath}"
2222
else:
2323
srcDir = os.path.dirname(blvPathList[0])
@@ -37,5 +37,7 @@ def runCommand(content, cacheInfo: CacheInfo, outputAllPath: str):
3737

3838
if return_code == 0:
3939
return True
40+
elif return_code == 126:
41+
print("ffmpeg没有权限")
4042
else:
4143
return False

modules/utils/SysUtils.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
import subprocess
13
import sys
24
from enum import Enum
35

@@ -34,3 +36,19 @@ def getTransparentIcon() -> QIcon:
3436
transparent_icon.addPixmap(transparent_pixmap)
3537

3638
return transparent_icon
39+
40+
# 检查ffmpeg文件是否具有可执行权限
41+
@staticmethod
42+
def checkFFmpegExecPermissions(ffmpeg_path: str):
43+
if os.access(ffmpeg_path, os.X_OK):
44+
print("ffmpeg具有执行权限")
45+
else:
46+
print("ffmpeg没有执行权限")
47+
# 使用subprocess执行chmod命令给ffmpeg文件添加可执行权限
48+
cmd = f"chmod 775 {ffmpeg_path}"
49+
exit_code = subprocess.call(cmd, shell=True)
50+
51+
if os.access(ffmpeg_path, os.X_OK):
52+
print(f"自动授权成功")
53+
else:
54+
print(f"自动授权失败,请手动给{ffmpeg_path}授予执行权限")

script/packagescript.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,27 @@
22
import shutil
33
import sys
44
from enum import Enum
5+
import sys
56

67
import PyInstaller.__main__
7-
8-
from modules.utils.SysUtils import SysType, SysUtils
9-
from script.appDetails import APP_NAME
10-
8+
#///////////////不能改变导入顺序///////////////////////////////
119
workPath = os.getcwd()
1210
workParentPath = os.path.dirname(workPath)
11+
# 将workParentPath也设置为工作目录
12+
sys.path.append(workParentPath)
13+
from script.appDetails import APP_NAME
14+
from modules.utils.SysUtils import SysType, SysUtils
15+
#//////////////////////////////////////////////
16+
17+
1318
# 未打包路径
14-
ffmpegExePath = "../res/ffmpeg/ffmpeg.exe"
19+
ffmpegExePath = os.path.join(workParentPath,"res/ffmpeg/ffmpeg.exe")
1520
# 打包后的路径
1621
ffmpegPackageDir = "./res/ffmpeg"
1722
ffmpegPackageDirUpkg = "./res/ffmpeg/ffmpeg.exe"
1823
pythonMainPath = os.path.join(workParentPath, 'main.py')
1924
outputDir = os.path.join(workPath, "dist")
20-
icoPath = workParentPath + '/res/images/images/ml.ico'
25+
icoPath =os.path.join(workParentPath,'res/images/images/ml.ico')
2126

2227
themesPath = os.path.join(workParentPath, 'themes')
2328
themesPackageDir = "./themes"
@@ -28,14 +33,14 @@
2833
def beforePkgMac():
2934
global ffmpegExePath
3035
global ffmpegPackageDirUpkg
31-
ffmpegExePath = "../res/ffmpeg/ffmpeg-mac"
36+
ffmpegExePath = os.path.join(workParentPath,"res/ffmpeg/ffmpeg-mac")
3237
ffmpegPackageDirUpkg = "./res/ffmpeg/ffmpeg-mac"
3338

3439

3540
def beforePkgLinux():
3641
global ffmpegExePath
3742
global ffmpegPackageDirUpkg
38-
ffmpegExePath = "../res/ffmpeg/ffmpeg-linux"
43+
ffmpegExePath = os.path.join(workParentPath, "res/ffmpeg/ffmpeg-linux")
3944
ffmpegPackageDirUpkg = "./res/ffmpeg/ffmpeg-linux"
4045

4146

@@ -52,10 +57,10 @@ def Ppkg(sysType):
5257
pythonMainPath, # 指定你的Python脚本文件
5358
'--add-data', f'{ffmpegExePath};{ffmpegPackageDir}', # 将ffmpeg文件复制到指定目录
5459
'-n', softName,
60+
'--add-binary', f'{themesPath};{themesPackageDir}',
5561
# 前面的顺序不要动
56-
# '--add-binary', f'{ffmpegExePath};{ffmpegPackageDir}', # 将ffmpeg文件夹复制到指定目录
62+
# '--add-binary', f'{ffmpegExePath}:{ffmpegPackageDir}', # 将ffmpeg文件夹复制到指定目录
5763
# '--onefile', # 打包成一个单独的可执行文件
58-
'--add-binary', f'{themesPath};{themesPackageDir}',
5964
'-i', icoPath,
6065
'--noconsole', # 不显示控制台窗口
6166
'--clean',
@@ -64,8 +69,9 @@ def Ppkg(sysType):
6469
# 需要打包文件夹
6570
if sysType == SysType.LINUX:
6671
cmd[1] = "--add-binary"
67-
cmd[2] = f'{ffmpegExePath};{ffmpegPackageDirUpkg}'
72+
cmd[2] = f'{ffmpegExePath}:{ffmpegPackageDirUpkg}'
6873
cmd[4] = APP_NAME
74+
cmd[6] = f'{themesPath}:{themesPackageDir}'
6975

7076
PyInstaller.__main__.run(cmd)
7177

@@ -145,7 +151,6 @@ def chooseType(sysType, inType):
145151
print(
146152
f"请选择打包方式:\n{PkgType.PYINSTALLER_PKG.value}.PyInstaller\n{PkgType.NUITKA.value}.Nuitka\n{PkgType.NON.value}.什么也不做\n请输入前面的序号:")
147153
inType = int(input())
148-
149154
# sysType = SysType.MAC
150155
# sysType = SysType.LINUX
151156
if inType == PkgType.NON.value:

0 commit comments

Comments
 (0)