From 3bc2d30f91fe038f1483d04f2c5100bc736340ef Mon Sep 17 00:00:00 2001 From: "Abhiraj Roy (iconized)" <157954129+iconized@users.noreply.github.com> Date: Fri, 26 Apr 2024 16:32:52 +0530 Subject: [PATCH 01/10] > push changes --- blackbox/blackbox.py | 1 + 1 file changed, 1 insertion(+) diff --git a/blackbox/blackbox.py b/blackbox/blackbox.py index b0d5f86..dc4336c 100644 --- a/blackbox/blackbox.py +++ b/blackbox/blackbox.py @@ -27,6 +27,7 @@ from gi.repository import Gtk,Gdk,GdkPixbuf, Pango, GLib import Functions as fn from Settings import Settings +from requests.packages import package base_dir = os.path.dirname(os.path.realpath(__file__)) From bb7fe420c5c4990d3766cb0c0f5d89da2855aba9 Mon Sep 17 00:00:00 2001 From: "Abhiraj Roy (iconized)" <157954129+iconized@users.noreply.github.com> Date: Fri, 26 Apr 2024 16:33:16 +0530 Subject: [PATCH 02/10] add signal/ --- blackbox/blackbox.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/blackbox/blackbox.py b/blackbox/blackbox.py index dc4336c..3249aef 100644 --- a/blackbox/blackbox.py +++ b/blackbox/blackbox.py @@ -7,6 +7,8 @@ from queue import Queue import sys import time from time import sleep +import signal + # UI modules from ui.GUI import GUI from ui.SplashScreen import SplashScreen From 1a3eb8667811ce7217fb1f4d71c2966f39f68b75 Mon Sep 17 00:00:00 2001 From: "Abhiraj Roy (iconized)" <157954129+iconized@users.noreply.github.com> Date: Fri, 26 Apr 2024 16:34:59 +0530 Subject: [PATCH 03/10] complete on_search_activated() --- blackbox/blackbox.py | 72 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/blackbox/blackbox.py b/blackbox/blackbox.py index 3249aef..510dad4 100644 --- a/blackbox/blackbox.py +++ b/blackbox/blackbox.py @@ -212,4 +212,76 @@ class Main(Gtk.Window): # Basic OOPS Concept ) self.search_activated = False + if searchentry.get_text_length() == 0: + self.search_activated = False + + search_term = searchentry.get_text() + if not search_term.isspace(): + try: + if len(search_term.rstrip().lstrip()) > 0: + th_search = fn.threading.Thread( + name="thread_search", + target=fn.search, + args=( + self, + search_term.rstrip().lstrip(), + ), + ) + fn.logger.info("Starting search") + th_search.start() + # get the search_results from the queue + results = self.search_queue.get() + if results is not None: + fn.logger.info("Search complete") + if len(results) > 0: + total = 0 + for val in results.values(): + total += len(val) + fn.logger.info("Search found %s results" % total) + # make sure the gui search only displays the pkgs inside the results + GUI.setup_gui_search( + self, + Gtk, + Gdk, + GdkPixbuf, + base_dir, + os, + Pango, + results, + search_term, + None, + ) + self.search_activated = True + else: + fn.logger.info("Search found %s results" % 0) + self.searchentry.grab_focus() + message_dialog = MessageDialog( + "Info", + "Search returned 0 results", + "Failed to find search term inside the package name or description.", + "Try to search again using another term", + "info", + False, + ) + message_dialog.show_all() + message_dialog.run() + message_dialog.hide() + elif self.search_activated == True: + GUI.setup_gui( + self, + Gtk, + Gdk, + GdkPixbuf, + base_dir, + os, + Pango, + None, + ) + self.search_activated = False + except Exception as err: + fn.logger.error("Exception in on_search_activated(): %s" % err) + finally: + if self.search_activated == True: + self.search_queue.task_done() + From bb5d73fe57cddc5a7682c32bc9b9b8398b97288c Mon Sep 17 00:00:00 2001 From: "Abhiraj Roy (iconized)" <157954129+iconized@users.noreply.github.com> Date: Fri, 26 Apr 2024 16:35:29 +0530 Subject: [PATCH 04/10] add function on_search_cleared() --- blackbox/blackbox.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/blackbox/blackbox.py b/blackbox/blackbox.py index 510dad4..19be15c 100644 --- a/blackbox/blackbox.py +++ b/blackbox/blackbox.py @@ -283,5 +283,22 @@ class Main(Gtk.Window): # Basic OOPS Concept finally: if self.search_activated == True: self.search_queue.task_done() + + def on_search_cleared(self, searchentry, icon_pos, event): + if self.search_activated: + GUI.setup_gui( + self, + Gtk, + Gdk, + GdkPixbuf, + base_dir, + os, + Pango, + None, + ) + + self.searchentry.set_placeholder_text("Search...") + + self.search_activated = False From 876f56f4fae241cf000e58daff29229b72918635 Mon Sep 17 00:00:00 2001 From: "Abhiraj Roy (iconized)" <157954129+iconized@users.noreply.github.com> Date: Fri, 26 Apr 2024 16:35:55 +0530 Subject: [PATCH 05/10] bump blank lines. --- blackbox/blackbox.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/blackbox/blackbox.py b/blackbox/blackbox.py index 19be15c..8c6fbfa 100644 --- a/blackbox/blackbox.py +++ b/blackbox/blackbox.py @@ -296,9 +296,7 @@ class Main(Gtk.Window): # Basic OOPS Concept Pango, None, ) - self.searchentry.set_placeholder_text("Search...") - self.search_activated = False From be264e1fb0ffc1b750e39f29cc4aa968e24be284 Mon Sep 17 00:00:00 2001 From: "Abhiraj Roy (iconized)" <157954129+iconized@users.noreply.github.com> Date: Fri, 26 Apr 2024 16:41:41 +0530 Subject: [PATCH 06/10] add app_toggle() --- blackbox/blackbox.py | 205 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 204 insertions(+), 1 deletion(-) diff --git a/blackbox/blackbox.py b/blackbox/blackbox.py index 8c6fbfa..da70884 100644 --- a/blackbox/blackbox.py +++ b/blackbox/blackbox.py @@ -299,4 +299,207 @@ class Main(Gtk.Window): # Basic OOPS Concept self.searchentry.set_placeholder_text("Search...") self.search_activated = False - + def on_close(self, widget, data): + settings = Settings(self.display_versions, self.display_package_progress) + settings.write_config_file() + if os.path.exists(fn.blackbox_lockfile): + os.unlink(fn.blackbox_lockfile) + if os.path.exists(fn.blackbox_pidfile): + os.unlink(fn.blackbox_pidfile) + fn.terminate_pacman() + Gtk.main_quit() + print("") + print("Thanks for using BlackBox") + print("Report issues to make it even better") + print("") + print("") + print("") + + def app_toggle(self, widget, active, package): + if widget.get_state() == False and widget.get_active() == True: + if len(package.name) > 0: + inst_str = [ + "pacman", + "-S", + package.name, + "--needed", + "--noconfirm", + ] + if self.display_package_progress is True: + if fn.check_pacman_lockfile(): + widget.set_state(False) + widget.set_active(False) + proc = fn.get_pacman_process() + message_dialog = MessageDialog( + "Warning", + "Blackbox cannot proceed pacman lockfile found", + "Pacman cannot lock the db, a lockfile is found inside %s" + % fn.pacman_lockfile, + "Pacman is running: %s" % proc, + "warning", + False, + ) + message_dialog.show_all() + message_dialog.run() + message_dialog.hide() + return True + else: + package_metadata = fn.get_package_information(package.name) + if ( + type(package_metadata) is str + and package_metadata.strip() + == "error: package '%s' was not found" % package.name + ): + self.package_found = False + fn.logger.warning( + "The package %s was not found in any configured Pacman repositories" + % package.name + ) + fn.logger.warning("Package install cannot continue") + message_dialog = MessageDialog( + "Error", + "Pacman repository error: package '%s' was not found" + % package.name, + "Blackbox cannot process the request", + "Are the correct pacman mirrorlists configured ?", + "error", + False, + ) + message_dialog.show_all() + message_dialog.run() + message_dialog.hide() + widget.set_state(False) + widget.set_active(False) + return True + else: + widget.set_state(True) + widget.set_active(True) + progress_dialog = ProgressDialog( + "install", + package, + " ".join(inst_str), + package_metadata, + ) + progress_dialog.show_all() + self.pkg_queue.put( + ( + package, + "install", + widget, + inst_str, + progress_dialog, + ), + ) + th = fn.threading.Thread( + name="thread_pkginst", + target=fn.install, + args=(self,), + daemon=True, + ) + th.start() + fn.logger.debug("Package-install thread started") + else: + progress_dialog = None + widget.set_sensitive(False) + widget.set_active(True) + widget.set_state(True) + fn.logger.info("Package to install : %s" % package.name) + # another pacman transaction is running, add items to the holding queue + if ( + fn.check_pacman_lockfile() is True + and self.display_package_progress is False + ): + self.pkg_holding_queue.put( + ( + package, + "install", + widget, + inst_str, + progress_dialog, + ), + ) + if fn.is_thread_alive("thread_check_holding_queue") is False: + th = fn.threading.Thread( + target=fn.check_holding_queue, + name="thread_check_holding_queue", + daemon=True, + args=(self,), + ) + th.start() + fn.logger.debug("Check-holding-queue thread started") + elif self.display_package_progress is False: + self.pkg_queue.put( + ( + package, + "install", + widget, + inst_str, + progress_dialog, + ), + ) + th = fn.threading.Thread( + name="thread_pkginst", + target=fn.install, + args=(self,), + daemon=True, + ) + th.start() + fn.logger.debug("Package-install thread started") + # switch widget is currently toggled on + if widget.get_state() == True and widget.get_active() == False: + # Uninstall the package + if len(package.name) > 0: + uninst_str = ["pacman", "-Rs", package.name, "--noconfirm"] + fn.logger.info("Package to remove : %s" % package.name) + if fn.check_pacman_lockfile(): + widget.set_state(True) + widget.set_active(True) + fn.logger.info("Pacman lockfile found, uninstall aborted") + GLib.idle_add( + self.show_lockfile_message_dialog, + priority=GLib.PRIORITY_DEFAULT, + ) + return True + if self.display_package_progress is True: + package_metadata = fn.get_package_information(package.name) + + progress_dialog = ProgressDialog( + "uninstall", + package, + " ".join(uninst_str), + package_metadata, + ) + progress_dialog.show_all() + else: + progress_dialog = None + widget.set_active(False) + widget.set_state(False) + self.pkg_queue.put( + ( + package, + "uninstall", + widget, + uninst_str, + progress_dialog, + ), + ) + th = fn.threading.Thread( + name="thread_pkgrem", + target=fn.uninstall, + args=(self,), + daemon=True, + ) + th.start() + fn.logger.debug("Package-uninstall thread started") + + # fn.print_running_threads() + + # return True to prevent the default handler from running + return True + + # App_Frame_GUI.GUI(self, Gtk, vboxStack1, fn, category, package_file) + # widget.get_parent().get_parent().get_parent().get_parent().get_parent().get_parent().get_parent().queue_redraw() + # self.gui.hide() + # self.gui.queue_redraw() + # self.gui.show_all() + \ No newline at end of file From 03a2abf7dc63229a1d8ffe2ea9900509462e6cee Mon Sep 17 00:00:00 2001 From: "Abhiraj Roy (iconized)" <157954129+iconized@users.noreply.github.com> Date: Fri, 26 Apr 2024 16:42:16 +0530 Subject: [PATCH 07/10] add show_lockfile_message_dialog() --- blackbox/blackbox.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/blackbox/blackbox.py b/blackbox/blackbox.py index da70884..afdc5f3 100644 --- a/blackbox/blackbox.py +++ b/blackbox/blackbox.py @@ -502,4 +502,19 @@ class Main(Gtk.Window): # Basic OOPS Concept # self.gui.hide() # self.gui.queue_redraw() # self.gui.show_all() - \ No newline at end of file + + def show_lockfile_message_dialog(self): + proc = fn.get_pacman_process() + message_dialog = MessageDialog( + "Warning", + "Blackbox cannot proceed pacman lockfile found", + "Pacman cannot lock the db, a lockfile is found inside %s" + % fn.pacman_lockfile, + "Process running = %s" % proc, + "warning", + False, + ) + message_dialog.show_all() + message_dialog.run() + message_dialog.hide() + message_dialog.destroy() \ No newline at end of file From d08b08a82d6f4255e52a3d3cef9dc98af4b27904 Mon Sep 17 00:00:00 2001 From: "Abhiraj Roy (iconized)" <157954129+iconized@users.noreply.github.com> Date: Fri, 26 Apr 2024 16:44:14 +0530 Subject: [PATCH 08/10] add on_packages_import_clicked() --- blackbox/blackbox.py | 107 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 106 insertions(+), 1 deletion(-) diff --git a/blackbox/blackbox.py b/blackbox/blackbox.py index afdc5f3..9e62659 100644 --- a/blackbox/blackbox.py +++ b/blackbox/blackbox.py @@ -517,4 +517,109 @@ class Main(Gtk.Window): # Basic OOPS Concept message_dialog.show_all() message_dialog.run() message_dialog.hide() - message_dialog.destroy() \ No newline at end of file + message_dialog.destroy() + + def recache_clicked(self, widget): + fn.logger.info("Recache applications - start") + fn.cache_btn() + + def on_package_search_clicked(self, widget): + fn.logger.debug("Showing Package Search window") + self.toggle_popover() + package_search_win = PackageSearchWindow() + package_search_win.show_all() + + # def on_arcolinux_iso_packages_clicked(self, widget): + # fn.logger.debug("Showing ArcoLinux ISO Packages window") + # arcolinux_iso_packages_window = ISOPackagesWindow() + # arcolinux_iso_packages_window.show() + + def on_about_app_clicked(self, widget): + fn.logger.debug("Showing About dialog") + self.toggle_popover() + about = AboutDialog() + about.run() + about.hide() + about.destroy() + + def on_packages_export_clicked(self, widget): + self.toggle_popover() + dialog_packagelist = PackageListDialog() + dialog_packagelist.show_all() + + def on_packages_import_clicked(self, widget): + self.toggle_popover() + try: + if not os.path.exists(fn.pacman_lockfile): + package_file = "%s/packages-x86_64.txt" % (fn.export_dir,) + package_import_logfile = "%spackages-install-status-%s-%s.log" % ( + fn.log_dir, + fn.datetime.today().date(), + fn.datetime.today().time().strftime("%H-%M-%S"), + ) + if os.path.exists(package_file): + # check we have a valid file + lines = None + with open(package_file, encoding="utf-8", mode="r") as f: + lines = f.readlines() + if lines is not None: + if ( + "# This file was auto-generated by the ArchLinux Tweak Tool on" + in lines[0] + or "# This file was auto-generated by Blackbox on" + in lines[0] + ): + fn.logger.info("Package list file is valid") + packages_list = [] + for line in lines: + if not line.startswith("#"): + packages_list.append(line.strip()) + + if len(packages_list) > 0: + dialog_package_import = PackagesImportDialog( + package_file, + packages_list, + package_import_logfile, + ) + dialog_package_import.show_all() + + else: + message_dialog = MessageDialog( + "Error", + "Package file is not valid %s" % package_file, + "Export a list of packages first using the Show Installed Packages button", + "", + "error", + False, + ) + + message_dialog.show_all() + message_dialog.run() + message_dialog.hide() + else: + message_dialog = MessageDialog( + "Warning", + "Cannot locate export package file %s" % package_file, + "Export a list of packages first using the Show Installed Packages button", + "", + "warning", + False, + ) + + message_dialog.show_all() + message_dialog.run() + message_dialog.hide() + else: + message_dialog = MessageDialog( + "Error", + "Pacman lock file found %s" % fn.pacman_lockfile, + "Cannot proceed, another pacman process is running", + "", + "error", + False, + ) + message_dialog.show_all() + message_dialog.run() + message_dialog.hide() + except Exception as e: + fn.logger.error("Exception in on_packages_import_clicked(): %s" % e) \ No newline at end of file From 820d67d42da2dc3ee1fa834abc6e4eeea94374e5 Mon Sep 17 00:00:00 2001 From: "Abhiraj Roy (iconized)" <157954129+iconized@users.noreply.github.com> Date: Fri, 26 Apr 2024 16:46:08 +0530 Subject: [PATCH 09/10] add kering_toggle() --- blackbox/blackbox.py | 59 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/blackbox/blackbox.py b/blackbox/blackbox.py index 9e62659..44ed09c 100644 --- a/blackbox/blackbox.py +++ b/blackbox/blackbox.py @@ -622,4 +622,61 @@ class Main(Gtk.Window): # Basic OOPS Concept message_dialog.run() message_dialog.hide() except Exception as e: - fn.logger.error("Exception in on_packages_import_clicked(): %s" % e) \ No newline at end of file + fn.logger.error("Exception in on_packages_import_clicked(): %s" % e) + + def toggle_popover(self): + if self.popover.get_visible(): + self.popover.hide() + else: + self.popover.show_all() + + def on_settings_clicked(self, widget): + self.toggle_popover() + + def snigdhaos_keyring_toggle(self, widget, data): + # toggle is currently off, add keyring + if widget.get_state() == False and widget.get_active() == True: + fn.logger.info("Installing Snigdha OS keyring") + install_keyring = fn.install_arco_keyring() + + if install_keyring == 0: + fn.logger.info("Installation of Snigdha OS keyring = OK") + rc = fn.add_arco_repos() + if rc == 0: + fn.logger.info("Snigdha OS repos added into %s" % fn.pacman_conf) + widget.set_active(True) + else: + message_dialog = MessageDialog( + "Error", + "Failed to update pacman conf", + "Errors occurred during update of the pacman config file", + rc, + "error", + True, + ) + message_dialog.show_all() + message_dialog.run() + message_dialog.hide() + widget.set_active(False) + widget.set_state(False) + return True + + else: + message_dialog = MessageDialog( + "Error", + "Failed to install Snigdha OS keyring", + "Errors occurred during install of the Snigdha OS keyring", + "Command run = %s\n\n Error = %s" + % (install_keyring["cmd_str"], install_keyring["output"]), + "error", + True, + ) + message_dialog.show_all() + message_dialog.run() + message_dialog.hide() + widget.set_active(False) + widget.set_state(False) + return True + # toggle is currently on + + \ No newline at end of file From 33025a90285ae84bbe2d224742f70ce472c507ee Mon Sep 17 00:00:00 2001 From: "Abhiraj Roy (iconized)" <157954129+iconized@users.noreply.github.com> Date: Fri, 26 Apr 2024 16:48:37 +0530 Subject: [PATCH 10/10] update snigdhaos_keyring_toggle() --- blackbox/blackbox.py | 50 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/blackbox/blackbox.py b/blackbox/blackbox.py index 44ed09c..8518206 100644 --- a/blackbox/blackbox.py +++ b/blackbox/blackbox.py @@ -637,11 +637,11 @@ class Main(Gtk.Window): # Basic OOPS Concept # toggle is currently off, add keyring if widget.get_state() == False and widget.get_active() == True: fn.logger.info("Installing Snigdha OS keyring") - install_keyring = fn.install_arco_keyring() + install_keyring = fn.install_snigdhaos_keyring() if install_keyring == 0: fn.logger.info("Installation of Snigdha OS keyring = OK") - rc = fn.add_arco_repos() + rc = fn.add_snigdhaos_repos() if rc == 0: fn.logger.info("Snigdha OS repos added into %s" % fn.pacman_conf) widget.set_active(True) @@ -678,5 +678,47 @@ class Main(Gtk.Window): # Basic OOPS Concept widget.set_state(False) return True # toggle is currently on - - \ No newline at end of file + if widget.get_state() == True and widget.get_active() == False: + remove_keyring = fn.remove_snigdhaos_keyring() + + if remove_keyring == 0: + fn.logger.info("Removing Snigdha OS keyring OK") + + rc = fn.remove_snigdhaos_repos() + if rc == 0: + fn.logger.info("Snigdha OS repos removed from %s" % fn.pacman_conf) + widget.set_active(False) + else: + message_dialog = MessageDialog( + "Error", + "Failed to update pacman conf", + "Errors occurred during update of the pacman config file", + rc, + "error", + True, + ) + + message_dialog.show_all() + message_dialog.run() + message_dialog.hide() + widget.set_active(True) + widget.set_state(True) + return True + else: + fn.logger.error("Failed to remove Snigdha OS keyring") + message_dialog = MessageDialog( + "Error", + "Failed to remove Snigdha OS keyring", + "Errors occurred during removal of the Snigdha OS keyring", + "Command run = %s\n\n Error = %s" + % (remove_keyring["cmd_str"], remove_keyring["output"]), + "error", + True, + ) + message_dialog.show_all() + message_dialog.run() + message_dialog.hide() + widget.set_active(False) + widget.set_state(False) + return True +