diff options
author | vg <vgm+dev@devys.org> | 2025-09-14 19:37:06 +0200 |
---|---|---|
committer | vg <vgm+dev@devys.org> | 2025-09-14 19:37:06 +0200 |
commit | f946248aa5b204ee6642adfeb6ede835ac30915d (patch) | |
tree | c0121ef9ad4bc24fa0a68608889c7d6ab12d11ea /gamechestcli | |
parent | 46f369b5e8b9819628b0e3a21e4b8c05d7975476 (diff) | |
download | gamechest-f946248aa5b204ee6642adfeb6ede835ac30915d.tar.gz gamechest-f946248aa5b204ee6642adfeb6ede835ac30915d.tar.bz2 gamechest-f946248aa5b204ee6642adfeb6ede835ac30915d.zip |
git-sync on ditawip
Diffstat (limited to 'gamechestcli')
-rw-r--r-- | gamechestcli/gamechest/runners/extract.py | 54 |
1 files changed, 30 insertions, 24 deletions
diff --git a/gamechestcli/gamechest/runners/extract.py b/gamechestcli/gamechest/runners/extract.py index 194cba0..970c956 100644 --- a/gamechestcli/gamechest/runners/extract.py +++ b/gamechestcli/gamechest/runners/extract.py @@ -30,30 +30,36 @@ class ExtractZip(RunnerBase): self.progress = 0 def extract_and_report(): - chunk_size = 1024**2 # 1MiB chunks - with zipfile.ZipFile(src, 'r') as zip_ref: - self.total_bytes = sum(getattr(file_info, 'file_size', 0) for file_info in zip_ref.infolist() if not file_info.is_dir()) - for file_info in zip_ref.infolist(): - if file_info.is_dir(): - continue - with zip_ref.open(file_info) as source_file: - target_path = os.path.join(dst, file_info.filename) - os.makedirs(os.path.dirname(target_path), exist_ok=True) - with open(target_path, 'wb') as target_file: - while not self.cancel_event.is_set(): - chunk = source_file.read(chunk_size) - if not chunk or self.cancel_event.is_set(): - # if we have read everything from the - # source file, OR, we got a cancel event - # in-between the read and the write, we - # break. - break - target_file.write(chunk) - self.written_bytes += len(chunk) - self.progress = (self.written_bytes / self.total_bytes) * 100 - #progress_message = f"Progress: {progress:.2f}% ({bytes_written} of {total_bytes} bytes)\n" - os.write(self.write_fd, b'.') - self.cancel_event.set() + try: + chunk_size = 1024**2 # 1MiB chunks + with zipfile.ZipFile(src, 'r') as zip_ref: + self.total_bytes = sum(getattr(file_info, 'file_size', 0) for file_info in zip_ref.infolist() if not file_info.is_dir()) + for file_info in zip_ref.infolist(): + if file_info.is_dir(): + continue + with zip_ref.open(file_info) as source_file: + target_path = os.path.join(dst, file_info.filename) + os.makedirs(os.path.dirname(target_path), exist_ok=True) + with open(target_path, 'wb') as target_file: + while not self.cancel_event.is_set(): + chunk = source_file.read(chunk_size) + if not chunk or self.cancel_event.is_set(): + # if we have read everything from the + # source file, OR, we got a cancel event + # in-between the read and the write, we + # break. + break + target_file.write(chunk) + self.written_bytes += len(chunk) + self.progress = (self.written_bytes / self.total_bytes) * 100 + #progress_message = f"Progress: {progress:.2f}% ({bytes_written} of {total_bytes} bytes)\n" + os.write(self.write_fd, b'.') + finally: + self.cancel_event.set() + self.progress = 100 + os.write(self.write_fd, b'.') + #os.close(self.read_fd) + #os.close(self.write_fd) # Create a thread for extraction extraction_thread = threading.Thread(target=extract_and_report) |