From c5a1f4375a59ab82cf3f6ea5056e8af5a7c18bae Mon Sep 17 00:00:00 2001 From: wangsong Date: Wed, 24 Aug 2022 09:50:15 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BB=A3=E7=A0=81=E7=9A=84?= =?UTF-8?q?=E7=B1=BB=E7=9A=84=E5=88=9D=E5=A7=8B=E5=8C=96=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/SystemUpdater/UpdateManager.py | 81 ---------------- backend/SystemUpdater/UpdateManagerDbus.py | 1 - .../backend/InstallBackendAptdaemon.py | 2 +- backend/SystemUpdater/backend/__init__.py | 93 +++++++++++++++++-- 4 files changed, 85 insertions(+), 92 deletions(-) diff --git a/backend/SystemUpdater/UpdateManager.py b/backend/SystemUpdater/UpdateManager.py index 4909df3..00e4665 100644 --- a/backend/SystemUpdater/UpdateManager.py +++ b/backend/SystemUpdater/UpdateManager.py @@ -83,14 +83,10 @@ class UpdateManager(): self.install_mode = UpdateInstallMode(self) self.apt_p2p_config = AptP2pConfigManager() - - self.inhibit_shutdown = InhibitShutdownLock() self._reload_options_config() #加载Cache self._refresh_cache_only() - - self.update_essential = UpdateEssentialItem(self) except Exception as e: logging.error(e) traceback.print_exc() @@ -791,42 +787,6 @@ class UpdateManager(): _group_satify = False return _noSatisfyList -class UpdateEssentialItem(): - def __init__(self,parent): - self.essential_pkgs = [] - self.remove_white = [] - - self.read_path = parent.config_path + 'kylin-update-desktop-system.json' - self.update() - logging.info("Initialize Essential Packages List...") - - def update(self): - if os.path.exists(self.read_path): - with open(self.read_path,'r') as f: - try: - data = json.load(f) - self.essential_pkgs = data['install_list'] - except Exception as exc: - logging.warning(exc) - try: - self.remove_white = data['remove_white_list'] - except Exception as exc: - pass - # logging.warning(exc) - - def check_essential(self,remove_pkgs): - logging.info("Check: For remove of Essential Packages...") - for pkg in remove_pkgs: - if pkg in self.essential_pkgs: - raise UpdateBaseError(ERROR_REMOVE_ESSENTIAL_PACKAGES) - - def check_white(self,remove_pkgs): - logging.info("Check: remove pkg in White Packages...") - for pkg in remove_pkgs: - if pkg in self.remove_white: - logging.info("%s will be remove in remove pkg...",pkg) - remove_pkgs.remove(pkg) - class MakeSourceInit(): DIR_MRDIA = "/media/" MOUNT_SQUASHFS_PATH = "/media/kylin/kylin-test-upgrade/upgrade-pool/" @@ -913,47 +873,6 @@ class AptP2pConfigManager(): return self.HEADER_DSC self.p2pConfigs.setValue("apt_p2p_Khashmir","BOOTSTRAP",str(value)) - -class InhibitShutdownLock(): - - def __init__(self): - self.inhibit_lock = None - - #安装时禁止关机 进行加锁 - def lock(self, caller='Kylin System Updater'): - """ - Send a dbus signal to logind to not suspend the system, it will be - released when the return value drops out of scope - """ - try: - from gi.repository import Gio, GLib - connection = Gio.bus_get_sync(Gio.BusType.SYSTEM) - - var, fdlist = connection.call_with_unix_fd_list_sync( - 'org.freedesktop.login1', '/org/freedesktop/login1', - 'org.freedesktop.login1.Manager', 'Inhibit', - GLib.Variant('(ssss)', - ('shutdown', - caller, 'Installing Packages', - 'block')), - None, 0, -1, None, None) - self.inhibit_lock = Gio.UnixInputStream(fd=fdlist.steal_fds()[var[0]]) - logging.info("Shutdown Has been locked...") - except Exception as e: - logging.error(e) - - #解锁禁止关机 - def unlock(self): - try: - if self.inhibit_lock != None: - self.inhibit_lock.close() - self.inhibit_lock == None - logging.info("Shutdown Has been unlocked...") - else: - logging.info("Not locked and Quitting ...") - except Exception as e: - logging.error("unlock failed." + str(e)) - class SimulateTerminal(): ZH_UNMET_DEPENDENCIES = '下列软件包有未满足的依赖关系:' EN_UNMET_DEPENDENCIES = 'The following packages have unmet dependencies:' diff --git a/backend/SystemUpdater/UpdateManagerDbus.py b/backend/SystemUpdater/UpdateManagerDbus.py index 406777a..fa86282 100755 --- a/backend/SystemUpdater/UpdateManagerDbus.py +++ b/backend/SystemUpdater/UpdateManagerDbus.py @@ -138,7 +138,6 @@ class UpdateManagerDbusController(dbus.service.Object): """Request a shutdown of the daemon.""" #如果在下载就请求 取消 self.CancelDownload() - self.parent.inhibit_shutdown.unlock() logging.info("Quitting was requested") logging.debug("Quitting main loop...") mainloop.quit() diff --git a/backend/SystemUpdater/backend/InstallBackendAptdaemon.py b/backend/SystemUpdater/backend/InstallBackendAptdaemon.py index 4176310..b4b9302 100644 --- a/backend/SystemUpdater/backend/InstallBackendAptdaemon.py +++ b/backend/SystemUpdater/backend/InstallBackendAptdaemon.py @@ -102,7 +102,7 @@ class InstallBackendAptdaemon(InstallBackend): logging.info("Installtion timeout to exit Due to inactivity and Releasing the shutdown lock...") else: #超时只单独进行解锁关机 - self.window_main.inhibit_shutdown.unlock() + self.inhibit_shutdown.unlock() self._action_done(self.ACTION_INSTALL, is_cancelled=False, success=False, #FIXME: 安装超时退出 diff --git a/backend/SystemUpdater/backend/__init__.py b/backend/SystemUpdater/backend/__init__.py index 8cc71f3..0631ec4 100644 --- a/backend/SystemUpdater/backend/__init__.py +++ b/backend/SystemUpdater/backend/__init__.py @@ -71,6 +71,41 @@ class NowUpgradeMeta: self.single_pkgs = content self.upgrade_content = self.upgrade_groups + self.single_pkgs +class UpdateEssentialItem(): + def __init__(self,parent): + self.essential_pkgs = [] + self.remove_white = [] + + self.read_path = parent.window_main.config_path + 'kylin-update-desktop-system.json' + self.update() + + def update(self): + if os.path.exists(self.read_path): + with open(self.read_path,'r') as f: + try: + data = json.load(f) + self.essential_pkgs = data['install_list'] + except Exception as exc: + logging.warning(exc) + try: + self.remove_white = data['remove_white_list'] + except Exception as exc: + pass + # logging.warning(exc) + + def check_essential(self,remove_pkgs): + logging.info("Check: For remove of Essential Packages...") + for pkg in remove_pkgs: + if pkg in self.essential_pkgs: + raise UpdateBaseError(ERROR_REMOVE_ESSENTIAL_PACKAGES) + + def check_white(self,remove_pkgs): + logging.info("Check: remove pkg in White Packages...") + for pkg in remove_pkgs: + if pkg in self.remove_white: + logging.info("%s will be remove in remove pkg...",pkg) + remove_pkgs.remove(pkg) + class AptdBaseInformation: """ @@ -133,6 +168,10 @@ class InstallBackend(): self.aptd_base = AptdBaseInformation() + self.inhibit_shutdown = InhibitShutdownLock() + + self.update_essential = UpdateEssentialItem(self) + #更新的时候此对象还未生成 if self.window_main.update_list != None: self.upgrade_data = window_main.update_list.upgrade_meta @@ -165,7 +204,7 @@ class InstallBackend(): # if self.action_mode == self.MODE_INSTALL_SINGLE: # logging.warning("MODE_INSTALL_SINGLE install:%s , upgrade:%s remove:%s",str(pkgs_install),str(pkgs_upgrade),str(pkgs_remove)) - self.window_main.update_essential.check_essential(pkgs_remove) + self.update_essential.check_essential(pkgs_remove) #检查磁盘的状态 self.check_free_space(self.cache) @@ -211,7 +250,7 @@ class InstallBackend(): logging.warning("Simulation of the deletion package list:%s",str(delete_pkgs)) logging.warning("ProblemResolver of the deletion package list:%s",str(pkgs_remove)) delete_desc = [] - self.window_main.update_essential.check_white(pkgs_remove) + self.update_essential.check_white(pkgs_remove) else: pkgs_remove = delete_pkgs else: @@ -279,7 +318,7 @@ class InstallBackend(): elif self.action == self.ACTION_FIX_BROKEN: pkgs_install,pkgs_upgrade,pkgs_remove = self._get_pkgs_from_cache(self.cache) - self.window_main.update_essential.check_essential(pkgs_remove) + self.update_essential.check_essential(pkgs_remove) self.fix_broken() # 修复不完整的安装dpkg configure -a elif self.action == self.ACTION_FIX_INCOMPLETE: @@ -612,12 +651,8 @@ class InstallBackend(): #当单包升级的时候 升级本身时,让程序退出,再重新启动 if self.window_main.GROUPS_PKG_NAME in self.now_upgrade.upgrade_content: - #只有安装配置文件包 才会走到此处 - self.window_main.update_essential.update() self.window_main.start_available() else: - #只有安装配置文件包 才会走到此处 - self.window_main.update_essential.update() self.window_main.start_available() else: self.window_main.dbusController.UpdateDetectFinished(False,[''],get_error_string_from_enum(ERROR_UPDATE_DEFAULT_FAILED),\ @@ -805,11 +840,11 @@ class InstallBackend(): def _start_install_lock(self, caller='Kylin System Updater'): self.window_main.configs_uncover.setValue("SystemStatus","abnormal_reboot",str(True)) - self.window_main.inhibit_shutdown.lock(caller=caller) + self.inhibit_shutdown.lock(caller=caller) def _release_install_lock(self): self.window_main.configs_uncover.setValue("SystemStatus","abnormal_reboot",str(False)) - self.window_main.inhibit_shutdown.unlock() + self.inhibit_shutdown.unlock() def _message_to_plymouth(self,message): subprocess.call(["/bin/plymouth", "message", "--text", message]) @@ -1025,3 +1060,43 @@ def get_backend(*args, **kwargs): # nothing found, raise raise Exception("No working backend found, please try installing " "aptdaemon or synaptic") + +class InhibitShutdownLock(): + + def __init__(self): + self.inhibit_lock = None + + #安装时禁止关机 进行加锁 + def lock(self, caller='Kylin System Updater'): + """ + Send a dbus signal to logind to not suspend the system, it will be + released when the return value drops out of scope + """ + try: + from gi.repository import Gio, GLib + connection = Gio.bus_get_sync(Gio.BusType.SYSTEM) + + var, fdlist = connection.call_with_unix_fd_list_sync( + 'org.freedesktop.login1', '/org/freedesktop/login1', + 'org.freedesktop.login1.Manager', 'Inhibit', + GLib.Variant('(ssss)', + ('shutdown', + caller, 'Installing Packages', + 'block')), + None, 0, -1, None, None) + self.inhibit_lock = Gio.UnixInputStream(fd=fdlist.steal_fds()[var[0]]) + logging.info("Shutdown Has been locked...") + except Exception as e: + logging.error(e) + + #解锁禁止关机 + def unlock(self): + try: + if self.inhibit_lock != None: + self.inhibit_lock.close() + self.inhibit_lock == None + logging.info("Shutdown Has been unlocked...") + else: + logging.info("Not locked and Quitting ...") + except Exception as e: + logging.error("unlock failed." + str(e)) \ No newline at end of file