状态信息转化为中文根据系统语言

This commit is contained in:
wangsong 2021-09-15 09:35:19 +08:00
parent a3da668f71
commit 686f5e320b
5 changed files with 39 additions and 30 deletions

View File

@ -493,6 +493,8 @@ class UpdateList():
return app_groups + pkg_groups
def _read_important_list(self):
header = ''
desc = ''
# 获取importantlist 本次更新推送
try:
with open(self.IMPORTANT_LIST_PATH, 'r') as f:
@ -501,8 +503,10 @@ class UpdateList():
logging.info("importantList: %s",self.important_list)
return True
except Exception as e:
logging.info("read important list failed becauce: %s",e)
return False
header = _("read important list failed")
desc = ("%s",str(e))
logging.info(header + desc)
return False,header,desc
def _make_pkg_info_json(self,cache,pkgs_list):
size = 0
@ -620,7 +624,6 @@ class UpdateList():
def update(self, cache, eventloop_callback=None):
pkgs_install = []
pkgs_upgrade = []
pkgs_remove = []
@ -666,10 +669,8 @@ class UpdateList():
#不需要升级 全部的软件都是新的
header = _("The software on this computer is up to date.")
desc = ''
return True,header,desc
#FIXME: 目前此功能不使用 但是以此按应用进行分组是更好的展示升级列表的方式
# self.update_groups = self._make_groups(cache, self.pkgs_upgrade,
# eventloop_callback)

View File

@ -135,11 +135,11 @@ class UpdateManager():
install_backend = get_backend(self, InstallBackend.ACTION_INSTALL)
install_backend.start_alone(pkgs_install,pkgs_upgrade,pkgs_remove,pkgs_purge)
#更新结束之后会调到此获取要升级的列表 and 安装完成后也会再重新调此方法,更新cache
#更新结束之后会调到此获取要升级的列表 and 更新cache 生成升级组列表JSON
def start_available(self, cancelled_update=False):
_success,header,desc = self.refresh_cache()
#特殊情况的处理 单独安装包需要直接退出
#特殊情况的处理 单独安装包需要直接退出 安装or卸载执行完毕后 还会调到start_available
if _success == True and header == INSTALL_ALONE_PROGRESS:
return
else:

View File

@ -65,7 +65,7 @@ class UpdateManagerDbusController(dbus.service.Object):
return False,'In the process of updating or Upgrading...'
else:
self.parent.start_update()
logging.info('dbus updating ...')
logging.info('method dbus updating ...')
return True
except Exception:
return False
@ -79,9 +79,13 @@ class UpdateManagerDbusController(dbus.service.Object):
logging.info('In the process of updating or Upgrading...')
return False,'In the process of updating or Upgrading...'
else:
logging.info('dbus upgrading ...')
self.parent.start_install()
return True
upgrade_groups_list = self.parent.update_list.local_upgrade_list.get('upgrade_groups_list',[])
if upgrade_groups_list:
logging.info('method dbus upgrading ...')
self.parent.start_install()
return True
else:
return False
except Exception:
return False
@ -119,6 +123,7 @@ class UpdateManagerDbusController(dbus.service.Object):
self.transaction.cancel()
status = True
message = "Success"
logging.info("dbus-mothod cancel task Success")
elif self.transaction == None or self.transaction.cancellable == False:
message = "Can not Cancel"
except Exception as e:
@ -133,7 +138,7 @@ class UpdateManagerDbusController(dbus.service.Object):
#更新完成的信号
@dbus.service.signal(INTERFACE,signature='basss')
def UpdateDetectFinished(self, success, upgrade_group,error_string='',error_desc='',):
logging.info("emit udapte success = %r , upgrade_group = %a, error_string = %s , error_desc = %s ",\
logging.info("emit update success = %r , upgrade_group = %a, error_string = %s , error_desc = %s ",\
success,upgrade_group, error_string,error_desc)
#升级的进度信息 0~100 进度信息 101为非预期的信号
@ -150,7 +155,7 @@ class UpdateManagerDbusController(dbus.service.Object):
#发送下载包信息
@dbus.service.signal(INTERFACE, signature='iiiii')
def UpdateDownloadInfo(self, current_items, total_items, currenty_bytes, total_bytes, current_cps):
logging.info("current_items = %d, total_items = %d, currenty_bytes = %d, total_bytes = %d, current_cps = %d .",\
logging.info("emit current_items = %d, total_items = %d, currenty_bytes = %d, total_bytes = %d, current_cps = %d .",\
current_items, total_items, \
currenty_bytes, total_bytes,\
current_cps)

View File

@ -5,9 +5,11 @@ from __future__ import print_function
from aptdaemon import client, errors
from defer import inline_callbacks
from aptdaemon.enums import (EXIT_SUCCESS,
EXIT_FAILED,
get_error_description_from_enum,
get_error_string_from_enum)
EXIT_FAILED,
get_error_description_from_enum,
get_error_string_from_enum,
get_status_string_from_enum
)
from UpdateManager.backend import InstallBackend
import logging
@ -35,15 +37,15 @@ class InstallBackendAptdaemon(InstallBackend):
self.window_main.dbusController.transaction = trans
#注册回调函数 接收更新的状态
yield self._show_transaction(trans, self.ACTION_UPDATE,
_("Checking for updates…"), False)
_("Checking for updates…"), False)
except errors.NotAuthorizedError:
self._action_done(self.ACTION_UPDATE,
authorized=False, success=False,
error_string=None, error_desc=None)
authorized=False, success=False,
error_string=None, error_desc=None)
except Exception:
self._action_done(self.ACTION_UPDATE,
authorized=True, success=False,
error_string=None, error_desc=None)
authorized=True, success=False,
error_string=None, error_desc=None)
raise
@inline_callbacks
@ -57,23 +59,23 @@ class InstallBackendAptdaemon(InstallBackend):
self.window_main.dbusController.transaction = trans
yield self._show_transaction(trans, self.ACTION_INSTALL,
_("Installing updates…"), True)
_("Installing updates…"), True)
except errors.NotAuthorizedError:
self._action_done(self.ACTION_INSTALL,
authorized=False, success=False,
error_string=None, error_desc=None)
authorized=False, success=False,
error_string=None, error_desc=None)
except errors.TransactionFailed as e:
self.trans_failed_msg = str(e)
except dbus.DBusException as e:
if e.get_dbus_name() != "org.freedesktop.DBus.Error.NoReply":
raise
self._action_done(self.ACTION_INSTALL,
authorized=False, success=False,
error_string=None, error_desc=None)
authorized=False, success=False,
error_string=None, error_desc=None)
except Exception:
self._action_done(self.ACTION_INSTALL,
authorized=True, success=False,
error_string=None, error_desc=None)
authorized=True, success=False,
error_string=None, error_desc=None)
raise
#进度回调
@ -86,7 +88,9 @@ class InstallBackendAptdaemon(InstallBackend):
#同步状态回调
def _on_status_changed(self, trans, status,action):
self.trans_status = status
#转化词条
self.trans_status = get_status_string_from_enum(status)
if action == self.ACTION_UPDATE:
self.window_main.dbusController.UpdateDetectStatusChanged(self.trans_progress,self.trans_status)
else:

View File

@ -92,7 +92,6 @@ class InstallBackend():
self.window_main.dbusController.UpdateDownloadFinished(success,self.upgrade_groups_list,'','')
else:
self.window_main.start_available()
elif error_string or error_desc:
logging.warning(error_string + error_desc)
self.window_main.dbusController.UpdateDownloadFinished(success,self.upgrade_groups_list,error_string,error_desc)