diff --git a/slpkg/downloader.py b/slpkg/downloader.py index a90c98a2..31445b3f 100644 --- a/slpkg/downloader.py +++ b/slpkg/downloader.py @@ -29,22 +29,23 @@ class Downloader: self.byellow = f'{self.bold}{self.yellow}' self.bred = f'{self.bold}{self.red}' self.progress = ProgressBar() + self.output = 0 self.stderr = None self.stdout = None def wget(self): """ Wget downloader. """ - output = subprocess.call(f'wget {self.configs.wget_options} --directory-prefix={self.path} {self.url}', - shell=True, stderr=self.stderr, stdout=self.stdout) - if output != 0: - raise SystemExit(output) + self.output = subprocess.call(f'wget {self.configs.wget_options} --directory-prefix={self.path} {self.url}', + shell=True, stderr=self.stderr, stdout=self.stdout) + if self.output != 0: + raise SystemExit(self.output) def check_if_downloaded(self): """ Checks if the file downloaded. """ file = self.url.split('/')[-1] path_file = Path(self.path, file) if not path_file.exists(): - raise SystemExit(f"\n{self.red}FAILED {self.stderr}:{self.endc} '{self.blue}{self.url}{self.endc}' " + raise SystemExit(f"\n{self.red}FAILED {self.output}:{self.endc} '{self.blue}{self.url}{self.endc}' " f"to download.\n") def download(self): @@ -68,9 +69,11 @@ class Downloader: # Terminate process 2 if process 1 finished if not p1.is_alive(): + if p1.exitcode != 0: done = f' {self.bred} Failed{self.endc}' - self.stderr = p1.exitcode + self.output = p1.exitcode + print(f'{self.endc}{done}', end='') p2.terminate() diff --git a/slpkg/remove_packages.py b/slpkg/remove_packages.py index 5f921916..d2998608 100644 --- a/slpkg/remove_packages.py +++ b/slpkg/remove_packages.py @@ -25,13 +25,16 @@ class RemovePackages: self.color = self.colors() self.bold = self.color['bold'] self.yellow = self.color['yellow'] - self.byellow = f'{self.bold}{self.yellow}' self.red = self.color['red'] self.endc = self.color['endc'] + self.byellow = f'{self.bold}{self.yellow}' + self.bred = f'{self.bold}{self.red}' self.installed_packages = [] self.dependencies = [] self.utils = Utilities() self.progress = ProgressBar() + self.output = 0 + self.remove_pkg = None self.stderr = None self.stdout = None @@ -59,6 +62,7 @@ class RemovePackages: def remove_packages(self): """ Run Slackware command to remove the packages. """ for package in self.installed_packages: + self.remove_pkg = package command = f'{self.configs.removepkg} {package}' self.multi_process(command, package) @@ -79,6 +83,7 @@ class RemovePackages: def multi_process(self, command, package): """ Starting multiprocessing remove process. """ if self.configs.view_mode == 'new': + done = f' {self.byellow} Done{self.endc}' message = f'{self.red}Remove{self.endc}' self.stderr = subprocess.DEVNULL self.stdout = subprocess.DEVNULL @@ -95,7 +100,12 @@ class RemovePackages: # Terminate process 2 if process 1 finished if not p1.is_alive(): - print(f'{self.endc}{self.byellow} Done{self.endc}', end='') + + if p1.exitcode != 0: + done = f' {self.bred} Failed{self.endc}' + self.output = p1.exitcode + + print(f'{self.endc}{done}', end='') p2.terminate() # Wait until process 2 finish @@ -106,9 +116,16 @@ class RemovePackages: else: self.process(command) + self.print_error() + def process(self, command): """ Processes execution. """ - output = subprocess.call(command, shell=True, - stderr=self.stderr, stdout=self.stdout) - if output > 0: - raise SystemExit(output) + self.output = subprocess.call(command, shell=True, + stderr=self.stderr, stdout=self.stdout) + if self.output != 0: + raise SystemExit(self.output) + + def print_error(self): + """ Stop the process and print the error message. """ + if self.output != 0: + raise SystemExit(f"\n{self.red}FAILED {self.stderr}:{self.endc} package '{self.remove_pkg}' to remove.\n") diff --git a/slpkg/slackbuild.py b/slpkg/slackbuild.py index d92180ac..7c64240d 100644 --- a/slpkg/slackbuild.py +++ b/slpkg/slackbuild.py @@ -41,12 +41,15 @@ class Slackbuilds: self.cyan = self.color['cyan'] self.red = self.color['red'] self.yellow = self.color['yellow'] - self.byellow = f'{self.bold}{self.yellow}' self.endc = self.color['endc'] + self.byellow = f'{self.bold}{self.yellow}' + self.bred = f'{self.bold}{self.red}' self.install_order = [] self.dependencies = [] self.sbos = {} self.progress = ProgressBar() + self.process_message = None + self.output = 0 self.stderr = None self.stdout = None @@ -231,9 +234,14 @@ class Slackbuilds: execute = self.configs.reinstall message = f'{self.cyan}Installing{self.endc}' + self.process_message = f"'{pkg}' to install" + if self.mode == 'upgrade': + self.process_message = f"package '{pkg}' to upgrade" message = f'{self.cyan}Upgrade{self.endc}' + command = f'{execute} {self.configs.tmp_path}/{package}' + self.multi_process(command, package, message) def creating_package_for_install(self, name: str): @@ -264,6 +272,8 @@ class Slackbuilds: self.set_makeflags() message = f'{self.red}Build{self.endc}' + self.process_message = f"package '{name}' to build" + self.multi_process(execute, name, message) @staticmethod @@ -286,6 +296,7 @@ class Slackbuilds: def multi_process(self, command, filename, message): """ Starting multiprocessing install/upgrade process. """ if self.configs.view_mode == 'new': + done = f' {self.byellow} Done{self.endc}' self.stderr = subprocess.DEVNULL self.stdout = subprocess.DEVNULL @@ -301,7 +312,12 @@ class Slackbuilds: # Terminate process 2 if process 1 finished if not p1.is_alive(): - print(f'{self.endc}{self.byellow} Done{self.endc}', end='') + + if p1.exitcode != 0: + done = f' {self.bred} Failed{self.endc}' + self.output = p1.exitcode + + print(f'{self.endc}{done}', end='') p2.terminate() # Wait until process 2 finish @@ -312,9 +328,16 @@ class Slackbuilds: else: self.process(command) + self.print_error() + def process(self, command): """ Processes execution. """ - output = subprocess.call(command, shell=True, - stderr=self.stderr, stdout=self.stdout) - if output > 0: - raise SystemExit(output) + self.output = subprocess.call(command, shell=True, + stderr=self.stderr, stdout=self.stdout) + if self.output != 0: + raise SystemExit(self.output) + + def print_error(self): + """ Stop the process and print the error message. """ + if self.output != 0: + raise SystemExit(f"\n{self.red}FAILED {self.output}:{self.endc} {self.process_message}.\n")