summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvg <vgm+dev@devys.org>2025-08-06 19:21:52 +0200
committervg <vgm+dev@devys.org>2025-08-06 19:21:52 +0200
commit2151bee6432ad456a3683a5d1b493463535c6ff2 (patch)
tree66b29ab02855ce10bb269466d97bb3519e55d3b6
parent10b06142cca4256f2473bee4d341071810a28dcb (diff)
downloadgamechest-2151bee6432ad456a3683a5d1b493463535c6ff2.tar.gz
gamechest-2151bee6432ad456a3683a5d1b493463535c6ff2.tar.bz2
gamechest-2151bee6432ad456a3683a5d1b493463535c6ff2.zip
git-sync on dita
-rw-r--r--gamechestcli/gamechest/runners/extract.py11
-rw-r--r--gamechestcli/gamechest/runners/install.py2
2 files changed, 5 insertions, 8 deletions
diff --git a/gamechestcli/gamechest/runners/extract.py b/gamechestcli/gamechest/runners/extract.py
index 23c3d34..194cba0 100644
--- a/gamechestcli/gamechest/runners/extract.py
+++ b/gamechestcli/gamechest/runners/extract.py
@@ -20,7 +20,6 @@ class ExtractZip(RunnerBase):
"""
def __init__(self, src, dst):
- self.zip = zipfile.ZipFile(src, 'r')
self.last_progress = Progress()
self.read_fd, self.write_fd = os.pipe()
self.cancel_event = threading.Event()
@@ -33,8 +32,10 @@ class ExtractZip(RunnerBase):
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())
+ 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)
@@ -52,6 +53,7 @@ class ExtractZip(RunnerBase):
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()
# Create a thread for extraction
extraction_thread = threading.Thread(target=extract_and_report)
@@ -80,14 +82,11 @@ class ExtractZip(RunnerBase):
self.close() # same as self.close, can be called multiple time
def poll(self):
- return None if self.zip else 0
+ return None if not self.cancel_event.is_set() else 0
def close(self):
self.cancel_event.set()
self.extraction_thread.join()
- if self.zip:
- self.zip.close()
- self.zip = None
class ExtractTar(RunnerBase):
diff --git a/gamechestcli/gamechest/runners/install.py b/gamechestcli/gamechest/runners/install.py
index 7b2ff7c..0b37304 100644
--- a/gamechestcli/gamechest/runners/install.py
+++ b/gamechestcli/gamechest/runners/install.py
@@ -1,5 +1,4 @@
import functools
-import os
from pathlib import Path
from .download import Download
@@ -24,7 +23,6 @@ if __name__ == '__main__':
import contextlib
import selectors
import sys
- import time
print('main test')
with contextlib.ExitStack() as stack:
stack.enter_context(contextlib.suppress(KeyboardInterrupt))