修改逻辑 将部分代码改变位置
This commit is contained in:
parent
6f5a03b4a1
commit
6b1afb4776
|
@ -214,12 +214,12 @@ class UpdateList():
|
|||
self.update_groups = []
|
||||
self.random = random.Random()
|
||||
|
||||
#新安装的包列表
|
||||
self.pkgs_install = []
|
||||
#要升级的包列表
|
||||
self.pkgs_upgrade = []
|
||||
#需要移除的包列表
|
||||
self.pkgs_remove = []
|
||||
# #新安装的包列表
|
||||
# self.pkgs_install = []
|
||||
# #要升级的包列表
|
||||
# self.pkgs_upgrade = []
|
||||
# #需要移除的包列表
|
||||
# self.pkgs_remove = []
|
||||
|
||||
#FIXME: 最好将这个常量通过配置文件读
|
||||
self.GROUPS_JSON_PKG = 'kylin-update-desktop-config'
|
||||
|
@ -227,6 +227,9 @@ class UpdateList():
|
|||
self.INPUT_CONFIG_PATH = '/usr/share/kylin-update-desktop-config/data'
|
||||
self.OUTPUT_CONFIG_PATH = os.getenv('HOME') + '/.config' +'/update_manager_config'
|
||||
|
||||
self.IMPORTANT_LIST_PATH="/var/lib/kylin-software-properties/template/important.list"
|
||||
|
||||
self.important_list = []
|
||||
# a stable machine uniq id
|
||||
try:
|
||||
with open(self.UNIQ_MACHINE_ID_FILE) as f:
|
||||
|
@ -492,7 +495,19 @@ class UpdateList():
|
|||
|
||||
return app_groups + pkg_groups
|
||||
|
||||
def _make_json(self,cache,pkgs_install, pkgs_upgrade, pkgs_remove):
|
||||
def _read_important_list(self):
|
||||
# 获取importantlist 本次更新推送
|
||||
try:
|
||||
with open(self.IMPORTANT_LIST_PATH, 'r') as f:
|
||||
data = f.read()
|
||||
self.important_list = data.split()
|
||||
logging.info("importantList: %s",self.important_list)
|
||||
return True
|
||||
except Exception as e:
|
||||
logging.info("read important list failed becauce: %s",e)
|
||||
return False
|
||||
|
||||
def _make_json(self,cache,pkgs_install = [], pkgs_upgrade = [], pkgs_remove = []):
|
||||
try:
|
||||
files = os.listdir(self.INPUT_CONFIG_PATH) #获得文件夹中所有文件的名称列表
|
||||
for file in files:
|
||||
|
@ -500,7 +515,7 @@ class UpdateList():
|
|||
if not os.path.isdir(file) and file.endswith('.json'):
|
||||
with open(self.INPUT_CONFIG_PATH+"/"+file,'r') as f:
|
||||
data = json.load(f)
|
||||
|
||||
|
||||
output_json = {}
|
||||
#FIXME: 确定输出文件的文件名 以及放置位置
|
||||
output_config_name = self.OUTPUT_CONFIG_PATH + '/' + data['package'] + '_output.json'
|
||||
|
@ -579,17 +594,6 @@ class UpdateList():
|
|||
output_json.update({"hold_list":hold_pkgs_list})
|
||||
output_json.update({"remove_list":remove_pkgs_list})
|
||||
|
||||
#判断目录是否存在不存在创建 存在时删除 再创建 清空上次产生的文件 保持最新
|
||||
#FIXME: 使用直接将目录删除的办法 或者使用清除目录下的文件的方法
|
||||
try:
|
||||
if not os.path.exists(self.OUTPUT_CONFIG_PATH):
|
||||
os.makedirs(self.OUTPUT_CONFIG_PATH)
|
||||
else:
|
||||
shutil.rmtree(self.OUTPUT_CONFIG_PATH)
|
||||
os.makedirs(self.OUTPUT_CONFIG_PATH)
|
||||
except Exception as e:
|
||||
logging.warning(e)
|
||||
|
||||
#6 产生JSON文件
|
||||
with open(output_config_name, 'w', encoding='utf-8') as f:
|
||||
json.dump(output_json, f, ensure_ascii=False, indent=4)
|
||||
|
@ -602,35 +606,32 @@ class UpdateList():
|
|||
|
||||
|
||||
def update(self, cache, eventloop_callback=None):
|
||||
self.held_back = []
|
||||
upgrade_pkgs = []
|
||||
|
||||
pkgs_install = []
|
||||
pkgs_upgrade = []
|
||||
pkgs_remove = []
|
||||
#查找所有可升级的包
|
||||
for pkg in cache:
|
||||
try:
|
||||
if pkg.marked_install:
|
||||
pkgname = pkg.name
|
||||
if pkg.is_auto_installed:
|
||||
pkgname += "#auto"
|
||||
self.pkgs_install.append(pkgname)
|
||||
# pkgname = pkg.name
|
||||
# if pkg.is_auto_installed:
|
||||
# pkgname += "#auto"
|
||||
pkgs_install.append(pkg)
|
||||
elif pkg.marked_upgrade:
|
||||
upgrade_pkgs.append(pkg)
|
||||
self.pkgs_upgrade.append(pkg.name)
|
||||
pkgs_upgrade.append(pkg)
|
||||
elif pkg.marked_delete:
|
||||
self.pkgs_remove.append(pkg.name)
|
||||
pkgs_remove.append(pkg)
|
||||
except Exception as e:
|
||||
logging.error(e)
|
||||
return False
|
||||
logging.info("Find all upgradeable packages finished...")
|
||||
logging.info("Find all upgradeable packages finished...")
|
||||
|
||||
fu = filter.UpdateListFilterCache()
|
||||
|
||||
#源过滤
|
||||
allowed_origin_upgrade_pkgs = fu.check_in_allowed_origin(upgrade_pkgs)
|
||||
whitelist_filter_upgrade_pkgs = fu.is_pkgname_in_whitelist(allowed_origin_upgrade_pkgs)
|
||||
|
||||
pass
|
||||
self._make_json(cache,self.pkgs_install,self.pkgs_upgrade,self.pkgs_remove)
|
||||
#源过滤 and 白名单过滤
|
||||
# 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]))
|
||||
|
||||
|
||||
#FIXME: 目前此功能不使用 但是以此按应用进行分组是更好的展示升级列表的方式
|
||||
|
|
|
@ -97,10 +97,10 @@ class UpdateListFilterCache(apt.Cache):
|
|||
# initUpdateImportantList()
|
||||
|
||||
# 获取list
|
||||
self.initLocalPackagesList()
|
||||
# self.initLocalPackagesList()
|
||||
|
||||
#除掉不在cache中的包
|
||||
self.checkInCache()
|
||||
# self.checkInCache()
|
||||
|
||||
def checkInCache(self):
|
||||
logging.info("start Check in cache")
|
||||
|
@ -343,20 +343,6 @@ def deleteDuplicatedElementFromList(list):
|
|||
resultList.append(item)
|
||||
return resultList
|
||||
|
||||
def initUpdateImportantList():
|
||||
lock = threading.Lock()
|
||||
bus = dbus.SystemBus()
|
||||
try:
|
||||
obj = bus.get_object('com.kylin.software.properties', '/com/kylin/software/properties')
|
||||
interface = dbus.Interface(obj, dbus_interface='com.kylin.software.properties.interface')
|
||||
lock.acquire()
|
||||
retval = interface.updateSourceTemplate()
|
||||
lock.release()
|
||||
except Exception as e:
|
||||
logging.error("initUpdateImportantList: %s"%str(e))
|
||||
if retval == False:
|
||||
logging.info("updateSourceTemplate failed")
|
||||
print("\nupdate SourceTemplate\n")
|
||||
|
||||
class UnknownMatcherError(ValueError):
|
||||
pass
|
|
@ -14,6 +14,7 @@ from gettext import gettext as _
|
|||
import os
|
||||
import apt_pkg
|
||||
import dbus
|
||||
import shutil
|
||||
import dbus.service
|
||||
from dbus.mainloop.glib import DBusGMainLoop
|
||||
DBusGMainLoop(set_as_default=True)
|
||||
|
@ -165,13 +166,13 @@ class UpdateManager():
|
|||
|
||||
self.update_list = UpdateList(self)
|
||||
|
||||
'''
|
||||
'''1、
|
||||
dist-upgrade 标记在此处进行
|
||||
来判断将要删除的包 如果存在要删除的break的包的话 会从dist-upgrade切换到upgrade 目前此功能不使用 默认使用dist-upgrade
|
||||
'''
|
||||
self.distUpgradeWouldDelete = self.cache.saveDistUpgrade()
|
||||
|
||||
#安装JSON分组配置文件包 安装完毕会重新调start_available --> here 安装失败就直接退出不会进行下面的操作
|
||||
#2、 安装JSON分组配置文件包 安装完毕会重新调start_available --> here 安装失败就直接退出不会进行下面的操作
|
||||
try:
|
||||
pkg_json = self.cache[self.update_list.GROUPS_JSON_PKG]
|
||||
#是否安装
|
||||
|
@ -195,7 +196,7 @@ class UpdateManager():
|
|||
logging.error(e)
|
||||
_success = False
|
||||
|
||||
#判断目录是JSON配置文件夹是否缺失 缺失后进行修复 卸载重新安装步骤
|
||||
#3、 判断目录是JSON配置文件夹是否缺失 缺失后进行修复 卸载重新安装步骤
|
||||
if not os.path.exists(self.update_list.INPUT_CONFIG_PATH):
|
||||
logging.info("groups JSON Config Path(%s) Missing and Trying to fix...",self.update_list.INPUT_CONFIG_PATH)
|
||||
#将软件包卸载 之后进行重新安装here --> purge --> start_available 进行判断是否安装未安装重新安装
|
||||
|
@ -203,20 +204,41 @@ class UpdateManager():
|
|||
#直接退出
|
||||
return
|
||||
|
||||
#FIXME: 待开发功能 根据监测存在配置文件 不存在进行重新安装包 再检测还是未存在的话 就判断此次没有可升级的
|
||||
|
||||
|
||||
#4、 清空上次输出的分组JSON文件
|
||||
try:
|
||||
_success = self.update_list.update(self.cache)
|
||||
except SystemError as e:
|
||||
header = _("Could not calculate the upgrade")
|
||||
desc = _("An unresolvable problem occurred while "
|
||||
"calculating the upgrade.\n\n"
|
||||
"Please report this bug against the 'update-manager' "
|
||||
"package and include the following error "
|
||||
"message:\n") + str(e)
|
||||
_success = False
|
||||
if not os.path.exists(self.update_list.OUTPUT_CONFIG_PATH):
|
||||
os.makedirs(self.update_list.OUTPUT_CONFIG_PATH)
|
||||
logging.info('making the configuration file is complete...')
|
||||
else:
|
||||
shutil.rmtree(self.update_list.OUTPUT_CONFIG_PATH)
|
||||
os.makedirs(self.update_list.OUTPUT_CONFIG_PATH)
|
||||
logging.info('Emptying the configuration file is complete...')
|
||||
except Exception as e:
|
||||
logging.warning(e)
|
||||
|
||||
#FIXME: 5、 待开发功能 根据监测存在配置文件 不存在进行重新安装包 再检测还是未存在的话 就判断此次没有可升级的
|
||||
|
||||
#FIXME: 6、 出错后未进行处理 更新important.list 文件错误的话
|
||||
# self.dbusController._on_update_important_list()
|
||||
|
||||
self.update_list._read_important_list()
|
||||
|
||||
#important_list 为空时此次不需要升级
|
||||
if self.update_list.important_list:
|
||||
try:
|
||||
_success = self.update_list.update(self.cache)
|
||||
except SystemError as e:
|
||||
header = _("Could not calculate the upgrade")
|
||||
desc = _("An unresolvable problem occurred while "
|
||||
"calculating the upgrade.\n\n"
|
||||
"Please report this bug against the 'update-manager' "
|
||||
"package and include the following error "
|
||||
"message:\n") + str(e)
|
||||
_success = False
|
||||
else:
|
||||
header = _("No upgrade required")
|
||||
desc = _("important.list list is empty")
|
||||
|
||||
#发送更新升级列表完成的标志
|
||||
self.dbusController.on_finished_signal(self.ACTION_UPDATE_LIST,_success,header,desc)
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
import dbus
|
||||
import dbus.service
|
||||
import logging
|
||||
import threading
|
||||
|
||||
from .Core.AlertWatcher import AlertWatcher
|
||||
from .Core.roam import NetworkManagerHelper
|
||||
|
@ -24,6 +25,27 @@ class UpdateManagerDbusController(dbus.service.Object):
|
|||
self.alert_watcher.connect("network-alert", self._on_network_alert)
|
||||
self.connected = False
|
||||
|
||||
#更新important.list的本次升级的列表
|
||||
def _on_update_important_list(self):
|
||||
lock = threading.Lock()
|
||||
bus = dbus.SystemBus()
|
||||
try:
|
||||
obj = bus.get_object('com.kylin.software.properties', '/com/kylin/software/properties')
|
||||
interface = dbus.Interface(obj, dbus_interface='com.kylin.software.properties.interface')
|
||||
lock.acquire()
|
||||
retval = interface.updateSourceTemplate()
|
||||
lock.release()
|
||||
except Exception as e:
|
||||
logging.error("update sourceTemplate Failed and Error mes:%s"%str(e))
|
||||
return False
|
||||
|
||||
if retval == False:
|
||||
logging.warning("update SourceTemplate failed")
|
||||
return False
|
||||
else:
|
||||
logging.info("update sourceTemplate successed...")
|
||||
return True
|
||||
|
||||
#检测网络的状态
|
||||
def _on_network_alert(self, watcher, state):
|
||||
if state in NetworkManagerHelper.NM_STATE_CONNECTED_LIST:
|
||||
|
@ -63,23 +85,6 @@ class UpdateManagerDbusController(dbus.service.Object):
|
|||
except Exception:
|
||||
return False
|
||||
|
||||
#返回下载大小 humanize_type=true时 返回字符串
|
||||
@dbus.service.method(INTERFACE,in_signature='b')
|
||||
def total_download_size(self,humanize_type = False):
|
||||
try:
|
||||
#只有当拿到cache时才能获取大小
|
||||
if self.parent.cache:
|
||||
dl = self.parent.cache.required_download
|
||||
#增加返回可读方式接口
|
||||
if humanize_type:
|
||||
return humanize_size(dl)
|
||||
else:
|
||||
return dl
|
||||
else:
|
||||
return False
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
#信号 发射更新和升级的状态
|
||||
@dbus.service.signal(INTERFACE, signature='s')
|
||||
def status_changed_signal(self, message):
|
||||
|
|
Loading…
Reference in New Issue