diff --git a/backend/SystemUpdater/UpdateManager.py b/backend/SystemUpdater/UpdateManager.py index e08419a..c1ed157 100644 --- a/backend/SystemUpdater/UpdateManager.py +++ b/backend/SystemUpdater/UpdateManager.py @@ -98,32 +98,49 @@ class UpdateManager(): 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)) + try: + (status,_error_str) = self._attempt_depends(deb_path,is_install) + if not status: + return status,_error_str + 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: + logging.info(str(e)) + + def _attempt_depends(self,deb_path,force): # 是否查找本地依赖 depends_list = [] depends_pkg = [] satisfy_list = [] depends_count = 0 - try: + _error_str = "" + absolute_path, debname = os.path.split(deb_path) + if force: deb = DebPackage(deb_path, self.cache) deb.check() (install, remove, unauth) = deb.required_changes - if len(install) > 1: + if remove: + logging.error("Need uninstall: %s.",str(remove)) + _error_str = "Installing "+str(debname.split("_")[0])+" requires uninstalling "+str(remove) + return False,_error_str + if force == False and len(install) > 0: + _error_str = str(debname.split("_")[0])+" dependency is not satisfied:\n"+str(install) + return False,_error_str + # 需要查找本地依赖 + elif len(install) > 0: 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: + if depends_count < len(depends_pkg)-1 and force == False: #本地依赖不满足 return False else: @@ -133,11 +150,6 @@ class UpdateManager(): 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: - logging.info(str(e)) - #进行升级的操作 def start_install(self,upgrade_mode,is_install = False,partial_upgrade_list = []): try: @@ -281,7 +293,8 @@ class UpdateManager(): """If a reboot is required to get all changes into effect.""" return os.path.exists(os.path.join(apt_pkg.config.find_dir("Dir"), "var/run/reboot-required")) - + + def _setup_dbus(self): # check if there is another g-a-i already and if not setup one # listening on dbus diff --git a/backend/SystemUpdater/UpdateManagerDbus.py b/backend/SystemUpdater/UpdateManagerDbus.py index 434c3c4..fd81696 100755 --- a/backend/SystemUpdater/UpdateManagerDbus.py +++ b/backend/SystemUpdater/UpdateManagerDbus.py @@ -243,7 +243,9 @@ class UpdateManagerDbusController(dbus.service.Object): 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, is_install) + (status,_error_str) = self.parent.start_deb_install(deb_path, is_install) + if not status: + return True,_error_str return True,'success' except Exception as e: logging.error(False, str(e)) diff --git a/backend/kylin-system-updater b/backend/kylin-system-updater index b7e0389..50bd351 100755 --- a/backend/kylin-system-updater +++ b/backend/kylin-system-updater @@ -66,6 +66,6 @@ if __name__ == "__main__": logging.info('kylin-system-updater starting ...') app = UpdateManager(options) - app.start_update() + # app.start_update() app.run() \ No newline at end of file