Merge branch 'dev' into 'master'

Dev

See merge request wangsong/kylin-system-updater!6
This commit is contained in:
王松 2021-10-08 02:55:19 +00:00
commit a6e9dbfdcb
10 changed files with 159 additions and 30 deletions

3
.gitignore vendored
View File

@ -13,6 +13,9 @@ debian/kylin-system-updater.postinst.debhelper
debian/kylin-system-updater.prerm.debhelper
debian/kylin-system-updater.substvars
po/kylin-system-updater.pot
system-updater.session.sql
build/scripts-3.8/
debian/files
# Misc
.*cache

View File

@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
import os
import re
import json
import shutil
import sqlite3
import logging
@ -18,7 +19,7 @@ class Sqlite3Server(object):
def __init__(self, window_main):
self.connect = None
self.window_main = window_main
logging.info("Init Sqlite3Server...")
logging.info(_("Init Sqlite3Server..."))
self.init_sqlit()
# 初始化连接数据库
@ -111,7 +112,7 @@ class Sqlite3Server(object):
logging.info(_("Data insertion complete ."))
# 接收更新列表与信息,生成数据并插入数据库中
def insert_info(self, lists, success, error_string, error_desc):
def insert_info(self, lists=[], success = '', error_string = '', error_desc = ''):
status = " "
update_lists = []
app_msg = {}
@ -126,7 +127,10 @@ class Sqlite3Server(object):
except Exception as e:
logging.error("_depcache error: %s", str(e))
for i in lists:
(pkgs_install,pkgs_upgrade,pkgs_remove) = self.refreshpkglist()
update_pkgs = list(set(pkgs_install).union(set(pkgs_upgrade)))
for i in update_pkgs:
try:
pkg = self.window_main.cache[i]
except Exception as e:
@ -136,10 +140,19 @@ class Sqlite3Server(object):
app_info['version'] = str(candidate)
app_info['description'] = str(pkg.candidate.raw_description)
app_info["icon"] = ""
if i in pkgs_upgrade:
app_info['action'] = str("Upgrade")
elif i in pkgs_install:
app_info['action'] = str("Install")
else:
app_info['action'] = ''
app_msg[i] = app_info.copy()
update_lists.append(app_msg.copy())
app_info.clear()
app_msg.clear()
else:
logging.warning("Cache is None.")
if success:
@ -154,8 +167,79 @@ class Sqlite3Server(object):
self.init_sqlit()
self.insert_into_updateinfo(updatesjson, timestr, status, "0", error_string)
def refreshpkglist(self):
pkgs_install = []
pkgs_upgrade = []
pkgs_remove = []
for pkg in self.window_main.cache:
try:
if pkg.marked_upgrade:
pkgs_upgrade.append(pkg.name)
elif pkg.marked_delete:
pkgs_remove.append(pkg.name)
except KeyError:
# pkg missing from fresh_cache can't be modified
pass
return pkgs_install,pkgs_upgrade,pkgs_remove
#查找数据库
def find_msg_from_datebase(self, action = 'check',table = 'updateinfos', cid = 0):
# 查询table
try:
self.cursor.execute("select sql from sqlite_master")
count_tables = 0
while True:
all_table = self.cursor.fetchone()
if all_table == None:
break
tmpstr = str(all_table)
if ("sqlite_sequence") in tmpstr or '(None,)' in tmpstr:
continue
else:
# logging.info(tmpstr)
count_tables = count_tables + 1
pass
logging.info("%d tables were found.", count_tables)
except Exception as e:
logging.error("Check tables error: %s", str(e))
# 检测历史更新升级
try:
sql = "SELECT COUNT(*) FROM updateinfos "
self.cursor.execute(sql)
update_count = self.cursor.fetchone()[0]
logging.info("%d history updates detected.", update_count)
except Exception as e:
logging.error("Check update error: %s", str(e))
# 获取第cid次更新
if cid != 0 and cid > 0:
sql = "SELECT * FROM updateinfos where id='"+str(cid-1)+"'"
try:
self.cursor.execute(sql)
update_count = self.cursor.fetchone()
logging.info("\n\n### Update %d =============>\n### date:%s\n### status:%s\n### keyword:%s\n### errorcode:%s", \
update_count[0]+1, \
update_count[2], \
update_count[3], \
update_count[4], \
update_count[5])
updatelists = json.loads(update_count[1])
logging.info("update_lists: ------------------------>")
for i in updatelists:
for key in i:
logging.info("package name:\n[ %s ].\n----- version: %s\n----- description: %s\n----- icon: %s\n----- action: %s\n", \
key, \
i[key]['version'], \
i[key]['description'], \
i[key]['icon'], \
i[key]['action'])
print("\n")
except Exception as e:
logging.error("Get update error: %s", str(e))
def listtojsonstr(lists):
import json
jsonfile = json.dumps(lists)
return jsonfile
return jsonfile

View File

@ -37,7 +37,7 @@ import random
import glob
import json
from gi.repository import Gio
import yaml
from SystemUpdater.Core import utils
from SystemUpdater.Core import filter
@ -513,12 +513,12 @@ class UpdateList():
group_important_list.append(pkg_name)
logging.info("pkg_important_list: %a, group_important_list:%a",pkg_important_list,group_important_list)
return True,group_important_list,pkg_important_list
return True,group_important_list,pkg_important_list,header,desc
except Exception as e:
header = _("read important list failed")
desc = ("%s",str(e))
desc = str(e)
logging.error(header + desc)
return False,[],[]
return False,group_important_list,pkg_important_list,header,desc
def _make_pkg_info_json(self,cache,pkgs_list):
total_download_size = 0
@ -561,7 +561,7 @@ class UpdateList():
# logging.info("this package(%s) not in list ",pkg_name)
return new_pkgs_list
def _make_group_output_json(self,data,upgrade_pkgs_json,install_pkgs_json,hold_pkgs_list,remove_pkgs_list):
def _make_group_output_json(self,data,data_yaml,upgrade_pkgs_json,install_pkgs_json):
groups_base_info = {}
output_json = {}
@ -574,13 +574,16 @@ class UpdateList():
groups_base_info.update({"name":data['name']})
groups_base_info.update({"description":data['description']})
groups_base_info.update({"icon":data['icon']})
#添加读yaml文件
groups_base_info.update({"changelog":data_yaml['changelog']})
#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})
# 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:
@ -592,22 +595,35 @@ class UpdateList():
files = os.listdir(self.INPUT_CONFIG_PATH) #获得文件夹中所有文件的名称列表
upgrade_groups_list = []
for file in files:
for ifile in files:
#判是否是目录以及是否以JSON结尾
if file.endswith('.json'):
with open(self.INPUT_CONFIG_PATH+"/"+file,'r') as f:
data = json.load(f)
if ifile.endswith('.json'):
#读取组JSON文件
with open(self.INPUT_CONFIG_PATH+"/"+ifile,'r') as f:
try:
data = json.load(f)
except json.JSONDecodeError as exc:
logging.error(exc)
continue
group_name = data['package']
#读取组的yaml 文件的changelog的信息
with open(self.INPUT_CONFIG_PATH + "/" + group_name + ".yaml", "r") as stream:
try:
data_yaml = yaml.safe_load(stream)
except yaml.YAMLError as exc:
logging.error(exc)
continue
#过滤没有推送的配置文件
if not group_name in group_list:
continue
upgrade_pkgs_list = data['upgrade_list']
hold_pkgs_list = data['hold_list']
# hold_pkgs_list = data['hold_list']
#这个安装升级列表中包含当前系统的cache中没有的包 需要过滤
remove_pkgs_list = data['remove_list']
# remove_pkgs_list = data['remove_list']
#检查包是否在cache中 以及是否已经安装 没有安装的话才添加到列表
new_install_pkgs_list = self._check_pkg_in_cache(cache,data['install_list'])
@ -630,7 +646,7 @@ class UpdateList():
install_pkgs_json = self._make_pkg_info_json(cache,new_install_pkgs_list)
#输出JSON配置文件
self._make_group_output_json(data,upgrade_pkgs_json,install_pkgs_json,hold_pkgs_list,remove_pkgs_list)
self._make_group_output_json(data,data_yaml,upgrade_pkgs_json,install_pkgs_json)
upgrade_groups_list.append(group_name)
@ -681,16 +697,20 @@ class UpdateList():
# fu = filter.UpdateListFilterCache()
# allowed_origin_upgrade_pkgs = fu.check_in_allowed_origin(pkgs_upgrade)
success,group_important_list,pkg_important_list = self._read_important_list(cache,pkgs_upgrade)
success,group_important_list,pkg_important_list,header,desc = self._read_important_list(cache,pkgs_upgrade)
#important_list 为空时此次不需要升级
if not group_important_list and not pkg_important_list:
if success == True and not group_important_list and not pkg_important_list:
#不需要升级 全部的软件都是新的
header = _("No software updates are available.")
desc = _('important_list is Empty')
return True,header,desc
self._make_groups_upgrade(cache,group_list = group_important_list,pkgs_upgrade = ([pkg.name for pkg in pkgs_upgrade]))
elif success == False:
return False,header,desc
#分组的包的JSON
self._make_groups_upgrade(cache,group_important_list,[pkg.name for pkg in pkgs_upgrade])
#产生单包的JSON
self._make_single_upgrade(cache,pkg_important_list)
#是否存在可升级的组

View File

@ -60,7 +60,7 @@ class UpdateListFilterCache(apt.Cache):
self.allowed_origins = get_allowed_origins()
self.allowed_origins = deleteDuplicatedElementFromList(self.allowed_origins)
logging.info("Allowed origins are: %s",
logging.info(_("Allowed origins are: %s"),
self.allowed_origins)
self.blacklist = apt_pkg.config.value_list(

View File

@ -291,5 +291,5 @@ class UpdateManager():
except dbus.DBusException:
bus_name = dbus.service.BusName('com.kylin.systemupgrade',
bus)
logging.info('initiate dbus success ...')
logging.info(_("initiate dbus success ..."))
return UpdateManagerDbusController(self, bus_name)

View File

@ -184,6 +184,17 @@ class UpdateManagerDbusController(dbus.service.Object):
logging.error(False, str(e))
return (False, str(e))
# 操作数据库的接口
@dbus.service.method(INTERFACE, out_signature='b')
def DataBaseOpt(self, action='check',table='', cid=19):
if action == 'check':
try:
self.parent.sqlite3_server.find_msg_from_datebase(action, table, cid)
except Exception as e:
logging.error(str(e))
return False
return True
#更新进度信息 0~100 进度信息 101为非预期的信号
@dbus.service.signal(INTERFACE,signature='is')
def UpdateDetectStatusChanged(self,progress,status):

View File

@ -77,8 +77,10 @@ class InstallBackend():
for pkg in pkgs_upgrade:
self.window_main.cache[pkg].mark_upgrade()
Fix.resolve(True)
#会安装新包和卸载包
Fix.resolve()
#不会安装和卸载 只升级
# Fix.resolve_by_keep()
logging.info("Complete calculation of dependencies...")
new_pkgs_install = []
@ -148,9 +150,9 @@ class InstallBackend():
if action == self.ACTION_INSTALL:
self.window_main.is_upgrading = False
# 信息插入数据库...
# self.window_main.sqlite3_server.insert_info(\
# self.window_main.tmplist, success, \
# error_string, error_desc)
self.window_main.sqlite3_server.insert_info(\
[""], success, \
error_string, error_desc)
if success:
#当组列表为空时 表示现在的单独进行安装某些包或卸载,不发信号到控制面板
if self.now_upgrade_list:

6
debian/changelog vendored
View File

@ -1,3 +1,9 @@
kylin-system-updater (1.1.2kord) v101; urgency=medium
* 增加数据库接口 .
-- luoxueyi <luoxueyi@kylinos.cn> Wed, 29 Sep 2021 17:13:31 +0800
kylin-system-updater (1.1.1kord) v101; urgency=medium
* add database .

2
debian/postinst vendored
View File

@ -7,5 +7,7 @@ if [ ! -f /var/cache/kylin-system-updater/kylin-system-updater.db ];then
cp -r /usr/share/kylin-system-updater/kylin-system-updater.db /var/cache/kylin-system-updater/
fi
cp -r /usr/share/kylin-system-updater/kylin-system-updater.db /var/cache/kylin-system-updater/
systemctl enable kylin-system-updater
systemctl start kylin-system-updater

View File

@ -5,4 +5,5 @@ SystemUpdater/UpdateManager.py
SystemUpdater/Core/MyCache.py
SystemUpdater/Core/UpdateList.py
SystemUpdater/Core/filter.py
kylin-system-updater
SystemUpdater/Core/Database.py
SystemUpdater/UpdateManagerDbus.py