def __init__(self, log_file_name): """Initialize logger variables""" # Set log dir to temp if writable, if not log to current dir log_dir = tempfile.gettempdir() if not Utils.dir_is_writable(log_dir): log_dir = os.path.abspath(os.getcwd()) self.log_file_path = os.path.join(log_dir, log_file_name)
def run(self): """Main process for archive extraction thread""" extract_count = 0 extract_range = len(self.archive_file_list) self.main_panel_object.extract_all_button.SetLabel( StringManager.SM.button_label_cancel) SimpleLogger.log.info_msg( f"ExtractionWorker thread started, extracting {extract_range} archive file(s)" ) # Close thread if the extraction path is not a directory if not os.path.isdir(self.extract_path): SimpleLogger.log.error_msg( f"Extract path '{self.extract_path}' does not exist, aborting") self.close_thread(cancelled=True) return # Close thread if the extraction path is not writable if not Utils.dir_is_writable(self.extract_path): SimpleLogger.log.error_msg( f"Extract path '{self.extract_path}' is not writable, aborting" ) self.close_thread(cancelled=True) return # Extract archive files for archive_file in self.archive_file_list: if not self.thread_active: SimpleLogger.log.info_msg( "ExtractionWorker thread cancelled, aborting") return SimpleLogger.log.info_msg( f"Extracting archive {extract_count + 1}/{extract_range}") if archive_file.archive_format == ".rar": self.__extract_rar_file(archive_file.file_path) if archive_file.archive_format == ".zip": self.__extract_zip_file(archive_file.file_path) if not self.thread_active: SimpleLogger.log.info_msg( "ExtractionWorker thread cancelled, aborting") return # Update progress bar extract_count += 1 self.main_panel_object.refresh_progress_bar( extract_count, extract_range) # Close thread self.close_thread() return