From 30f68a3521d1c0a8b096acb056e7ed4ab6a5d62e Mon Sep 17 00:00:00 2001 From: Melon Bread Date: Tue, 5 Mar 2019 09:27:48 -0500 Subject: [PATCH] Maybe instead of stressing about threads I should make sure my logic is sound. --- RetroUFO_GUI.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/RetroUFO_GUI.py b/RetroUFO_GUI.py index 7185e43..da297c0 100755 --- a/RetroUFO_GUI.py +++ b/RetroUFO_GUI.py @@ -10,7 +10,6 @@ __license__ = "MIT" import os import platform import sys -import time import zipfile from shutil import rmtree from urllib.request import urlretrieve @@ -48,23 +47,27 @@ class GrabThread(QThread): self.extract_cores(self.location) pass + def create_dir(self, _name): + if not os.path.isdir(_name): + os.makedirs(_name) + + def obtain_core_list(self, _platform, _architecture): + urlretrieve( + '{}/{}/{}/latest/.index-extended'.format( + URL, _platform, _architecture), 'cores/index') + self.add_to_log.emit('Obtained core index!\n') + def download_cores(self, _platform, _architecture): """ Downloads every core to the working directory """ cores = [] # Makes core directory to store archives if needed - if not os.path.isdir('cores'): - os.makedirs("cores") - time.sleep(1) # TODO: Do not leave this here! Find a way to wait for the core dir to be made! + self.create_dir("cores") # Downloads a list of all the cores available - urlretrieve( - '{}/{}/{}/latest/.index-extended'.format( - URL, _platform, _architecture), 'cores/index') - time.sleep(1) # TODO: Do not leave this here! Find a way to wait for the index to download! - self.add_to_log.emit('Obtained core index!\n') - + self.obtain_core_list(_platform, _architecture) + # Adds all the core's file names to a list core_index = open('cores/index') @@ -180,6 +183,8 @@ class Form(QDialog): def grab_cores(self): """ Where the magic happens """ + if not self.chkboxKeepDownload.isChecked(): + self.clean_up() # TODO: Lock (disable) the UI elements while grabbing cores @@ -191,8 +196,6 @@ class Form(QDialog): self.grab.add_to_log.connect(self.update_log) self.grab.start() - if not self.chkboxKeepDownload.isChecked(): - self.clean_up() def get_platform(self): """ Gets the Platform and Architecture if not supplied """