From 2239bd86edaefe245e8a3f58214dc65e0bd7ab09 Mon Sep 17 00:00:00 2001 From: luoxueyi Date: Fri, 5 Nov 2021 11:06:05 +0800 Subject: [PATCH] =?UTF-8?q?local=E8=B7=AF=E5=BE=84=E4=B8=8B=E6=9F=A5?= =?UTF-8?q?=E6=89=BE=E4=BE=9D=E8=B5=96=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/SystemUpdater/UpdateManager.py | 42 ++++++++++++++++++++-- backend/SystemUpdater/UpdateManagerDbus.py | 5 +-- backend/SystemUpdater/backend/__init__.py | 3 +- 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/backend/SystemUpdater/UpdateManager.py b/backend/SystemUpdater/UpdateManager.py index dd451e5..3b3e416 100644 --- a/backend/SystemUpdater/UpdateManager.py +++ b/backend/SystemUpdater/UpdateManager.py @@ -3,9 +3,13 @@ import os import sys +import apt +from apt import cache +import shutil import dbus import logging import dbus.service +from apt.debfile import DebPackage from dbus.mainloop.glib import DBusGMainLoop DBusGMainLoop(set_as_default=True) @@ -92,9 +96,43 @@ class UpdateManager(): # 进行本地deb包安装的操作 def start_deb_install(self, deb_path = "", is_install = False): + absolute_path, debname = os.path.split(deb_path) + logging.info("About to Install Package: %s.",str(debname)) + depends_list = [] + depends_pkg = [] + satisfy_list = [] + depends_count = 0 try: - absolute_path, debname = os.path.split(deb_path) - logging.info("About to Install Package: %s.",str(debname)) + deb = DebPackage(deb_path, self.cache) + deb.check() + (install, remove, unauth) = deb.required_changes + if len(install) > 1: + for pkg in self.cache: + if pkg.marked_install: + print(pkg.name) + depends_pkg.append(pkg) + elif pkg.marked_upgrade: + print(pkg.name) + depends_pkg.append(pkg) + if depends_pkg: #查找本地deb包 + depends_list = [debfile for debfile in os.listdir(absolute_path) if debfile.endswith(".deb")] + print(depends_list) + for depends in depends_pkg: + for debfile in depends_list: + if depends.name in debfile and depends.candidate.version in debfile: + #FIXME:检查depends包的合法性,高阶依赖 + depends_count += 1 + satisfy_list.append(debfile) + if depends_count < len(depends_pkg)-1 and is_install == False: + #本地依赖不满足 + return False + else: + #将应用包与依赖包拷贝至archive目录安装 + try: + for satisfy in satisfy_list: + shutil.copy(os.path.join(absolute_path,satisfy),"/var/cache/apt/archives/") + except Exception as e: + logging.info(str(e)) install_backend = get_backend(self, InstallBackend.ACTION_INSTALL_DEB) install_backend.start_alone(partial_upgrade_list = deb_path, _is_install = is_install) except Exception as e: diff --git a/backend/SystemUpdater/UpdateManagerDbus.py b/backend/SystemUpdater/UpdateManagerDbus.py index 1b0ee96..434c3c4 100755 --- a/backend/SystemUpdater/UpdateManagerDbus.py +++ b/backend/SystemUpdater/UpdateManagerDbus.py @@ -65,7 +65,7 @@ class UpdateManagerDbusController(dbus.service.Object): obj = bus.get_object('com.kylin.software.properties', '/com/kylin/software/properties') interface = dbus.Interface(obj, dbus_interface='com.kylin.software.properties.interface') lock.acquire() - retval = interface.updateSourceTemplate() + retval = True #interface.updateSourceTemplate() lock.release() except Exception as e: header = _("update important list occur Exception") @@ -241,8 +241,9 @@ class UpdateManagerDbusController(dbus.service.Object): def InstallDebFile(self,source = "unKnown", path = "", _is_install = False): try: is_install = bool(_is_install) + deb_path = str(path) logging.info('method InstallDebFile and is_install:%r...',is_install) - self.parent.start_deb_install(deb_path = path, is_install = is_install) + self.parent.start_deb_install(deb_path, is_install) return True,'success' except Exception as e: logging.error(False, str(e)) diff --git a/backend/SystemUpdater/backend/__init__.py b/backend/SystemUpdater/backend/__init__.py index 56b6f27..365bfeb 100644 --- a/backend/SystemUpdater/backend/__init__.py +++ b/backend/SystemUpdater/backend/__init__.py @@ -153,7 +153,6 @@ class InstallBackend(): self.install_deb(install_path = partial_upgrade_list, install_force = True) except Exception as e: logging.error(str(e)) - def update(self): """Run a update to refresh the package list""" @@ -366,7 +365,7 @@ class InstallBackend(): else: self.window_main.dbusController.UpdateDetectFinished(success,[],'','') elif action == self.ACTION_INSTALL_DEB: - pass + print("run hear...") unLockedEnableShutdown() # try aptdaemon