修改信号的传输方式

This commit is contained in:
wangsong 2021-09-10 11:25:56 +08:00
parent 6b1afb4776
commit de8d83b6c3
7 changed files with 62 additions and 42 deletions

View File

@ -230,6 +230,8 @@ class UpdateList():
self.IMPORTANT_LIST_PATH="/var/lib/kylin-software-properties/template/important.list" self.IMPORTANT_LIST_PATH="/var/lib/kylin-software-properties/template/important.list"
self.important_list = [] self.important_list = []
self.output_upgrade_list = []
# a stable machine uniq id # a stable machine uniq id
try: try:
with open(self.UNIQ_MACHINE_ID_FILE) as f: with open(self.UNIQ_MACHINE_ID_FILE) as f:
@ -511,11 +513,17 @@ class UpdateList():
try: try:
files = os.listdir(self.INPUT_CONFIG_PATH) #获得文件夹中所有文件的名称列表 files = os.listdir(self.INPUT_CONFIG_PATH) #获得文件夹中所有文件的名称列表
for file in files: for file in files:
#判是否是目录以及是否以JSON结尾 #判是否是目录以及是否以JSON结尾
if not os.path.isdir(file) and file.endswith('.json'): if not os.path.isdir(file) and file.endswith('.json'):
with open(self.INPUT_CONFIG_PATH+"/"+file,'r') as f: with open(self.INPUT_CONFIG_PATH+"/"+file,'r') as f:
data = json.load(f) data = json.load(f)
#过滤没有推送的配置文件
if not data['package'] in self.important_list:
continue
groups_base_info = {}
output_json = {} output_json = {}
#FIXME: 确定输出文件的文件名 以及放置位置 #FIXME: 确定输出文件的文件名 以及放置位置
output_config_name = self.OUTPUT_CONFIG_PATH + '/' + data['package'] + '_output.json' output_config_name = self.OUTPUT_CONFIG_PATH + '/' + data['package'] + '_output.json'
@ -582,22 +590,27 @@ class UpdateList():
pass pass
#4、添加一些基础信息 #4、添加一些基础信息
output_json.update({"package":data['package']}) groups_base_info.update({"package":data['package']})
output_json.update({"version":data['version']}) groups_base_info.update({"version":data['version']})
output_json.update({"name":data['name']}) groups_base_info.update({"name":data['name']})
output_json.update({"description":data['description']}) groups_base_info.update({"description":data['description']})
output_json.update({"icon":data['icon']}) groups_base_info.update({"icon":data['icon']})
#5、添加升级的内容 #5、添加升级的内容
output_json.update(groups_base_info)
output_json.update({"upgrade_list":upgrade_pkgs_json}) output_json.update({"upgrade_list":upgrade_pkgs_json})
output_json.update({"install_list":install_pkgs_json}) output_json.update({"install_list":install_pkgs_json})
output_json.update({"hold_list":hold_pkgs_list}) output_json.update({"hold_list":hold_pkgs_list})
output_json.update({"remove_list":remove_pkgs_list}) output_json.update({"remove_list":remove_pkgs_list})
#6 产生JSON文件 #6 产生JSON文件
with open(output_config_name, 'w', encoding='utf-8') as f: with open(output_config_name, 'w', encoding='utf-8') as f:
json.dump(output_json, f, ensure_ascii=False, indent=4) json.dump(output_json, f, ensure_ascii=False, indent=4)
logging.info("Generate Jsonfile(%s) to complete... ",output_config_name) logging.info("Generate Jsonfile(%s) to complete... ",output_config_name)
#添加到输出升级列表
self.output_upgrade_list.append(data['package'])
else: else:
pass pass
except Exception as e: except Exception as e:
@ -627,11 +640,11 @@ class UpdateList():
logging.info("Find all upgradeable packages finished...") logging.info("Find all upgradeable packages finished...")
#源过滤 and 白名单过滤 #源过滤 and 白名单过滤
# fu = filter.UpdateListFilterCache() fu = filter.UpdateListFilterCache()
# allowed_origin_upgrade_pkgs = fu.check_in_allowed_origin(pkgs_upgrade) allowed_origin_upgrade_pkgs = fu.check_in_allowed_origin(pkgs_upgrade)
# filter_upgrade_pkgs = fu.is_pkgname_in_whitelist(allowed_origin_upgrade_pkgs) # filter_upgrade_pkgs = fu.is_pkgname_in_whitelist(allowed_origin_upgrade_pkgs)
self._make_json(cache,pkgs_upgrade = ([i.name for i in pkgs_upgrade])) self._make_json(cache,pkgs_upgrade = ([i.name for i in allowed_origin_upgrade_pkgs]))
#FIXME: 目前此功能不使用 但是以此按应用进行分组是更好的展示升级列表的方式 #FIXME: 目前此功能不使用 但是以此按应用进行分组是更好的展示升级列表的方式

View File

@ -180,8 +180,8 @@ class UpdateListFilterCache(apt.Cache):
for v in pkg.versions: for v in pkg.versions:
if is_in_allowed_origin(v, self.allowed_origins) and not pkg in new_upgrade_pkgs: if is_in_allowed_origin(v, self.allowed_origins) and not pkg in new_upgrade_pkgs:
new_upgrade_pkgs.append(pkg) new_upgrade_pkgs.append(pkg)
else: # else:
pkg.mark_keep() # pkg.mark_keep()
return new_upgrade_pkgs return new_upgrade_pkgs
def is_pkgname_in_blacklist(self, pkgs): def is_pkgname_in_blacklist(self, pkgs):

View File

@ -240,7 +240,7 @@ class UpdateManager():
desc = _("important.list list is empty") desc = _("important.list list is empty")
#发送更新升级列表完成的标志 #发送更新升级列表完成的标志
self.dbusController.on_finished_signal(self.ACTION_UPDATE_LIST,_success,header,desc) self.dbusController.UpdateDetectFinished(_success,self.update_list.output_upgrade_list,header,desc)
def _setup_dbus(self): def _setup_dbus(self):
""" this sets up a dbus listener if none is installed already """ """ this sets up a dbus listener if none is installed already """

View File

@ -57,7 +57,7 @@ class UpdateManagerDbusController(dbus.service.Object):
#更新的dbus #更新的dbus
@dbus.service.method(INTERFACE) @dbus.service.method(INTERFACE)
def update(self): def UpdateDetect(self):
try: try:
#处于更新和升级中的话 不进行更新 #处于更新和升级中的话 不进行更新
if self.parent.is_updating or self.parent.is_upgrading: if self.parent.is_updating or self.parent.is_upgrading:
@ -72,7 +72,7 @@ class UpdateManagerDbusController(dbus.service.Object):
#升级的dbus #升级的dbus
@dbus.service.method(INTERFACE) @dbus.service.method(INTERFACE)
def upgrade(self): def UpgradeSystem(self):
try: try:
#处于更新和升级中的话 不进行升级 #处于更新和升级中的话 不进行升级
if self.parent.is_updating or self.parent.is_upgrading: if self.parent.is_updating or self.parent.is_upgrading:
@ -84,6 +84,15 @@ class UpdateManagerDbusController(dbus.service.Object):
return True return True
except Exception: except Exception:
return False return False
#更新和升级的进度信息 0~100 进度信息 101为非预期的信号
@dbus.service.signal(INTERFACE,signature='is')
def UpdateDetectStatusChanged(self,progress,status):
logging.info("emit progress = %d , status = %s",progress,status)
@dbus.service.signal(INTERFACE,signature='basss')
def UpdateDetectFinished(self, success, data,error_string='',error_desc='',):
logging.info("emit success = %r , data = %a, error_string = %s , error_desc = %s ",success,data, error_string,error_desc)
pass
#信号 发射更新和升级的状态 #信号 发射更新和升级的状态
@dbus.service.signal(INTERFACE, signature='s') @dbus.service.signal(INTERFACE, signature='s')
@ -107,7 +116,3 @@ class UpdateManagerDbusController(dbus.service.Object):
logging.info("emit action = %d , success = %r , error_string = %s , error_desc = %s",action,success, error_string,error_desc) logging.info("emit action = %d , success = %r , error_string = %s , error_desc = %s",action,success, error_string,error_desc)
pass pass
#更新和升级的进度信息 0~101 进度信息
@dbus.service.signal(INTERFACE,signature='i')
def on_progress_changed_signal(self,progress):
pass

View File

@ -11,7 +11,9 @@ from aptdaemon import client, errors
from defer import inline_callbacks from defer import inline_callbacks
from aptdaemon.gtk3widgets import ( from aptdaemon.gtk3widgets import (
AptConfigFileConflictDialog, AptConfigFileConflictDialog,
AptMediumRequiredDialog) AptMediumRequiredDialog,
AptProgressBar
)
from aptdaemon.enums import (EXIT_SUCCESS, from aptdaemon.enums import (EXIT_SUCCESS,
EXIT_FAILED, EXIT_FAILED,
get_error_description_from_enum, get_error_description_from_enum,
@ -35,6 +37,9 @@ class InstallBackendAptdaemon(InstallBackend):
self._expanded_size = None self._expanded_size = None
self.trans_failed_msg = None self.trans_failed_msg = None
self.trans_progress = 0
self.trans_status = ''
@inline_callbacks @inline_callbacks
def update(self): def update(self):
"""刷新包cache""" """刷新包cache"""
@ -84,30 +89,32 @@ class InstallBackendAptdaemon(InstallBackend):
raise raise
def _on_progress_changed(self, trans, progress): def _on_progress_changed(self, trans, progress):
self.window_main.dbusController.on_progress_changed_signal(progress) self.trans_progress = progress
logging.debug(progress) self.window_main.dbusController.UpdateDetectStatusChanged(self.trans_progress,self.trans_status)
def _on_status_changed(self, trans, status):
self.trans_status = status
self.window_main.dbusController.UpdateDetectStatusChanged(self.trans_progress,self.trans_status)
def _on_details_changed(self, trans, details): def _on_details_changed(self, trans, details):
logging.info(details) logging.info(details)
def _on_status_changed(self, trans, status):
self.window_main.dbusController.status_changed_signal(status)
logging.info(status)
def _on_download_changed(self, trans, details): def _on_download_changed(self, trans, details):
logging.info(details) logging.info(details)
@inline_callbacks @inline_callbacks
def _show_transaction(self, trans, action, header, show_details): def _show_transaction(self, trans, action, header, show_details):
# progressbar = AptProgressBar(trans)
# trans.connect("status-details-changed", self._on_details_changed) # trans.connect("status-details-changed", self._on_details_changed)
#状态改变的时候的回调函数 #状态改变的时候的回调函数
trans.connect("status-changed", self._on_status_changed)
#update 更新完成的时候的回调 #update 更新完成的时候的回调
trans.connect("finished", self._on_finished, action) trans.connect("finished", self._on_finished, action)
# trans.connect("medium-required", self._on_medium_required) # trans.connect("medium-required", self._on_medium_required)
# trans.connect("progress-changed", self._on_progress_changed)
trans.connect("status-changed", self._on_status_changed)
trans.connect("progress-changed", self._on_progress_changed)
# trans.connect("download-changed", self._on_download_changed) # trans.connect("download-changed", self._on_download_changed)
@ -182,8 +189,7 @@ class InstallBackendAptdaemon(InstallBackend):
error_string = '' error_string = ''
error_desc = '' error_desc = ''
trans_failed = False trans_failed = False
logging.info(status)
if status == EXIT_FAILED: if status == EXIT_FAILED:
error_string = get_error_string_from_enum(trans.error.code) error_string = get_error_string_from_enum(trans.error.code)
error_desc = get_error_description_from_enum(trans.error.code) error_desc = get_error_description_from_enum(trans.error.code)
@ -191,10 +197,7 @@ class InstallBackendAptdaemon(InstallBackend):
trans_failed = True trans_failed = True
error_desc = error_desc + "\n" + self.trans_failed_msg error_desc = error_desc + "\n" + self.trans_failed_msg
is_success = (status == EXIT_SUCCESS) is_success = (status == EXIT_SUCCESS)
#安装或升级完成之后emit的信号
self.window_main.dbusController.on_finished_signal(action,is_success,error_string,error_desc)
try: try:
self._action_done(action, self._action_done(action,
authorized=True, success=is_success, authorized=True, success=is_success,

View File

@ -91,13 +91,13 @@ class InstallBackend():
pass pass
else: else:
self.window_main.is_updating = False self.window_main.is_updating = False
if error_string or error_desc: if success:
logging.warning(error_string + error_desc)
elif success:
self.window_main.start_available() self.window_main.start_available()
elif error_string or error_desc:
logging.warning(error_string + error_desc)
self.window_main.dbusController.UpdateDetectFinished(success,[],error_string,error_desc)
else: else:
pass self.window_main.dbusController.UpdateDetectFinished(success,[],'','')
# try aptdaemon # try aptdaemon
if os.path.exists("/usr/sbin/aptd") \ if os.path.exists("/usr/sbin/aptd") \

View File

@ -40,6 +40,5 @@ if __name__ == "__main__":
app.start_update() app.start_update()
Gtk.main() Gtk.main()