From ff66a97770b2221acc2371ab1c57ad4697d6d571 Mon Sep 17 00:00:00 2001 From: Ludovic <54670129+lbr38@users.noreply.github.com> Date: Thu, 18 Jul 2024 11:09:37 +0200 Subject: [PATCH] patch --- src/controllers/Package/Apt.py | 10 +---- src/controllers/Package/Dnf.py | 77 +++++++++++++++++++++++----------- 2 files changed, 53 insertions(+), 34 deletions(-) diff --git a/src/controllers/Package/Apt.py b/src/controllers/Package/Apt.py index 9cd4e63..ddf3b39 100644 --- a/src/controllers/Package/Apt.py +++ b/src/controllers/Package/Apt.py @@ -235,17 +235,9 @@ def update(self, packagesList, update_method: str = 'one_by_one', exit_on_packag # If command succeeded, increment the success counter self.summary['update']['success']['count'] += 1 + # TODO : à tester # If update_method is 'global', update all packages at once (one command) if update_method == 'global': - packages = [] - - for pkg in packagesList: - if not pkg['excluded']: - packages.append(pkg['name']) - - # Convert the list of packages to a string - packages = ' '.join(packages) - # If --keep-oldconf is True, then keep the old configuration file if self.keep_oldconf: cmd = ['apt', 'upgrade', '-y', '-o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold"'] diff --git a/src/controllers/Package/Dnf.py b/src/controllers/Package/Dnf.py index fd6fb9d..ff58035 100644 --- a/src/controllers/Package/Dnf.py +++ b/src/controllers/Package/Dnf.py @@ -240,16 +240,59 @@ def remove_all_exclusions(self): # #------------------------------------------------------------------------------------------------------------------- def update(self, packagesList, update_method: str = 'one_by_one', exit_on_package_update_error: bool = True): - # Loop through the list of packages to update - for pkg in packagesList: - # If the package is excluded, ignore it - if pkg['excluded']: - continue + # If update_method is 'one_by_one', update packages one by one (one command per package) + if update_method == 'one_by_one': + # Loop through the list of packages to update + for pkg in packagesList: + # If the package is excluded, ignore it + if pkg['excluded']: + continue + + print('\n ▪ Updating ' + Fore.GREEN + pkg['name'] + Style.RESET_ALL + ' (' + pkg['current_version'] + ' → ' + pkg['available_version'] + '):') + + # Define the command to update the package + cmd = ['dnf', 'update', pkg['name'], '-y'] + + popen = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1, universal_newlines=True) + + # Print lines as they are read + for line in popen.stdout: + line = line.replace('\r', '') + print(' | ' + line, end='') + + # Wait for the command to finish + popen.wait() + + # If command failed, either raise an exception or print a warning + if popen.returncode != 0: + + self.summary['update']['failed']['count'] += 1 + + # Print error message for the package + print(' ▪ Error while updating ' + Fore.RED + pkg['name'] + Style.RESET_ALL) + + # If error is critical, raise an exception to quit + if (exit_on_package_update_error == True): + raise Exception('error while updating ' + pkg['name']) - print('\n ▪ Updating ' + Fore.GREEN + pkg['name'] + Style.RESET_ALL + ' (' + pkg['current_version'] + ' → ' + pkg['available_version'] + '):') + # Else continue to the next package + else: + continue - # Define the command to update the package - cmd = ['dnf', 'update', pkg['name'], '-y'] + # Close the pipe + popen.stdout.close() + + # If command succeeded, increment the success counter + self.summary['update']['success']['count'] += 1 + + # Print success message for the package + print(' ▪ ' + Fore.GREEN + pkg['name'] + Style.RESET_ALL + ' updated successfully') + + # TODO : à tester + # If update_method is 'global', update all packages at once (one command) + if update_method == 'global': + # Define the command to update all packages + cmd = ['dnf', 'update', '-y'] popen = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1, universal_newlines=True) @@ -263,29 +306,13 @@ def update(self, packagesList, update_method: str = 'one_by_one', exit_on_packag # If command failed, either raise an exception or print a warning if popen.returncode != 0: - - self.summary['update']['failed']['count'] += 1 - - # Print error message for the package - print(' ▪ Error while updating ' + Fore.RED + pkg['name'] + Style.RESET_ALL) - # If error is critical, raise an exception to quit if (exit_on_package_update_error == True): - raise Exception('error while updating ' + pkg['name']) - - # Else continue to the next package - else: - continue + raise Exception('error while updating packages') # Close the pipe popen.stdout.close() - # If command succeeded, increment the success counter - self.summary['update']['success']['count'] += 1 - - # Print success message for the package - print(' ▪ ' + Fore.GREEN + pkg['name'] + Style.RESET_ALL + ' updated successfully') - #------------------------------------------------------------------------------------------------------------------- #