Skip to content

Commit a23add6

Browse files
committed
upd: gui
1 parent cfead51 commit a23add6

File tree

10 files changed

+355
-128
lines changed

10 files changed

+355
-128
lines changed

Launcher.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ set "_pyBin=%_root%\toolkit\"
1010
set "_GitBin=%_root%\toolkit\Git\mingw64\bin"
1111
set "PATH=%_pyBin%;%_pyBin%\Scripts;%_GitBin%;%PATH%"
1212
title Python-Git-Program-Launcher
13-
python -m main
13+
python -m gui
1414

1515
echo The program is over. This may be due to an error or an active end.
1616
pause

gui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ def main():
2424
main()
2525

2626
# cef: pip install cefpython3
27-
# qt: pip install PyQtWebEngine; pip install PyQt5
27+
# qt: pip install PyQtWebEngine
2828
# edgechromium: install edge

main.py

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,25 @@ def write(self,x):
2121
else:
2222
self.original.write(x)
2323

24+
class ProgressTracker():
25+
def __init__(self) -> None:
26+
self.percentage = 0
27+
self.info = ''
28+
self.end_flag = False
29+
30+
def set_percentage(self, x):
31+
self.percentage = x
32+
33+
def set_info(self, x):
34+
self.info = x
2435

25-
36+
def inp(self, info, percentage):
37+
self.info = info
38+
self.percentage = percentage
39+
2640
class GitManager(Command):
2741

28-
def __init__(self, installer_config):
42+
def __init__(self, installer_config, progress_tracker=None):
2943
self.git = os.path.join(ROOT_PATH, "toolkit\\Git\\mingw64\\bin\\git.exe")
3044
self.Repository = installer_config["Repository"]
3145
self.Branch = installer_config["Branch"]
@@ -36,6 +50,9 @@ def __init__(self, installer_config):
3650
self.folder_path = REPO_PATH
3751

3852
verify_path(self.folder_path)
53+
54+
if progress_tracker is None: progress_tracker = ProgressTracker()
55+
self.progress_tracker = progress_tracker
3956

4057
@staticmethod
4158
def remove(file):
@@ -46,30 +63,30 @@ def remove(file):
4663
logger.info(f'File not found: {file}')
4764

4865
def git_repository_init(self, repo, source='origin', branch='master', proxy=False, keep_changes=False):
49-
logger.hr(t2t('Git Init'))
66+
self.logger_hr_and_track(t2t('Git Init'), p=0.1)
5067
if not self.execute(f'"{self.git}" init', allow_failure=True):
5168
self.remove('./.git/config')
5269
self.remove('./.git/index')
5370
self.remove('./.git/HEAD')
5471
self.execute(f'"{self.git}" init')
5572

56-
logger.hr(t2t('Set Git Proxy'), 1)
73+
self.logger_hr_and_track(t2t('Set Git Proxy'), 1, p=0.2)
5774
if proxy:
5875
self.execute(f'"{self.git}" config --local http.proxy {proxy}')
5976
self.execute(f'"{self.git}" config --local https.proxy {proxy}')
6077
else:
6178
self.execute(f'"{self.git}" config --local --unset http.proxy', allow_failure=True)
6279
self.execute(f'"{self.git}" config --local --unset https.proxy', allow_failure=True)
6380

64-
logger.hr(t2t('Set Git Repository'), 1)
81+
self.logger_hr_and_track(t2t('Set Git Repository'), 1, p=0.3)
6582
if not self.execute(f'"{self.git}" remote set-url {source} {repo}', allow_failure=True):
6683
self.execute(f'"{self.git}" remote add {source} {repo}')
6784

68-
logger.hr(t2t('Fetch Repository Branch'), 1)
69-
# logger.hr('For cn user: 重要: 如果你正在使用Github地址,确保你已经启动Watt Toolkit或其他加速器')
85+
self.logger_hr_and_track(t2t('Fetch Repository Branch'), 1, p=0.4)
86+
# self.logger_hr_and_track('For cn user: 重要: 如果你正在使用Github地址,确保你已经启动Watt Toolkit或其他加速器')
7087
self.execute(f'"{self.git}" fetch {source} {branch}')
7188

72-
logger.hr(t2t('Pull Repository Branch'), 1)
89+
self.logger_hr_and_track(t2t('Pull Repository Branch'), 1, p=0.5)
7390
# Remove git lock
7491
lock_file = './.git/index.lock'
7592
if os.path.exists(lock_file):
@@ -94,11 +111,11 @@ def git_repository_init(self, repo, source='origin', branch='master', proxy=Fals
94111
if self.tag != 'lastest' and self.tag != '':
95112
self.execute(f'"{self.git}" checkout {self.tag}')
96113

97-
logger.hr(t2t('Show Version'), 1)
114+
self.logger_hr_and_track(t2t('Show Version'), 1, p=0.8)
98115
self.execute(f'"{self.git}" log --no-merges -1')
99116

100117
def git_install(self):
101-
logger.hr(f'Update {PROGRAM_NAME}', 0)
118+
self.logger_hr_and_track(f'Update {PROGRAM_NAME}', 0, p=0.9)
102119

103120
if not self.AutoUpdate:
104121
logger.info(t2t('AutoUpdate is disabled, skip'))
@@ -117,7 +134,7 @@ def git_install(self):
117134

118135
class PipManager(Command):
119136

120-
def __init__(self, installer_config):
137+
def __init__(self, installer_config, progress_tracker=None):
121138
self.RequirementsFile = installer_config["RequirementsFile"]
122139
self.python = PROGRAM_PYTHON_PATH # os.path.join(os.path.dirname(os.path.abspath(__file__)), "toolkit\\python.exe")
123140

@@ -129,6 +146,9 @@ def __init__(self, installer_config):
129146
"en_US": "https://pypi.org/simple"
130147
}[GLOBAL_LANG]
131148

149+
if progress_tracker is None: progress_tracker = ProgressTracker()
150+
self.progress_tracker = progress_tracker
151+
132152
# self.execute("set _pyBin=%_root%\\toolkit")
133153
# self.execute("set _GitBin=%_root%\\toolkit\Git\mingw64\\bin")
134154
# self.execute("set PATH=%_root%\\toolkit\\alias;%_root%\\toolkit\command;%_pyBin%;%_pyBin%\Scripts;%_GitBin%")
@@ -160,24 +180,26 @@ def pip_install(self):
160180
# arg += ['--disable-pip-version-check']
161181
arg = ' ' + ' '.join(arg) if arg else ''
162182
# Don't update pip, just leave it.
163-
logger.hr(t2t('Update pip'), 1)
183+
self.logger_hr_and_track(t2t('Update pip'), 1, p=0.1)
164184

165185
self.execute(f'{self.pip()} install --upgrade pip{arg}')
166186
self.execute(f'{self.pip()} install setuptools{arg}')
167187
self.execute(f'{self.pip()} install wheel{arg}')
168188
self.execute(f'"{self.pip()}" install -r {os.path.join(ROOT_PATH, "toolkit", "basic_requirements.txt")}{arg}')
169189
# self.execute(f'pip install progressbar2{arg}')
170190

171-
logger.hr(t2t('Update Dependencies'), 1)
191+
self.logger_hr_and_track(t2t('Update Dependencies'), 1, p=0.3)
172192

173193
# self.execute((f'{self.pip()} install pycocotools-windows{arg}'))
174194
self.execute(f'{self.pip()} install -r {self.requirements_file()}{arg}')
195+
196+
self.progress_tracker.set_percentage(1)
175197

176198

177199
class PythonManager(Command):
178200

179201
@logger.catch()
180-
def __init__(self, installer_config):
202+
def __init__(self, installer_config, progress_tracker:ProgressTracker=None):
181203
self.python_version = installer_config['PythonVersion']
182204
n = installer_config['Repository'].split('/')[-1]
183205
self.python_folder = os.path.join(ROOT_PATH, 'toolkit', f'python', f"{self.python_version}_{n}")
@@ -188,6 +210,9 @@ def __init__(self, installer_config):
188210
"zh_CN": "https://mirrors.huaweicloud.com/python",
189211
"en_US": "https://www.python.org/ftp/python"
190212
}[GLOBAL_LANG]
213+
if progress_tracker is None:
214+
progress_tracker = ProgressTracker()
215+
self.progress_tracker = progress_tracker
191216

192217
# https://registry.npmmirror.com/-/binary/python/3.10.1/python-3.10.1-amd64.exe
193218
# paths = ''
@@ -201,7 +226,7 @@ def __init__(self, installer_config):
201226

202227
def add_environ(x):
203228
os.environ['PATH'] = x + os.pathsep + os.environ['PATH']
204-
229+
self.progress_tracker.inp(t2t('set environ'), 0)
205230
add_environ(os.path.join(self.python_folder, "Lib", "site-packages"))
206231
add_environ(os.path.join(self.python_folder, "Lib"))
207232
add_environ(os.path.join(self.python_folder, "Scripts"))
@@ -221,19 +246,20 @@ def clean_py(self, py_folder):
221246

222247
def download_python_zip(self):
223248
import zipfile
249+
self.progress_tracker.inp(t2t('download python'), 0.1)
224250
ver = self.python_version
225251
ver2 = ver.split(".")[0]+ver.split(".")[1]
226252
url = fr"{self.python_mirror}/{ver}/python-{ver}-embed-amd64.zip"
227253
logger.info(f'url: {url}')
228254
file_name = os.path.join(self.python_folder, f'python-{ver}-amd64.zip')
229255
download_url(url, file_name)
230-
logger.hr(t2t("Download python successfully, extract zip"))
256+
self.logger_hr_and_track(t2t("Download python successfully, extract zip"), p=0.5)
231257
with zipfile.ZipFile(file_name, 'r') as zip_ref:
232258
zip_ref.extractall(self.python_folder)
233259
# with zipfile.ZipFile(file_name.replace(f'python-{ver}-amd64.zip', f'python{ver2}.zip'), 'r') as zip_ref:
234260
# zip_ref.extractall(self.python_folder)
235261
# install pip
236-
logger.hr("Installing pip")
262+
self.logger_hr_and_track("Installing pip", p=0.8)
237263
self.execute(f'"{self.python_path}" {os.path.join(ROOT_PATH, "toolkit", "get-pip.py")} --no-setuptools --no-wheel')
238264
# self.execute(f'"{self.python_path}" -m pip install setuptools ')
239265

@@ -276,7 +302,7 @@ def download_python_installer(self):
276302
download_url(url, file_name)
277303
os.rename(file_name, file_name2)
278304

279-
logger.hr(t2t("Download Successfully"))
305+
self.logger_hr_and_track(t2t("Download Successfully"))
280306

281307
# with zipfile.ZipFile(file_name, 'r') as zip_ref:
282308
# zip_ref.extractall(self.python_folder)
@@ -289,15 +315,15 @@ def download_python_installer(self):
289315
f'python_{ver}.exe Include_launcher=0 InstallAllUsers=0 Include_test=0 SimpleInstall=1 /passive TargetDir={self.python_folder}',
290316
is_format=False)
291317
os.chdir(ROOT_PATH)
292-
logger.hr(t2t("Please waiting, python is installing. It may cost a few minutes."))
318+
self.logger_hr_and_track(t2t("Please waiting, python is installing. It may cost a few minutes."))
293319

294320
while 1:
295321
time.sleep(1)
296322
if os.path.exists(self.python_path):
297323
break
298-
logger.hr(t2t("Python installed successfully. Cleaning."))
324+
self.logger_hr_and_track(t2t("Python installed successfully. Cleaning."))
299325
time.sleep(1)
300-
logger.hr(t2t("Python is installed."))
326+
self.logger_hr_and_track(t2t("Python is installed."))
301327

302328
def install_pip(self):
303329
# self.execute(f'curl -sSL https://bootstrap.pypa.io/get-pip.py -o get-pip.py')
@@ -309,7 +335,7 @@ def run(self):
309335
verify_path(self.python_folder)
310336

311337
if not os.path.exists(self.python_path):
312-
logger.hr(f"Downloading Python Version: {self.python_version} into {self.python_folder}")
338+
self.logger_hr_and_track(f"Downloading Python Version: {self.python_version} into {self.python_folder}", p=0.05)
313339
# logger.warning(t2t("Please do not exit the program while python is being downloaded. If you accidentally quit or the installation fails, empty the . /toolkit/python folder in the corresponding folder and try again."))
314340
self.download_python_zip()
315341
else:
@@ -327,7 +353,7 @@ def run(self):
327353
# self.install_pip()
328354
global PROGRAM_PYTHON_PATH
329355
PROGRAM_PYTHON_PATH = self.python_path
330-
356+
self.logger_hr_and_track(t2t('python installed'), p=1)
331357
return self.python_path
332358
# self.execute(f'{self.python_path} -m pip')
333359

0 commit comments

Comments
 (0)