Merge branch 'backend_manual' into 'backend_uu'

Backend manual

See merge request kylin-desktop/update-manager-group/kylin-system-updater!459
This commit is contained in:
luoxueyi 2022-07-28 06:26:48 +00:00
commit a0002ac9cb
5 changed files with 121 additions and 69 deletions

View File

@ -679,6 +679,25 @@ def kill_process(path):
return False
return True
def whether_to_quit_uu():
osreleasedict={}
try:
with open('/etc/os-release') as f:
lines = f.readlines()
for line in lines:
ls = line.strip().split('=',1)
osreleasedict.update({ls[0]:ls[1].strip('"')})
except Exception as e:
pass
if 'SUB_PROJECT_CODENAME' not in osreleasedict.keys():
osreleasedict.update({'SUB_PROJECT_CODENAME':''})
if 'PROJECT_CODENAME' in osreleasedict:
if osreleasedict['PROJECT_CODENAME']=='V10SP1-edu':
if 'SUB_PROJECT_CODENAME' in osreleasedict:
if osreleasedict['SUB_PROJECT_CODENAME']=='mavis':
return False
return True
def get_proc_from_dbus_name(dbus_name, bus=None):
"""Return a deferred that gets the id of process owning the given
system D-Bus name.

View File

@ -30,7 +30,7 @@ from .Core.DataAcquisition import UpdateMsgCollector
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 SystemUpdater.Core.utils import deb_verify,PolicyKit_Authority,get_proc_from_dbus_name,whether_to_quit_uu
class UpdateManager():
BACKEND_PKG_NAME = 'kylin-system-updater'
@ -194,7 +194,8 @@ class UpdateManager():
resolver_backend.start(upgrade_content)
else:
if not_resolver == True:
kill_process(self.RUN_UNATTENDED_UPGRADE)
if upgrade_mode == InstallBackend.MODE_INSTALL_SINGLE and whether_to_quit_uu:
kill_process(self.RUN_UNATTENDED_UPGRADE)
install_backend = get_backend(self, InstallBackend.ACTION_INSTALL,upgrade_mode)
install_backend.start(upgrade_content)
else:
@ -391,62 +392,18 @@ class UpdateManager():
raise UpdateProgressExit()
def _check_system_broken(self,cache):
with cache.actiongroup():
if cache.get_changes():
cache.clear()
#获取出现破损状态包的数量
wouldDelete = cache._depcache.broken_count
if wouldDelete > 0:
broken_msg = get_broken_details(cache)
#获取那些依赖关系不满足导致的问题
logging.info(broken_msg)
else:
logging.info("Check: System Apt Cache for Broken Successfully...")
return
try:
#计算依赖的解决方案
cache.fix_broken()
except SystemError as e:
logging.error(e)
return
pkgs_install = []
pkgs_upgrade = []
pkgs_remove = []
#计算修复破损包 方案 需要删除 新装那些包
for pkg in cache:
try:
if pkg.marked_install :
pkgs_install.append(pkg.name)
elif pkg.marked_upgrade:
pkgs_upgrade.append(pkg.name)
elif pkg.marked_delete:
pkgs_remove.append(pkg.name)
except KeyError:
# pkg missing from fresh_cache can't be modified
pass
logging.warning("Fix broken Packages is need to install:%a and upgrade:%a and remove:%a",pkgs_install,pkgs_upgrade,pkgs_remove)
#当存在需要卸载包的情况时 不进行修复
if len(pkgs_remove) == 0:
logging.warning("start fix system broken pkgs...")
self.start_fix_broken()
else:
raw_description = []
delete_desc = []
#添加关于删除包的描述信息
for pkg in pkgs_remove:
delete_desc.append('')
pkg_obj = self.cache[pkg]
raw_description.append(getattr(pkg_obj.candidate, "summary", ''))
self.dbusController.UpdateFixBrokenStatus(True,True,pkgs_remove,raw_description,delete_desc,'','')
if cache.get_changes():
cache.clear()
raise UpdateProgressExit()
if cache.get_changes():
cache.clear()
#获取出现破损状态包的数量
if cache._depcache.broken_count > 0:
#线程获取详细的卸载软件包情况
self.simulate_mode.start_caculate(["apt-get", "install","-f","--simulate"],thread=True)
else:
logging.info("Check: System Apt Cache for Broken Successfully...")
return
fix_backend = get_backend(self, InstallBackend.ACTION_CHECK_BROKEN)
fix_backend.start()
raise UpdateProgressExit()
def _setup_dbus(self):
# check if there is another g-a-i already and if not setup one
@ -776,9 +733,9 @@ class UpdateManager():
absolute_path, debname = os.path.split(deb_path)
# 检查本地破损
try:
logging.info("Install package, open cache")
logging.info("Install deb package, open cache")
deb_cache = Cache()
logging.info("Install package, check broken")
logging.info("Install deb package, check broken")
broken_count = deb_cache._depcache.broken_count
deb = DebPackage(deb_path, deb_cache)
deb.check(allow_downgrade=True)
@ -995,7 +952,23 @@ class SimulateTerminal():
ZH_UNMET_DEPENDENCIES = '下列软件包有未满足的依赖关系:'
EN_UNMET_DEPENDENCIES = 'The following packages have unmet dependencies:'
def __init__(self):
pass
self.update_args = ["apt-get", "update"]
self.install_args = ["apt-get", "install","--simulate"]
def _sub_emulate(self,args):
p = subprocess.run(args, stdout=subprocess.PIPE,stderr=subprocess.STDOUT,text=True)
logging.info(str(p.stdout))
return p.stdout
def start_caculate(self,args = [],thread = False):
tmp_str = ''
if thread is True:
threading_emulate = threading.Thread(target=self._sub_emulate,args=(args,))
threading_emulate.start()
else:
p = subprocess.run(args, stdout=subprocess.PIPE,stderr=subprocess.STDOUT,text=True)
tmp_str = p.stdout
return tmp_str
def _emulate_install(self,pkgs):
args = ["apt-get", "install","--simulate"]

View File

@ -103,11 +103,11 @@ class InstallBackendAptdaemon(InstallBackend):
else:
#超时只单独进行解锁关机
self.window_main.inhibit_shutdown.unlock()
# self._action_done(self.ACTION_INSTALL,
# is_cancelled=False, success=False,
# #FIXME: 安装超时退出
# error_string=_("Could not install the upgrades"),
# error_desc=_("Installtion timeout to exit Due to inactivity") + self.aptd_base.details)
self._action_done(self.ACTION_INSTALL,
is_cancelled=False, success=False,
#FIXME: 安装超时退出
error_string=_("Could not install the upgrades"),
error_desc=_("Installtion timeout to exit Due to inactivity") + self.aptd_base.details)
# self.window_main.dbusController.Quit(None)
return False

View File

@ -105,6 +105,7 @@ class InstallBackend():
ACTION_CLEAN = 8
ACTION_INSTALL_SHUTDOWN = 9
ACTION_BACKGROUND_UPGRADE = 10
ACTION_CHECK_BROKEN = 11
MODE_DEFAULT_STATUS = -1
@ -252,7 +253,37 @@ class InstallBackend():
self._action_done(self.action,False,True,'','')
#修复未满足的依赖关系 与apt-get -f install匹配
elif self.action == self.ACTION_CHECK_BROKEN:
try:
#计算依赖的解决方案
self.cache.fix_broken()
except Exception as e:
logging.error(e)
raise UpdateBaseError(ERROR_RESOLVER_FAILED)
pkgs_install,pkgs_upgrade,pkgs_remove = self._get_pkgs_from_cache(self.cache)
logging.warning("Fix broken Packages is need to install:%a and upgrade:%a and remove:%a",pkgs_install,pkgs_upgrade,pkgs_remove)
#当存在需要卸载包的情况时 不进行修复
if len(pkgs_remove) == 0:
logging.warning("start fix system broken pkgs...")
self.fix_broken()
else:
raw_description = []
delete_desc = []
#添加关于删除包的描述信息
for pkg in pkgs_remove:
delete_desc.append('')
pkg_obj = self.cache[pkg]
raw_description.append(getattr(pkg_obj.candidate, "summary", ''))
self.window_main.dbusController.UpdateFixBrokenStatus(True,True,pkgs_remove,raw_description,delete_desc,'','')
self._action_done(self.action,False,True,'','')
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.fix_broken()
# 修复不完整的安装dpkg configure -a
elif self.action == self.ACTION_FIX_INCOMPLETE:
@ -283,12 +314,22 @@ class InstallBackend():
self.install_deb(install_path = partial_upgrade_list, install_force = _is_install)
except Exception as e:
logging.error(str(e))
# 安装在线包的接口
elif self.action == self.ACTION_BACKGROUND_UPGRADE:
try:
pkgs_install = partial_upgrade_list
pkgs_install = [ str(pkg) for pkg in partial_upgrade_list]
logging.info("Install deb package, open cache")
cache = Cache()
for pkg_name in pkgs_install:
if pkg_name not in cache:
if "=" not in pkg_name or ("=" in pkg_name and pkg_name.split("=")[0] not in cache):
# 没找到包或格式不正确
self.window_main.dbusController.UpdateInstallFinished(False, pkgs_install, "'"+pkg_name+"' is not in cache", "")
return
self.commit(self.ACTION_INSTALL,pkgs_install,[],[])
except Exception as e:
logging.error(str(e))
self.window_main.dbusController.UpdateInstallFinished(False, pkgs_install, str(e), "")
def update(self):
"""Run a update to refresh the package list"""
@ -318,6 +359,25 @@ class InstallBackend():
"""purge_packages"""
raise NotImplementedError
def _get_pkgs_from_cache(self,cache):
pkgs_install = []
pkgs_upgrade = []
pkgs_remove = []
#计算修复破损包 方案 需要删除 新装那些包
for pkg in cache:
try:
if pkg.marked_install :
pkgs_install.append(pkg.name)
elif pkg.marked_upgrade:
pkgs_upgrade.append(pkg.name)
elif pkg.marked_delete:
pkgs_remove.append(pkg.name)
except KeyError:
# pkg missing from fresh_cache can't be modified
pass
return pkgs_install,pkgs_upgrade,pkgs_remove
#从cache中拿到标记的列表
def _get_mark_from_cache(self,cache,_adjust_pkgs,upgrade_mode):
pkgs_install = []
@ -564,7 +624,7 @@ class InstallBackend():
error_string +' '+error_desc)
#调用aptdeamon结束之后处理的地方 不管是出错还是正常都在此处理
def _action_done(self, action, is_cancelled,success, error_string,error_desc,error_code=''):
def _action_done(self, action, is_cancelled,success, error_string='',error_desc='',error_code=''):
#后端的状态 到空闲状态
self.window_main.now_working = self.ACTION_DEFUALT_STATUS

View File

@ -65,7 +65,7 @@ if __name__ == "__main__":
#当不存在语言变量时 默认显示中文
if not "LANGUAGE" in os.environ:
os.environ["LANGUAGE"] = "zh_CN"
os.environ["LANGUAGE"] = "zh_CN.UTF-8"
#当不存在语言变量时 默认显示中文
if not "LANG" in os.environ: