mirror of
https://github.com/Faraphel/Atlas-Install.git
synced 2025-07-03 19:28:25 +02:00
splitted the code into 2 function, and added a last clean process to wait for last track conversion.
This commit is contained in:
parent
31de91f082
commit
c155131b9b
1 changed files with 79 additions and 64 deletions
|
@ -34,10 +34,9 @@ def patch_track(self, tracks, total_track="?"):
|
||||||
process_list = {}
|
process_list = {}
|
||||||
error_count, error_max = 0, 3
|
error_count, error_max = 0, 3
|
||||||
|
|
||||||
for i, track in enumerate(tracks):
|
def add_process(track_file):
|
||||||
track_file = get_trackname(track=track)
|
nonlocal error_count, error_max, process_list
|
||||||
while True:
|
|
||||||
if len(process_list) < max_process:
|
|
||||||
process_list[track_file] = None # Used for
|
process_list[track_file] = None # Used for
|
||||||
self.Progress(statut=self.translate("Conversion des courses") + f"\n({i + 1}/{total_track})\n" +
|
self.Progress(statut=self.translate("Conversion des courses") + f"\n({i + 1}/{total_track})\n" +
|
||||||
"\n".join(process_list.keys()), add=1)
|
"\n".join(process_list.keys()), add=1)
|
||||||
|
@ -60,7 +59,8 @@ def patch_track(self, tracks, total_track="?"):
|
||||||
self.translate("Impossible de télécharger cette course ! (") +
|
self.translate("Impossible de télécharger cette course ! (") +
|
||||||
str(error_count) + "/" + str(error_max) + ")")
|
str(error_count) + "/" + str(error_max) + ")")
|
||||||
|
|
||||||
if not (os.path.exists(get_track_szs(track_file))) or download_returncode == 3: # returncode 3 is track has been updated
|
if not (os.path.exists(
|
||||||
|
get_track_szs(track_file))) or download_returncode == 3: # returncode 3 is track has been updated
|
||||||
if os.path.exists(get_track_wu8(track_file)):
|
if os.path.exists(get_track_wu8(track_file)):
|
||||||
process_list[track_file] = subprocess.Popen([
|
process_list[track_file] = subprocess.Popen([
|
||||||
"./tools/szs/wszst", "NORMALIZE", get_track_wu8(track_file), "--DEST",
|
"./tools/szs/wszst", "NORMALIZE", get_track_wu8(track_file), "--DEST",
|
||||||
|
@ -72,35 +72,50 @@ def patch_track(self, tracks, total_track="?"):
|
||||||
"Réactiver le téléchargement des courses et réessayer."))
|
"Réactiver le téléchargement des courses et réessayer."))
|
||||||
return -1
|
return -1
|
||||||
elif self.boolvar_del_track_after_conv.get(): os.remove(get_track_wu8(track_file))
|
elif self.boolvar_del_track_after_conv.get(): os.remove(get_track_wu8(track_file))
|
||||||
break
|
return 0
|
||||||
else:
|
|
||||||
for _track_file, process in process_list.items():
|
def clean_process():
|
||||||
|
nonlocal error_count, error_max, process_list
|
||||||
|
|
||||||
|
for track_file, process in process_list.items():
|
||||||
if process is not None:
|
if process is not None:
|
||||||
if process.poll() is None: pass # if the process is still running
|
if process.poll() is None:
|
||||||
|
pass # if the process is still running
|
||||||
else: # process ended
|
else: # process ended
|
||||||
process_list.pop(_track_file)
|
process_list.pop(track_file)
|
||||||
stderr = process.stderr.read()
|
stderr = process.stderr.read()
|
||||||
if b"wszst: ERROR" in stderr: # Error occured
|
if b"wszst: ERROR" in stderr: # Error occured
|
||||||
os.remove(get_track_szs(_track_file))
|
os.remove(get_track_szs(track_file))
|
||||||
error_count += 1
|
error_count += 1
|
||||||
if error_count > error_max: # Too much track wasn't correctly converted
|
if error_count > error_max: # Too much track wasn't correctly converted
|
||||||
messagebox.showerror(
|
messagebox.showerror(
|
||||||
self.translate("Erreur"),
|
self.translate("Erreur"),
|
||||||
self.translate("Trop de course ont eu une erreur de conversion."))
|
self.translate("Trop de course ont eu une erreur de conversion."))
|
||||||
return
|
return -1
|
||||||
else: # if the error max hasn't been reach
|
else: # if the error max hasn't been reach
|
||||||
messagebox.showwarning(
|
messagebox.showwarning(
|
||||||
self.translate("Attention"),
|
self.translate("Attention"),
|
||||||
self.translate("La course ") +
|
self.translate("La course ") +
|
||||||
get_track_wu8(_track_file) +
|
get_track_wu8(track_file) +
|
||||||
self.translate(" n'a pas été correctement converti. (") +
|
self.translate(" n'a pas été correctement converti. (") +
|
||||||
str(error_count) + "/" + str(error_max) + ")")
|
str(error_count) + "/" + str(error_max) + ")")
|
||||||
break
|
return 0
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if self.boolvar_del_track_after_conv.get(): os.remove(get_track_wu8(_track_file))
|
if self.boolvar_del_track_after_conv.get(): os.remove(get_track_wu8(track_file))
|
||||||
break
|
return 0
|
||||||
else:
|
else:
|
||||||
process_list.pop(_track_file)
|
process_list.pop(track_file)
|
||||||
break
|
|
||||||
|
if any(process_list.values()): return 0 # si il y a encore des processus
|
||||||
|
else: return 1 # si il n'y a plus de processus
|
||||||
|
|
||||||
|
for i, track in enumerate(tracks):
|
||||||
|
track_file = get_trackname(track=track)
|
||||||
|
while True:
|
||||||
|
if len(process_list) < max_process:
|
||||||
|
if add_process(track_file) == 0: break
|
||||||
|
else: clean_process()
|
||||||
|
while clean_process() != 1: pass # End the process if all process ended
|
||||||
|
|
||||||
return 0
|
return 0
|
Loading…
Reference in a new issue