Skip to content

Commit f760cbd

Browse files
committed
Refactor update mechanism and simplify config
- Migrate part of config settings to main file and updater file - Add deprecated file cleaning feature to main file - Remove configParser in updater - Remove commandline scripts in updater - Remove redundant inner functions in updater - Add exception handling for archive unpacking - Standarlize variable naming conventions
1 parent faaf75e commit f760cbd

File tree

4 files changed

+157
-169
lines changed

4 files changed

+157
-169
lines changed

EVT_GUI/src/config.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,12 @@
11
import sys
22
from pathlib import Path
3-
from PyEasyUtils import getFileInfo, getBaseDir, normPath
43

54
##############################################################################################################################
65

7-
# Set current version
8-
currentVersion = "v1.2.4"
9-
106
# Set info for update url
117
repoOwner = 'Spr-Aachen'
128
repoName = 'Easy-Voice-Toolkit'
139
fileName = 'EVT_windows_x64'
1410
fileFormat = 'zip'
1511

16-
##############################################################################################################################
17-
18-
# Check whether python file is compiled
19-
_, isFileCompiled = getFileInfo()
20-
21-
# Get current directory
22-
currentDir = getBaseDir(sys.argv[0])
23-
24-
# Set path to store log
25-
logPath = normPath(Path(currentDir).joinpath('log.txt'))
26-
27-
# Set directory to load static dependencies
28-
resourceDir = currentDir if getBaseDir(searchMEIPASS = True) is None else getBaseDir(searchMEIPASS = True)
29-
3012
##############################################################################################################################

EVT_GUI/src/main.py

Lines changed: 60 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from datetime import date
99
from PySide6 import __file__ as PySide6_File
1010
from PySide6.QtCore import Qt, QObject, Signal
11-
from PySide6.QtCore import QCoreApplication as QCA, QThreadPool
11+
from PySide6.QtCore import QCoreApplication as QCA, QThreadPool, QTimer
1212
from PySide6.QtGui import QColor, QPixmap, QIcon, QTextCursor
1313
from QEasyWidgets import QFunctions as QFunc
1414
from QEasyWidgets import QTasks
@@ -25,20 +25,41 @@
2525

2626
##############################################################################################################################
2727

28+
# Get current path
29+
currentPath = EasyUtils.getCurrentPath()
30+
31+
# Get current directory
32+
currentDir = Path(currentPath).parent.as_posix()
33+
34+
# Set path to store log
35+
logPath = EasyUtils.normPath(Path(currentDir).joinpath('log.txt'))
36+
37+
# Set directory to load static dependencies
38+
resourceDir = EasyUtils.getBaseDir(searchMEIPASS = True) or currentDir
39+
40+
# Check whether python file is compiled
41+
_, isFileCompiled = EasyUtils.getFileInfo()
42+
43+
# Get current version (assume resourceDir is the name of current version after being compiled)
44+
currentVersion = Path(resourceDir).name if isFileCompiled else 'beta version'
45+
46+
##############################################################################################################################
47+
2848
# Change working directory to current directory
2949
os.chdir(currentDir)
3050

3151

3252
# Parse path settings
3353
parser = argparse.ArgumentParser()
34-
parser.add_argument("--updater", help = "path to updater", default = Path(currentDir).joinpath('Updater.py' if isFileCompiled == False else 'Updater.exe'))
35-
parser.add_argument("--core", help = "dir of core files", default = Path(resourceDir).joinpath('EVT_Core'))
36-
parser.add_argument("--manifest", help = "path to manifest.json", default = Path(resourceDir).joinpath('manifest.json'))
37-
parser.add_argument("--requirements", help = "path to requirements.txt", default = Path(resourceDir).joinpath('requirements.txt'))
38-
parser.add_argument("--dependencies", help = "dir of dependencies", default = Path(currentDir).joinpath(''))
39-
parser.add_argument("--models", help = "dir of models", default = Path(currentDir).joinpath('Models'))
40-
parser.add_argument("--output", help = "dir of output", default = Path(currentDir).joinpath(''))
41-
parser.add_argument("--profile", help = "dir of profile", default = Path(currentDir).joinpath(''))
54+
parser.add_argument("--updater", help = "path to updater", default = Path(resourceDir).joinpath('updater.exe') if isFileCompiled else Path(currentDir).joinpath('updater.py'))
55+
parser.add_argument("--core", help = "dir of core files", default = Path(resourceDir).joinpath('EVT_Core'))
56+
parser.add_argument("--manifest", help = "path to manifest.json", default = Path(resourceDir).joinpath('manifest.json'))
57+
parser.add_argument("--requirements", help = "path to requirements.txt", default = Path(resourceDir).joinpath('requirements.txt'))
58+
parser.add_argument("--dependencies", help = "dir of dependencies", default = Path(currentDir).joinpath(''))
59+
parser.add_argument("--models", help = "dir of models", default = Path(currentDir).joinpath('Models'))
60+
parser.add_argument("--output", help = "dir of output", default = Path(currentDir).joinpath(''))
61+
parser.add_argument("--profile", help = "dir of profile", default = Path(currentDir).joinpath(''))
62+
parser.add_argument("--deprecatedVersion", help = "deprecated version", default = None)
4263
args = parser.parse_args()
4364

4465
updaterPath = args.updater
@@ -49,14 +70,13 @@
4970
modelDir = args.models
5071
outputDir = args.output
5172
profileDir = args.profile
73+
deprecatedVersion = args.deprecatedVersion
5274

5375

5476
# Set up client config
5577
configDir = EasyUtils.normPath(Path(profileDir).joinpath('config'))
5678
configPath = EasyUtils.normPath(Path(configDir).joinpath('config.ini'))
5779
config = EasyUtils.configManager(configPath)
58-
config.editConfig('Info', 'currentVersion', str(currentVersion))
59-
config.editConfig('Info', 'executerName', str(EasyUtils.getFileInfo()[0]))
6080

6181

6282
# Set up environment variables while python file is not compiled
@@ -154,7 +174,6 @@ def __init__(self):
154174
self.MonitorUsage.start()
155175

156176
def closeEvent(self, event):
157-
config.editConfig('Info', 'executerName', '')
158177
FunctionSignals.Signal_TaskStatus.connect(lambda: QApplication.instance().exit())
159178
FunctionSignals.Signal_ForceQuit.emit()
160179

@@ -602,19 +621,31 @@ def showTTSResult(self, mediaPath):
602621
)
603622
ChildWindow_TTS.exec()
604623

605-
def chkUpdate(self):
624+
def chkUpdate(self, runUpdateChecker: bool):
625+
recordedVersion = deprecatedVersion or config.getValue('Info', 'RecordedVersion', currentVersion)
626+
if not EasyUtils.isVersionSatisfied(recordedVersion, currentVersion):
627+
deprecatedDir = Path(resourceDir).parent.joinpath(recordedVersion).as_posix()
628+
time.sleep(3)
629+
try:
630+
shutil.rmtree(deprecatedDir)
631+
except:
632+
pass
633+
else:
634+
config.editConfig('Info', 'RecordedVersion', currentVersion)
635+
606636
FunctionSignals.Signal_ReadyToUpdate.connect(
607-
lambda DownloadURL, VersionInfo: (
637+
lambda downloadURL, versionInfo: (
608638
MessageBoxBase.pop(None,
609639
QMessageBox.Question, "Ask",
610640
text = "检测到可用的新版本,是否更新?\nNew version available, wanna update?",
611-
detailedText = VersionInfo,
641+
detailedText = versionInfo,
612642
buttons = QMessageBox.Yes|QMessageBox.No,
613643
buttonEvents = {
614644
QMessageBox.Yes: lambda: (
615645
config.editConfig('Updater', 'Asked', 'True'),
616-
subprocess.Popen(f'{"python" if isFileCompiled == False else ""} "{updaterPath}" --config "{configPath}"', shell = True, env = os.environ),
617-
QApplication.instance().exit()
646+
subprocess.Popen(f'{"python" if isFileCompiled == False else ""} "{updaterPath}" --programPath "{currentPath}" --currentVersion {currentVersion} --downloadURL "{downloadURL}"', shell = True, env = os.environ),
647+
QApplication.instance().exit(),
648+
sys.exit(0) # In case the main event loop is not entered
618649
),
619650
QMessageBox.No: lambda: (
620651
config.editConfig('Updater', 'Asked', 'False'),
@@ -623,7 +654,6 @@ def chkUpdate(self):
623654
)
624655
)
625656
)
626-
627657
Function_SetMethodExecutor(
628658
executeMethod = Function_UpdateChecker,
629659
executeParams = (
@@ -635,14 +665,14 @@ def chkUpdate(self):
635665
),
636666
threadPool = self.threadPool,
637667
parentWindow = self,
638-
)
668+
) if runUpdateChecker else None
639669

640670
def main(self):
641671
'''
642672
Main funtion to orgnize all the subfunctions
643673
'''
644674
# Check for updates
645-
self.chkUpdate() if config.getValue('Settings', 'AutoUpdate', 'Enabled') == 'Enabled' else None
675+
self.chkUpdate(config.getValue('Settings', 'AutoUpdate', 'Enabled') == 'Enabled') if isFileCompiled else None
646676

647677
# Logo
648678
self.setWindowIcon(QIcon(EasyUtils.normPath(Path(resourceDir).joinpath('assets/images/Logo.ico'))))
@@ -871,7 +901,7 @@ def main(self):
871901
self.ui.Label_Donate_Text.setText(QCA.translate('MainWindow', "赞助作者"))
872902
Function_SetURL(
873903
button = self.ui.Button_Donate,
874-
url = "https://ko-fi.com/spr_aachen",
904+
url = "https://afdian.tv/a/Spr_Aachen/plan",
875905
buttonTooltip = "Click to buy author a coffee"
876906
)
877907

@@ -1301,7 +1331,7 @@ def main(self):
13011331
subPage_process.addChkOutputSideBtn(
13021332
outputRootEdit = self.ui.LineEdit_Process_OutputRoot,
13031333
)
1304-
self.task_audioProcessing = Execute_Audio_Processing(coreDir)
1334+
self.task_audioProcessing = Execute_Audio_Processing(coreDir, logPath)
13051335
subPage_process.setExecutor(
13061336
consoleWidget = self.ui.Frame_Console,
13071337
executeMethod = self.task_audioProcessing.execute,
@@ -1539,7 +1569,7 @@ def EditVPRResult():
15391569
EditVPRResult
15401570
]
15411571
)
1542-
self.task_voiceIdentifying_vpr = Execute_Voice_Identifying_VPR(coreDir)
1572+
self.task_voiceIdentifying_vpr = Execute_Voice_Identifying_VPR(coreDir, logPath)
15431573
subPage_VPR.setExecutor(
15441574
consoleWidget = self.ui.Frame_Console,
15451575
executeMethod = self.task_voiceIdentifying_vpr.execute,
@@ -1675,7 +1705,7 @@ def EditVPRResult():
16751705
subPage_ASR.addChkOutputSideBtn(
16761706
outputRootEdit = self.ui.LineEdit_ASR_Whisper_OutputRoot
16771707
)
1678-
self.task_voiceTranscribing_whisper = Execute_Voice_Transcribing_Whisper(coreDir)
1708+
self.task_voiceTranscribing_whisper = Execute_Voice_Transcribing_Whisper(coreDir, logPath)
16791709
subPage_ASR.setExecutor(
16801710
consoleWidget = self.ui.Frame_Console,
16811711
executeMethod = self.task_voiceTranscribing_whisper.execute,
@@ -1817,7 +1847,7 @@ def EditVPRResult():
18171847
subPage_dataset_GPTSoVITS.addChkOutputSideBtn(
18181848
outputRootEdit = self.ui.LineEdit_DAT_GPTSoVITS_OutputRoot
18191849
)
1820-
self.task_datasetCreating_gptsovits = Execute_Dataset_Creating_GPTSoVITS(coreDir)
1850+
self.task_datasetCreating_gptsovits = Execute_Dataset_Creating_GPTSoVITS(coreDir, logPath)
18211851
subPage_dataset_GPTSoVITS.setExecutor(
18221852
consoleWidget = self.ui.Frame_Console,
18231853
executeMethod = self.task_datasetCreating_gptsovits.execute,
@@ -2007,7 +2037,7 @@ def EditVPRResult():
20072037
subPage_dataset_VITS.addChkOutputSideBtn(
20082038
outputRootEdit = self.ui.LineEdit_DAT_VITS_OutputRoot
20092039
)
2010-
self.task_datasetCreating_vits = Execute_Dataset_Creating_VITS(coreDir)
2040+
self.task_datasetCreating_vits = Execute_Dataset_Creating_VITS(coreDir, logPath)
20112041
subPage_dataset_VITS.setExecutor(
20122042
consoleWidget = self.ui.Frame_Console,
20132043
executeMethod = self.task_datasetCreating_vits.execute,
@@ -2263,7 +2293,7 @@ def EditVPRResult():
22632293
)
22642294
]
22652295
)
2266-
self.task_voiceTraining_gptsovits = Execute_Voice_Training_GPTSoVITS(coreDir)
2296+
self.task_voiceTraining_gptsovits = Execute_Voice_Training_GPTSoVITS(coreDir, logPath)
22672297
subPage_train_gptsovits.setExecutor(
22682298
consoleWidget = self.ui.Frame_Console,
22692299
executeMethod = self.task_voiceTraining_gptsovits.execute,
@@ -2505,7 +2535,7 @@ def EditVPRResult():
25052535
)
25062536
]
25072537
)
2508-
self.task_voiceTraining_vits = Execute_Voice_Training_VITS(coreDir)
2538+
self.task_voiceTraining_vits = Execute_Voice_Training_VITS(coreDir, logPath)
25092539
subPage_train_VITS.setExecutor(
25102540
consoleWidget = self.ui.Frame_Console,
25112541
executeMethod = self.task_voiceTraining_vits.execute,
@@ -2722,7 +2752,7 @@ def EditVPRResult():
27222752
)
27232753
]
27242754
)
2725-
self.task_voiceConverting_gptsovits = Execute_Voice_Converting_GPTSoVITS(coreDir)
2755+
self.task_voiceConverting_gptsovits = Execute_Voice_Converting_GPTSoVITS(coreDir, logPath)
27262756
subPage_tts_gptsovits.setExecutor(
27272757
consoleWidget = self.ui.Frame_Console,
27282758
executeMethod = self.task_voiceConverting_gptsovits.execute,
@@ -2876,7 +2906,7 @@ def EditVPRResult():
28762906
)
28772907
]
28782908
)
2879-
self.task_voiceConverting_vits = Execute_Voice_Converting_VITS(coreDir)
2909+
self.task_voiceConverting_vits = Execute_Voice_Converting_VITS(coreDir, logPath)
28802910
subPage_TTS_VITS.setExecutor(
28812911
consoleWidget = self.ui.Frame_Console,
28822912
executeMethod = self.task_voiceConverting_vits.execute,

0 commit comments

Comments
 (0)