From fa34cd043e301ae72a8c0d700a593e273f6fe83a Mon Sep 17 00:00:00 2001 From: Pardus Date: Mon, 15 Apr 2024 16:02:40 +0300 Subject: [PATCH] feat: downgrade, upgrade --- src/MainWindow.py | 61 +++++++++++++++++++++++++---------------------- src/nvidia.py | 36 ++++++++++++++++++---------- src/package.py | 38 ++++++++++++++++++++--------- ui/ui.glade | 53 ++++++++++------------------------------ 4 files changed, 96 insertions(+), 92 deletions(-) diff --git a/src/MainWindow.py b/src/MainWindow.py index 4bc5218..8d33390 100644 --- a/src/MainWindow.py +++ b/src/MainWindow.py @@ -1,7 +1,7 @@ import gi import os import apt - +import signal import nvidia import std_opr import locale @@ -45,10 +45,13 @@ def __init__(self, application): except GObject.GError: print("Error while creating user interface from glade file") return False - + self.application = application self.driver_buttons = [] self.active_driver = "" self.toggled_driver = "" + self.drv_arr = [] + self.initial_gpu_driver = "" + self.initial_sec_gpu_state = False self.state = nvidia.source() self.ui_gpu_info_box = self.get_ui("ui_gpu_info_box") self.ui_gpu_box = self.get_ui("ui_gpu_box") @@ -62,6 +65,7 @@ def __init__(self, application): self.ui_enabled_gpu_box = self.get_ui("ui_enabled_gpu_box") self.ui_apply_chg_button = self.get_ui("ui_apply_chg_button") + self.ui_disable_check_button = self.get_ui("ui_disable_check_button") self.ui_status_label = self.get_ui("ui_status_label") self.ui_status_progressbar = self.get_ui("ui_status_progressbar") @@ -69,20 +73,18 @@ def __init__(self, application): self.ui_repo_switch = self.get_ui("ui_repo_switch") self.ui_repo_switch.set_state(self.state) self.ui_repo_switch.connect("state-set", self.on_nvidia_mirror_changed) - # self.ui_pardus_src_button = self.get_ui("ui_pardus_src_button") - # self.ui_pardus_src_button.connect("clicked", self.on_nvidia_mirror_changed) - # self.ui_nvidia_src_button = self.get_ui("ui_nvidia_src_button") - # self.ui_nvidia_src_button.connect("clicked", self.on_nvidia_mirror_changed) + self.ui_about_dialog = self.get_ui("ui_about_dialog") self.ui_about_button = self.get_ui("ui_about_button") - self.ui_downgrade_dialog = self.get_ui("ui_downgrade_dialog") - self.ui_upgrade_dialog = self.get_ui("ui_upgrade_dialog") + + self.ui_info_dialog = self.get_ui("ui_info_dialog") + self.ui_about_button.connect("clicked", self.on_about_button_clicked) self.nvidia_devices = nvidia.graphics() self.ui_controller_box = self.get_ui("ui_controller_box") self.ui_secondary_gpu_box = self.get_ui("ui_secondary_gpu_box") - self.ui_disable_check_button = self.get_ui("ui_disable_check_button") + self.ui_main_stack = self.get_ui("ui_main_stack") self.ui_nvidia_box = self.get_ui("ui_nvidia_box") self.ui_novidia_box = self.get_ui("ui_novidia_box") @@ -91,21 +93,23 @@ def __init__(self, application): ) self.ui_enable_button = self.get_ui("ui_enable_button") self.ui_enable_button.connect("clicked", self.on_enable_button_clicked) - self.initial_sec_gpu_state = False - self.initial_gpu_driver = "" + self.check_secondary_gpu() - self.drv_arr = [] self.apt_opr = "" self.create_gpu_drivers() self.ui_main_window.set_application(application) self.ui_main_window.set_title(_("Pardus Nvidia Installer")) - + self.user_disclaimer() self.ui_main_window.show_all() - # self.ui_nvidia_src_button.set_sensitive(not state) - # self.ui_pardus_src_button.set_sensitive(state) + def user_disclaimer(self): + response = self.ui_info_dialog.run() + if response != Gtk.ResponseType.OK: + self.application.quit() + else: + self.ui_info_dialog.close() def check_secondary_gpu(self): self.initial_sec_gpu_state = package.check_sec_state() @@ -131,7 +135,8 @@ def create_gpu_drivers(self): self.nvidia_drivers = nvidia.drivers() self.filtered_nvidia_drivers = [] - for index,nvidia_driver in enumerate(self.nvidia_drivers): + for index, nvidia_driver in enumerate(self.nvidia_drivers): + print(nvidia_driver) if index == 0: self.filtered_nvidia_drivers.append(nvidia_driver) else: @@ -140,9 +145,8 @@ def create_gpu_drivers(self): self.filtered_nvidia_drivers.append(nvidia_driver) else: self.filtered_nvidia_drivers.append(nvidia_driver) - - self.nvidia_drivers = self.filtered_nvidia_drivers + self.nvidia_drivers = self.filtered_nvidia_drivers for index, nvidia_driver in enumerate(self.nvidia_drivers): toggle = self.driver_box( @@ -152,17 +156,15 @@ def create_gpu_drivers(self): nvidia_driver.repo, ) - drv_state = nvidia.is_pkg_installed( - nvidia_driver.package, nvidia_driver.version - ) - if drv_state: + if nvidia_driver.installed: self.initial_gpu_driver = nvidia_driver self.toggled_driver = nvidia_driver self.ui_apply_chg_button.set_sensitive(True) - toggle.set_active(drv_state) + toggle.set_active(nvidia_driver.installed) toggle.connect("toggled", self.on_drv_toggled, nvidia_driver) self.drv_arr.append(toggle) self.ui_gpu_box.pack_start(toggle, True, True, 5) + self.ui_apply_chg_button.set_sensitive(self.check_initials()) def get_ui(self, object_name: str): return self.gtk_builder.get_object(object_name) @@ -222,9 +224,7 @@ def lbl_markup(self, label, desc, color=None): def on_drv_toggled(self, radio_button, driver): if radio_button.get_active(): self.toggled_driver = driver - - - # self.ui_apply_chg_button.set_sensitive(self.check_initials()) + self.ui_apply_chg_button.set_sensitive(self.check_initials()) def on_enable_button_clicked(self, button): params = ["/usr/bin/pkexec", cur_path + pkg_file, "enable-sec-gpu"] @@ -237,9 +237,14 @@ def on_apply_button_clicked(self, button): dlg_res = None if self.initial_sec_gpu_state == self.ui_disable_check_button.get_active(): self.apt_opr = "disable-sec-gpu" + params.append(self.apt_opr) + std_opr.start_prc(self, params) + + else: + self.apt_opr = "install" + params += [self.apt_opr, self.toggled_driver.package] + std_opr.start_prc(self, params) - #if len(params) != 2: - # std_opr.start_prc(self, params) # self.ui_apply_chg_button.set_sensitive(False) def on_about_button_clicked(self, button): diff --git a/src/nvidia.py b/src/nvidia.py index c340fb2..93b0111 100644 --- a/src/nvidia.py +++ b/src/nvidia.py @@ -6,6 +6,7 @@ import locale import apt_pkg from locale import gettext as _ + apt_pkg.init_system() APPNAME_CODE = "pardus-nvidia-installer" TRANSLATION_PATH = "/usr/share/locale" @@ -25,11 +26,15 @@ class NvidiaDriver: - def __init__(self, package, version, type, repo): + def __init__(self, package, version, type, repo, installed=False): self.package = package self.version = version self.type = type self.repo = repo + self.installed = installed + + def __str__(self) -> str: + return f"package:{self.package}, version:{self.version}, type:{self.type}, repo:{self.repo}, installed:{self.installed}" class NvidiaDevice: @@ -127,6 +132,7 @@ def graphics(): return devices + def get_package_info(package_name): cache = apt.Cache() package = cache[package_name] @@ -139,12 +145,14 @@ def get_package_info(package_name): ver_list[orig.origin] = version.version else: if orig.origin in ver_list.keys(): - result = apt_pkg.version_compare(ver_list[orig.origin],version.version) + result = apt_pkg.version_compare( + ver_list[orig.origin], version.version + ) if result < 0: ver_list[orig.origin] = version.version print(ver_list) return ver_list - + def readfile(filepath): content = None @@ -156,10 +164,10 @@ def readfile(filepath): def is_pkg_installed(driver, version=None): cache = apt.Cache() - if version: return version in str(cache[driver].installed) - return cache[driver].is_installed + else: + return cache[driver].is_installed def drivers(): @@ -175,22 +183,26 @@ def drivers(): get_pkg_ver(nouveau), _("Open Source Driver"), get_package_origin(nouveau, get_pkg_ver(nouveau)), + is_pkg_installed(nouveau, get_pkg_ver(nouveau)), ), ) - print(drivers[0].repo) cache = apt.Cache() for gpu in gpus: for driver in parsed_nvidia_drivers: if gpu.device_id_str in parsed_nvidia_drivers[driver].keys(): driver_lists = get_package_info(driver) - for origin in driver_lists: + version = driver_lists[origin] drivers.append( - NvidiaDriver( - driver,driver_lists[origin], _("Proprietary Driver"), origin - ) - ) + NvidiaDriver( + driver, + version, + _("Proprietary Driver"), + origin, + is_pkg_installed(driver, version), + ) + ) return drivers @@ -199,9 +211,9 @@ def get_package_origin(package_name, package_version=None): cache = apt.Cache() pkg = cache[package_name] vers = pkg.versions - print(vers) if package_version and package_version in str(vers): for ver in vers: + if package_version in str(ver): for orig in ver.origins: if orig.origin: diff --git a/src/package.py b/src/package.py index 1b1580f..1f5d22c 100755 --- a/src/package.py +++ b/src/package.py @@ -6,6 +6,7 @@ import shutil import nvidia import apt_pkg + apt_pkg.init_system() os.environ["DEBIAN_FRONTEND"] = "noninteractive" nouveau = "xserver-xorg-video-nouveau" @@ -24,13 +25,13 @@ def sys_source(): return os.path.isfile(dest) -compare_version = apt_pkg.version_compare +compare_version = apt_pkg.version_compare def disable_sec_gpu(): if not os.path.isfile(nvidia_disable_gpu_path): - with open(nvidia_disable_gpu_path,"a") as f: + with open(nvidia_disable_gpu_path, "a") as f: f.write("Secondary GPU Disabled") if os.path.isfile(nvidia_modprobe_conf): @@ -38,6 +39,7 @@ def disable_sec_gpu(): if os.path.isfile(nouveau_modprobe_conf): os.rename(nouveau_modprobe_conf, nouveau_modprobed_conf) + def enable_sec_gpu(): if os.path.isfile(nvidia_disable_gpu_path): os.remove(nvidia_disable_gpu_path) @@ -46,9 +48,11 @@ def enable_sec_gpu(): if os.path.isfile(nouveau_modprobed_conf): os.rename(nouveau_modprobed_conf, nouveau_modprobe_conf) + def check_sec_state(): return not os.path.isfile(nvidia_disable_gpu_path) + def toggle_source_list(): src_state = sys_source() if src_state: @@ -69,7 +73,7 @@ def install_nvidia(nv_drv): ) subprocess.call( - ["apt","autoremove","-yq","-o","APT::Status-Fd=1"], + ["apt", "autoremove", "-yq", "-o", "APT::Status-Fd=1"], env={**os.environ}, ) @@ -85,21 +89,30 @@ def install_nouveau(): env={**os.environ}, ) + def toggle_driver(self): toggle_source_list() install_nvidia() + def update(): if os.path.isfile(dest): os.remove(dest) else: shutil.copyfile(src_list, dest) - + subprocess.call( ["apt", "update", "-yq", "-o", "APT::Status-Fd=1"], env={**os.environ} ) +def install(driver): + if driver != nouveau: + install_nvidia(driver) + else: + install_nouveau() + + def get_pkg_info(package_name: str): cache = apt.Cache() pkg = cache[package_name] @@ -116,18 +129,21 @@ def get_pkg_info(package_name: str): if __name__ == "__main__": args = sys.argv if len(args) > 1: - if args[1] == nouveau: + param1 = args[1] + if param1 == nouveau: install_nouveau() - elif args[1] == "update": + elif param1 == "update": update() - elif args[1] == "disable-sec-gpu": + elif param1 == "disable-sec-gpu": disable_sec_gpu() - elif args[1] == "enable-sec-gpu": + elif param1 == "enable-sec-gpu": enable_sec_gpu() - elif args[1] == "toggle": + elif param1 == "toggle": toggle_driver() - else: - install_nvidia(args[1]) + elif param1 == "install": + driver = args[2] + print(driver) + install(driver) else: print("no argument passed on") diff --git a/ui/ui.glade b/ui/ui.glade index 9b2533d..b9982bd 100644 --- a/ui/ui.glade +++ b/ui/ui.glade @@ -78,15 +78,23 @@ Ali Riza Keskin <aliriza.keskin@pardus.org.tr> - + False + True center dialog - question + warning ok-cancel - <span><b>Warning</b></span> + <span><b>⚠️ Important Notice: ⚠️</b></span> True - Current driver is on Nvidia repository. To select driver on Pardus repository, you need to uninstall driver and install downgraded driver. Press OK to continue. + Please be informed that the driver installation provided through this app is sourced exclusively from the Pardus and Nvidia repositories. While we strive to ensure the quality and reliability of these drivers, it is crucial to understand that we are not affiliated with Pardus or Nvidia. + +<b>Disclaimer: </b> +We want to emphasize that we do not accept responsibility for any issues or complications that may arise during or after the installation process. While every effort has been made to provide a seamless experience, unforeseen circumstances can occur. + +<b>Issue Reporting:</b> +Feel free to report any issues or concerns via our GitHub repository: [Your GitHub Address] + True False @@ -590,41 +598,4 @@ You can't use this application - - False - center - dialog - question - ok-cancel - <span><b>Warning</b></span> - True - Current driver is on Pardus repository. To select driver on Nvidia repository, you need to uninstall driver and install new driver. Press OK to continue. - - - False - vertical - 2 - - - False - end - - - - - - - - - False - False - 0 - - - - - - - -