修改信号的传输方式
This commit is contained in:
parent
6b1afb4776
commit
de8d83b6c3
|
@ -230,6 +230,8 @@ class UpdateList():
|
|||
self.IMPORTANT_LIST_PATH="/var/lib/kylin-software-properties/template/important.list"
|
||||
|
||||
self.important_list = []
|
||||
|
||||
self.output_upgrade_list = []
|
||||
# a stable machine uniq id
|
||||
try:
|
||||
with open(self.UNIQ_MACHINE_ID_FILE) as f:
|
||||
|
@ -511,11 +513,17 @@ class UpdateList():
|
|||
try:
|
||||
files = os.listdir(self.INPUT_CONFIG_PATH) #获得文件夹中所有文件的名称列表
|
||||
for file in files:
|
||||
|
||||
#判是否是目录以及是否以JSON结尾
|
||||
if not os.path.isdir(file) and file.endswith('.json'):
|
||||
with open(self.INPUT_CONFIG_PATH+"/"+file,'r') as f:
|
||||
data = json.load(f)
|
||||
|
||||
|
||||
#过滤没有推送的配置文件
|
||||
if not data['package'] in self.important_list:
|
||||
continue
|
||||
|
||||
groups_base_info = {}
|
||||
output_json = {}
|
||||
#FIXME: 确定输出文件的文件名 以及放置位置
|
||||
output_config_name = self.OUTPUT_CONFIG_PATH + '/' + data['package'] + '_output.json'
|
||||
|
@ -582,22 +590,27 @@ class UpdateList():
|
|||
pass
|
||||
|
||||
#4、添加一些基础信息
|
||||
output_json.update({"package":data['package']})
|
||||
output_json.update({"version":data['version']})
|
||||
output_json.update({"name":data['name']})
|
||||
output_json.update({"description":data['description']})
|
||||
output_json.update({"icon":data['icon']})
|
||||
groups_base_info.update({"package":data['package']})
|
||||
groups_base_info.update({"version":data['version']})
|
||||
groups_base_info.update({"name":data['name']})
|
||||
groups_base_info.update({"description":data['description']})
|
||||
groups_base_info.update({"icon":data['icon']})
|
||||
|
||||
#5、添加升级的内容
|
||||
output_json.update(groups_base_info)
|
||||
output_json.update({"upgrade_list":upgrade_pkgs_json})
|
||||
output_json.update({"install_list":install_pkgs_json})
|
||||
output_json.update({"hold_list":hold_pkgs_list})
|
||||
output_json.update({"remove_list":remove_pkgs_list})
|
||||
|
||||
|
||||
#6 产生JSON文件
|
||||
with open(output_config_name, 'w', encoding='utf-8') as f:
|
||||
json.dump(output_json, f, ensure_ascii=False, indent=4)
|
||||
logging.info("Generate Jsonfile(%s) to complete... ",output_config_name)
|
||||
|
||||
#添加到输出升级列表
|
||||
self.output_upgrade_list.append(data['package'])
|
||||
else:
|
||||
pass
|
||||
except Exception as e:
|
||||
|
@ -627,11 +640,11 @@ class UpdateList():
|
|||
logging.info("Find all upgradeable packages finished...")
|
||||
|
||||
#源过滤 and 白名单过滤
|
||||
# fu = filter.UpdateListFilterCache()
|
||||
# allowed_origin_upgrade_pkgs = fu.check_in_allowed_origin(pkgs_upgrade)
|
||||
fu = filter.UpdateListFilterCache()
|
||||
allowed_origin_upgrade_pkgs = fu.check_in_allowed_origin(pkgs_upgrade)
|
||||
# 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: 目前此功能不使用 但是以此按应用进行分组是更好的展示升级列表的方式
|
||||
|
|
|
@ -180,8 +180,8 @@ class UpdateListFilterCache(apt.Cache):
|
|||
for v in pkg.versions:
|
||||
if is_in_allowed_origin(v, self.allowed_origins) and not pkg in new_upgrade_pkgs:
|
||||
new_upgrade_pkgs.append(pkg)
|
||||
else:
|
||||
pkg.mark_keep()
|
||||
# else:
|
||||
# pkg.mark_keep()
|
||||
return new_upgrade_pkgs
|
||||
|
||||
def is_pkgname_in_blacklist(self, pkgs):
|
||||
|
|
|
@ -240,7 +240,7 @@ class UpdateManager():
|
|||
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):
|
||||
""" this sets up a dbus listener if none is installed already """
|
||||
|
|
|
@ -57,7 +57,7 @@ class UpdateManagerDbusController(dbus.service.Object):
|
|||
|
||||
#更新的dbus
|
||||
@dbus.service.method(INTERFACE)
|
||||
def update(self):
|
||||
def UpdateDetect(self):
|
||||
try:
|
||||
#处于更新和升级中的话 不进行更新
|
||||
if self.parent.is_updating or self.parent.is_upgrading:
|
||||
|
@ -72,7 +72,7 @@ class UpdateManagerDbusController(dbus.service.Object):
|
|||
|
||||
#升级的dbus
|
||||
@dbus.service.method(INTERFACE)
|
||||
def upgrade(self):
|
||||
def UpgradeSystem(self):
|
||||
try:
|
||||
#处于更新和升级中的话 不进行升级
|
||||
if self.parent.is_updating or self.parent.is_upgrading:
|
||||
|
@ -84,6 +84,15 @@ class UpdateManagerDbusController(dbus.service.Object):
|
|||
return True
|
||||
except Exception:
|
||||
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')
|
||||
|
@ -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)
|
||||
pass
|
||||
|
||||
#更新和升级的进度信息 0~101 进度信息
|
||||
@dbus.service.signal(INTERFACE,signature='i')
|
||||
def on_progress_changed_signal(self,progress):
|
||||
pass
|
|
@ -11,7 +11,9 @@ from aptdaemon import client, errors
|
|||
from defer import inline_callbacks
|
||||
from aptdaemon.gtk3widgets import (
|
||||
AptConfigFileConflictDialog,
|
||||
AptMediumRequiredDialog)
|
||||
AptMediumRequiredDialog,
|
||||
AptProgressBar
|
||||
)
|
||||
from aptdaemon.enums import (EXIT_SUCCESS,
|
||||
EXIT_FAILED,
|
||||
get_error_description_from_enum,
|
||||
|
@ -35,6 +37,9 @@ class InstallBackendAptdaemon(InstallBackend):
|
|||
self._expanded_size = None
|
||||
self.trans_failed_msg = None
|
||||
|
||||
self.trans_progress = 0
|
||||
self.trans_status = ''
|
||||
|
||||
@inline_callbacks
|
||||
def update(self):
|
||||
"""刷新包cache"""
|
||||
|
@ -84,30 +89,32 @@ class InstallBackendAptdaemon(InstallBackend):
|
|||
raise
|
||||
|
||||
def _on_progress_changed(self, trans, progress):
|
||||
self.window_main.dbusController.on_progress_changed_signal(progress)
|
||||
logging.debug(progress)
|
||||
self.trans_progress = 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):
|
||||
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):
|
||||
logging.info(details)
|
||||
|
||||
@inline_callbacks
|
||||
def _show_transaction(self, trans, action, header, show_details):
|
||||
|
||||
# progressbar = AptProgressBar(trans)
|
||||
# trans.connect("status-details-changed", self._on_details_changed)
|
||||
#状态改变的时候的回调函数
|
||||
trans.connect("status-changed", self._on_status_changed)
|
||||
|
||||
#update 更新完成的时候的回调
|
||||
trans.connect("finished", self._on_finished, action)
|
||||
# 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)
|
||||
|
||||
|
@ -182,8 +189,7 @@ class InstallBackendAptdaemon(InstallBackend):
|
|||
error_string = ''
|
||||
error_desc = ''
|
||||
trans_failed = False
|
||||
|
||||
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)
|
||||
|
@ -191,10 +197,7 @@ class InstallBackendAptdaemon(InstallBackend):
|
|||
trans_failed = True
|
||||
error_desc = error_desc + "\n" + self.trans_failed_msg
|
||||
is_success = (status == EXIT_SUCCESS)
|
||||
|
||||
#安装或升级完成之后emit的信号
|
||||
self.window_main.dbusController.on_finished_signal(action,is_success,error_string,error_desc)
|
||||
|
||||
|
||||
try:
|
||||
self._action_done(action,
|
||||
authorized=True, success=is_success,
|
||||
|
|
|
@ -91,13 +91,13 @@ class InstallBackend():
|
|||
pass
|
||||
else:
|
||||
self.window_main.is_updating = False
|
||||
if error_string or error_desc:
|
||||
logging.warning(error_string + error_desc)
|
||||
elif success:
|
||||
if success:
|
||||
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:
|
||||
pass
|
||||
|
||||
self.window_main.dbusController.UpdateDetectFinished(success,[],'','')
|
||||
|
||||
# try aptdaemon
|
||||
if os.path.exists("/usr/sbin/aptd") \
|
||||
|
|
|
@ -40,6 +40,5 @@ if __name__ == "__main__":
|
|||
app.start_update()
|
||||
Gtk.main()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue