From 152ec2e987e63951f2aa7676de10b5ee4ee0fce7 Mon Sep 17 00:00:00 2001 From: RedDeadDepresso <94017243+RedDeadDepresso@users.noreply.github.com> Date: Thu, 26 Sep 2024 01:42:28 +0100 Subject: [PATCH] refactor: 7-zip subprocess --- app/view/setting_interface.py | 2 +- util/file_manager.py | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/view/setting_interface.py b/app/view/setting_interface.py index 50093ea..ff6b748 100644 --- a/app/view/setting_interface.py +++ b/app/view/setting_interface.py @@ -50,7 +50,7 @@ class SettingInterface(ScrollArea): self.filenameCard = LineEditSettingCard( cfg.filename, FIF.ZIP_FOLDER, - self.tr('Name for the backup zip file'), + self.tr('Name for the backup 7-zip file'), None, parent=self.backupGroup ) diff --git a/util/file_manager.py b/util/file_manager.py index a52b272..7940158 100644 --- a/util/file_manager.py +++ b/util/file_manager.py @@ -127,16 +127,18 @@ class FileManager: command = f'"{path_to_7zip}" a -t7z "{archive_file}" {include_string} {exclude_string}' # Call the command - process = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) # Print the output - for line in process.stdout.decode().split('\n'): - if line.strip(): - logger.info("7-Zip", line) + while process.poll() is None: + for line in process.stdout: + if line.strip(): + logger.info("7-Zip", line) # Check the return code if process.returncode not in [0, 1]: - raise Exception() + logger.error("7-Zip", f"Exited with return code: {process.returncode}") + raise Exception(f"7-zip exited with return code: {process.returncode}") def extract_archive(self, archive_path: Union[Path, str]): from app.components.password_dialog import password_dialog