From f752ae8ba03e21befd76c0523e3918a186aeb543 Mon Sep 17 00:00:00 2001 From: wangsong Date: Tue, 14 Jun 2022 10:59:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=A8=A1=E6=8B=9F=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/SystemUpdater/UpdateManager.py | 47 ++++++++++++++++++++--- backend/SystemUpdater/backend/__init__.py | 23 ----------- 2 files changed, 41 insertions(+), 29 deletions(-) diff --git a/backend/SystemUpdater/UpdateManager.py b/backend/SystemUpdater/UpdateManager.py index c759cfd..224cb88 100644 --- a/backend/SystemUpdater/UpdateManager.py +++ b/backend/SystemUpdater/UpdateManager.py @@ -1,9 +1,6 @@ # UpdateManager.py # -*- Mode: Python; indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*- import os -import subprocess -from unicodedata import lookup -from apt import Cache import apt_pkg import sys import time @@ -12,10 +9,16 @@ import dbus import logging import dbus.service import json +import threading +import subprocess +from apt import Cache +from gettext import gettext as _ from apt.debfile import DebPackage from dbus.mainloop.glib import DBusGMainLoop DBusGMainLoop(set_as_default=True) +from .Core.errors import * +from .Core.enums import * from .Core.MyCache import MyCache from .UpdateManagerDbus import UpdateManagerDbusController,UPDATER_DBUS_INTERFACE,UPDATER_DBUS_PATH,UPDATER_DBUS_SERVICE from .Core.UpdateList import UpdateList @@ -24,14 +27,12 @@ from .Core.Database import Sqlite3Server from .Core.loop import mainloop from .Core.DataAcquisition import UpdateMsgCollector -from gettext import gettext as _ from SystemUpdater.Core.UpdaterConfigParser import UpgradeConfig from SystemUpdater.Core.utils import get_broken_details,kill_process from SystemUpdater.Core.DpkgInstallProgress import LogInstallProgress from SystemUpdater.Core.utils import deb_verify,PolicyKit_Authority,get_proc_from_dbus_name -from .Core.errors import * -from .Core.enums import * + class UpdateManager(): BACKEND_PKG_NAME = 'kylin-system-updater' @@ -888,6 +889,40 @@ class InhibitShutdownLock(): except Exception as e: logging.error("unlock failed." + str(e)) +class SimulateUpdateInstall(): + + def __init__(self): + pass + + def emulate_install(self,pkgs): + args = ["apt-get", "install","--simulate"] + args = args + pkgs + + p = subprocess.run(args, stdout=subprocess.PIPE,stderr=subprocess.STDOUT,text=True) + logging.info(str(p.stdout)) + return p.stdout + + def emulate_update(self): + args = ["apt-get", "update"] + + p = subprocess.run(args, stdout=subprocess.PIPE,stderr=subprocess.STDOUT,text=True) + logging.info(str(p.stdout)) + return p.stdout + + def thread_install(self): + threading_emulate = threading.Thread(target=self.emulate_update) + threading_emulate.start() + + def thread_update(self): + threading_emulate = threading.Thread(target=self.emulate_update) + threading_emulate.start() + + def emulate_install_broken(self,pkgs): + self.emulate_install(pkgs) + + + pass + class UpdateInstallMode(): def __init__(self,parent): self.parent = parent diff --git a/backend/SystemUpdater/backend/__init__.py b/backend/SystemUpdater/backend/__init__.py index 05359b6..1492531 100644 --- a/backend/SystemUpdater/backend/__init__.py +++ b/backend/SystemUpdater/backend/__init__.py @@ -250,28 +250,8 @@ class InstallBackend(): self.fix_incomplete() #卸载包 elif self.action == self.ACTION_REMOVE_PACKAGES: - # remove_pkgs = [] - # for pkg in partial_upgrade_list: - # if pkg in self.cache: - # pkg_cache = self.cache[pkg] - # pkg_cache.mark_delete(True, True) - # else: - # #没有在cache中就认为不需要升级 - # logging.error("Check: (%s) The reomve package is not in Cache...",pkg) - - # for pkg_obj in self.cache.get_changes(): - # if pkg_obj.marked_delete: - # remove_pkgs.append(pkg_obj.name) - - # success,header,desc = self.check_essential_pkgs(remove_pkgs) - # if success == False: - # self._action_done(self.action,False,False,header,desc) - # return - # else: self._start_install_lock() self.purge_packages(partial_upgrade_list) - - #清空所有下载的文件 elif self.action == self.ACTION_CLEAN: self.clean() #更新cache @@ -481,13 +461,10 @@ class InstallBackend(): for pkg in pkgs_install + pkgs_upgrade: pkg_string = pkg_string + ' ' + str(pkg) logging.info('Resolver calculation Packages List: '+pkg_string+'\n') - # logging.error('\n' + msg) terminal_msg = self.emulate_calcul_broken(pkgs_install + pkgs_upgrade) logging.error(terminal_msg) raise UpdateBaseError(ERROR_RESOLVER_FAILED, desc= terminal_msg) - # threading_emulate = threading.Thread(target=emulate_calcul_broken,args=(pkgs_install + pkgs_upgrade,)) - # threading_emulate.start() def _emulate_calcul_delete(self,pkg,cache): try: