增加电量检测 增加finished错误反馈的信号

This commit is contained in:
wangsong 2021-08-31 17:49:50 +08:00
parent e061864679
commit c67d28a030
7 changed files with 117 additions and 41 deletions

View File

@ -176,6 +176,7 @@ class MyCache(DistUpgrade.DistUpgradeCache.MyCache):
""" this functions mimics a upgrade but will never remove anything """
#upgrade(True) 为True时使用dist-upgrade进行升级
self._depcache.upgrade(True)
wouldDelete = self._depcache.del_count
wouldDelete = 0
if wouldDelete > 0:
deleted_pkgs = [pkg for pkg in self if pkg.marked_delete]

View File

@ -487,7 +487,7 @@ class UpdateList():
def update(self, cache, eventloop_callback=None):
self.held_back = []
#来判断将要删除的包
#来判断将要删除的包 如果存在要删除的break的包的话 会从dist-upgrade切换到upgrade 目前此功能不使用 默认使用dist-upgrade
self.distUpgradeWouldDelete = cache.saveDistUpgrade()
# Find all upgradable packages
@ -504,6 +504,8 @@ class UpdateList():
self.pkgs_remove.append(pkg.name)
except KeyError:
pass
print("")
#支持输出json文件 包含新安装 and 升级 and 移除
# pkgs_json = {"install": self.pkgs_install, "upgrade": self.pkgs_upgrade,"remove": self.pkgs_remove}

View File

@ -11,15 +11,16 @@ import logging
import sys
from gettext import gettext as _
import apt_pkg
import dbus
import dbus.service
from dbus.mainloop.glib import DBusGMainLoop
DBusGMainLoop(set_as_default=True)
from DistUpgrade.DistUpgradeCache import NotEnoughFreeSpaceError
from .Core.MyCache import MyCache
from .UpdateManagerDbus import UpdateManagerDbusController
from .Core.UpdateList import UpdateList
from .Core.utils import get_arch
from .backend import (InstallBackend,
get_backend)
@ -35,12 +36,66 @@ class UpdateManager():
self.is_updating = False
self.is_upgrading = False
#获取系统的架构
self.arch = get_arch()
#建立dbus
self.dbusController = self._setup_dbus()
def return_remove(self):
return self.update_list.pkgs_remove
# # FIXME: 目前此功能没有进行测试不知道是否可以进行检查 安装的时进行检查磁盘空间
def check_free_space(self,cache):
err_sum = _("Not enough free disk space")
err_msg = _("The upgrade needs a total of %s free space on "
"disk '%s'. "
"Please free at least an additional %s of disk "
"space on '%s'. %s")
# specific ways to resolve lack of free space
remedy_archivedir = _("Remove temporary packages of former "
"installations using 'sudo apt clean'.")
remedy_boot = _("You can remove old kernels using "
"'sudo apt autoremove', and you could also "
"set COMPRESS=xz in "
"/etc/initramfs-tools/initramfs.conf to "
"reduce the size of your initramfs.")
remedy_root = _("Empty your trash and remove temporary "
"packages of former installations using "
"'sudo apt clean'.")
remedy_tmp = _("Reboot to clean up files in /tmp.")
remedy_usr = _("")
# check free space and error if its not enough
try:
cache.checkFreeSpace()
except NotEnoughFreeSpaceError as e:
# CheckFreeSpace examines where packages are cached
archivedir = apt_pkg.config.find_dir("Dir::Cache::archives")
err_long = ""
for req in e.free_space_required_list:
if err_long != "":
err_long += " "
if req.dir == archivedir:
err_long += err_msg % (req.size_total, req.dir,
req.size_needed, req.dir,
remedy_archivedir)
elif req.dir == "/boot":
err_long += err_msg % (req.size_total, req.dir,
req.size_needed, req.dir,
remedy_boot)
elif req.dir == "/":
err_long += err_msg % (req.size_total, req.dir,
req.size_needed, req.dir,
remedy_root)
elif req.dir == "/tmp":
err_long += err_msg % (req.size_total, req.dir,
req.size_needed, req.dir,
remedy_tmp)
elif req.dir == "/usr":
err_long += err_msg % (req.size_total, req.dir,
req.size_needed, req.dir,
remedy_usr)
#在此抛出异常
# self.window_main.start_error(False, err_sum, err_long)
return False
except SystemError:
logging.exception("free space check failed")
return True
#进行更新的操作
def start_update(self):
@ -55,6 +110,11 @@ class UpdateManager():
#进行升级的操作
def start_install(self):
#FIXME: 此功能未完善
#检查磁盘的状态
if self.check_free_space(self.cache) == False:
return
self.is_upgrading = True
install_backend = get_backend(self, InstallBackend.ACTION_INSTALL)
install_backend.start()
@ -107,10 +167,6 @@ class UpdateManager():
"message:\n") + str(e)
self.start_error(True, header, desc)
if self.update_list.distUpgradeWouldDelete > 0:
print(self.update_list.distUpgradeWouldDelete)
#self._start_pane(PartialUpgradeDialog(self))
def _setup_dbus(self):
""" this sets up a dbus listener if none is installed already """
# check if there is another g-a-i already and if not setup one

View File

@ -58,7 +58,7 @@ class UpdateManagerDbusController(dbus.service.Object):
return False,'In the process of updating or Upgrading...'
else:
self.parent.start_install()
logging.info('dbus installing ...')
logging.info('dbus upgrading ...')
return True
except Exception:
return False
@ -85,8 +85,20 @@ class UpdateManagerDbusController(dbus.service.Object):
def status_changed_signal(self, message):
pass
#更新升级完毕的信号 status(str) action(update or upgrade)
#更新升级完毕的信号
#ACTION_UPDATE = 0 ACTION_INSTALL = 1
@dbus.service.signal(INTERFACE,signature='si')
def on_finished_signal(self,status,action):
'''
action 表示更新或者安装0更新 1安装
success 更新安装是成功还是失败
trans_failed 是否可以重试
error_string 错误的结果
error_desc 产生的原因
'''
@dbus.service.signal(INTERFACE,signature='ibbss')
def on_finished_signal(self,action, success, trans_failed=False, error_string=None,error_desc=None):
pass
#更新和升级的进度信息 0~101 进度信息
@dbus.service.signal(INTERFACE,signature='i')
def on_progress_changed_signal(self,progress):
pass

View File

@ -37,7 +37,7 @@ class InstallBackendAptdaemon(InstallBackend):
@inline_callbacks
def update(self):
"""刷新包cache 使用异步更新"""
"""刷新包cache"""
try:
trans = yield self.client.update_cache(defer=True)
#注册回调函数 接收更新的状态
@ -84,11 +84,13 @@ class InstallBackendAptdaemon(InstallBackend):
raise
def _on_progress_changed(self, trans, progress):
self.window_main.dbusController.on_progress_changed_signal(progress)
logging.debug("_on_progress_changed", progress)
def _on_details_changed(self, trans, details):
logging.info(details)
pass
# logging.info(details)
def _on_status_changed(self, trans, status):
self.window_main.dbusController.status_changed_signal(status)
@ -175,15 +177,17 @@ class InstallBackendAptdaemon(InstallBackend):
error_desc = None
trans_failed = False
#安装或升级完成之后emit的信号
self.window_main.dbusController.on_finished_signal(status,action)
logging.info(status)
if status == EXIT_FAILED:
error_string = get_error_string_from_enum(trans.error.code)
error_desc = get_error_description_from_enum(trans.error.code)
if self.trans_failed_msg:
trans_failed = True
error_desc = error_desc + "\n" + self.trans_failed_msg
is_success = (status == EXIT_SUCCESS)
self.window_main.dbusController.on_finished_signal(action,is_success,trans_failed,error_string,error_desc)
try:
self._action_done(action,
authorized=True, success=is_success,

View File

@ -29,30 +29,30 @@ class InstallBackend():
if self.action == self.ACTION_INSTALL:
# Get the packages which should be installed and update
pkgs_install = ['ukui-panel','atril-common']
pkgs_install = []
pkgs_upgrade = []
pkgs_remove = []
# Get a fresh cache in case update-manager's is outdated to
# skip operations that already took place
# fresh_cache = Cache(rootdir=self.window_main.cache.rootdir)
# for pkg in self.window_main.cache:
# try:
# if pkg.marked_install \
# and not fresh_cache[pkg.name].is_installed:
# pkgname = pkg.name
# if pkg.is_auto_installed:
# pkgname += "#auto"
# pkgs_install.append(pkgname)
# elif (pkg.marked_upgrade
# and fresh_cache[pkg.name].is_upgradable):
# pkgs_upgrade.append(pkg.name)
# elif (pkg.marked_delete
# and fresh_cache[pkg.name].is_installed):
# pkgs_remove.append(pkg.name)
# except KeyError:
# # pkg missing from fresh_cache can't be modified
# pass
fresh_cache = Cache(rootdir=self.window_main.cache.rootdir)
for pkg in self.window_main.cache:
try:
if pkg.marked_install \
and not fresh_cache[pkg.name].is_installed:
pkgname = pkg.name
if pkg.is_auto_installed:
pkgname += "#auto"
pkgs_install.append(pkgname)
elif (pkg.marked_upgrade
and fresh_cache[pkg.name].is_upgradable):
pkgs_upgrade.append(pkg.name)
elif (pkg.marked_delete
and fresh_cache[pkg.name].is_installed):
pkgs_remove.append(pkg.name)
except KeyError:
# pkg missing from fresh_cache can't be modified
pass
self.commit(pkgs_install, pkgs_upgrade, pkgs_remove)
else:
@ -73,11 +73,12 @@ class InstallBackend():
if success:
self.window_main.start_available()
elif error_string:
logging.error(trans_failed, error_string, error_desc)
logging.warning(error_string + error_desc)
#update 更新完毕走的分支
else:
if error_string:
logging.error(trans_failed, error_string, error_desc)
#失败的话直接退出
logging.warning(error_string + error_desc)
else:
is_cancelled_update = not success
self.window_main.start_available(is_cancelled_update)

View File

@ -30,12 +30,12 @@ if __name__ == "__main__":
(options, args) = parser.parse_args()
if options.debug:
logging.basicConfig(format=FORMAT_DEBUG,level=logging.DEBUG)
logging.basicConfig(format=FORMAT,level=logging.DEBUG)
else:
logging.basicConfig(format=FORMAT,level=logging.INFO)
logging.info('kylin-update-manager starting ...')
app = UpdateManager(options)
# app.start_update()
app.start_update()
Gtk.main()