Merge branch 'backend_manual' of gitlab2.kylin.com:kylin-desktop/update-manager-group/kylin-system-updater into backend_manual
This commit is contained in:
commit
2423d9d882
|
@ -13,6 +13,7 @@ from gettext import gettext as _
|
|||
from sys import exec_prefix
|
||||
from SystemUpdater.Core.DataAcquisition import PHPSeverSend
|
||||
from SystemUpdater.Core.UpdaterConfigParser import UpgradeConfig
|
||||
from SystemUpdater.Core.utils import get_config_patch
|
||||
|
||||
import apt_pkg
|
||||
from ..backend import InstallBackend
|
||||
|
@ -25,6 +26,7 @@ class Sqlite3Server(object):
|
|||
def __init__(self, window_main):
|
||||
self.connect = None
|
||||
self.window_main = window_main
|
||||
self.config_path = get_config_patch()
|
||||
logging.info(_("Init Sqlite3Server..."))
|
||||
self.init_sqlit()
|
||||
|
||||
|
@ -219,7 +221,7 @@ class Sqlite3Server(object):
|
|||
|
||||
#FIXME: 临时方案 PHP
|
||||
PHPSeverSend(_send_log = self.window_main.configs_uncover.getWithDefault("SystemStatus", "upload_upgrade_log", False), _appname=pkgname, _appversion=pkgversion, _statue=status, _errorcode="10000100")
|
||||
with open(self.window_main.config_path + str(pkgname) + ".yaml", "r") as stream:
|
||||
with open(self.config_path + str(pkgname) + ".yaml", "r") as stream:
|
||||
try:
|
||||
data_yaml = yaml.safe_load(stream)
|
||||
changeLog = data_yaml['changelog']
|
||||
|
@ -353,7 +355,7 @@ class Sqlite3Server(object):
|
|||
#FIXME: 临时方案 PHP
|
||||
PHPSeverSend(_send_log = self.window_main.configs_uncover.getWithDefault("SystemStatus", "upload_upgrade_log", False), _appname=i, _appversion=pkgversion, _statue=status, _errorcode="10000100")
|
||||
|
||||
with open(self.window_main.config_path + str(i) + ".yaml", "r") as stream:
|
||||
with open(self.config_path + str(i) + ".yaml", "r") as stream:
|
||||
try:
|
||||
data_yaml = yaml.safe_load(stream)
|
||||
changeLog = data_yaml['changelog']
|
||||
|
@ -389,10 +391,10 @@ class Sqlite3Server(object):
|
|||
# 获取group信息
|
||||
def GetGroupmsg(self, appname):
|
||||
jsonfile = appname+".json"
|
||||
files = os.listdir(self.window_main.config_path) #获取文件夹中所有文件
|
||||
files = os.listdir(self.config_path) #获取文件夹中所有文件
|
||||
if jsonfile in files: # 存在
|
||||
# 读取组JSON文件
|
||||
with open(self.window_main.config_path+jsonfile, "r") as f:
|
||||
with open(self.config_path+jsonfile, "r") as f:
|
||||
try :
|
||||
data = json.load(f)
|
||||
except json.JSONDecodeError as e:
|
||||
|
@ -493,7 +495,7 @@ class Sqlite3Server(object):
|
|||
def get_default_version(self):
|
||||
update_version = ""
|
||||
os_version = ""
|
||||
INPUT_CONFIG_PATH = self.window_main.config_path + 'kylin-update-desktop-system.json'
|
||||
INPUT_CONFIG_PATH = self.config_path + 'kylin-update-desktop-system.json'
|
||||
if os.path.isfile(INPUT_CONFIG_PATH): # 存在
|
||||
# 读取JSON文件
|
||||
with open(INPUT_CONFIG_PATH, "r") as f:
|
||||
|
|
|
@ -28,6 +28,7 @@ from gettext import gettext as _
|
|||
|
||||
import apt
|
||||
import apt_pkg
|
||||
from SystemUpdater.Core.utils import get_config_patch
|
||||
|
||||
ImportantListPath="/var/lib/kylin-software-properties/template/important.list"
|
||||
SOURCESLIST = "/etc/apt/sources.list"
|
||||
|
@ -55,7 +56,9 @@ class UpdateListFilterCache(apt.Cache):
|
|||
self.upgradeList = []
|
||||
# 必须升级的包
|
||||
self.installList = []
|
||||
|
||||
|
||||
self.config_path = get_config_patch()
|
||||
|
||||
# 获取源属性
|
||||
self.origin_property = OriginProperty()
|
||||
self.origin_property.get_allowed_sources()
|
||||
|
@ -106,7 +109,7 @@ class UpdateListFilterCache(apt.Cache):
|
|||
exit(-1)
|
||||
|
||||
# 获取/usr/share/kylin-update-desktop-config/data/下所有json文件
|
||||
for root,dirs,files in os.walk(self.window_main.config_path):
|
||||
for root,dirs,files in os.walk(self.config_path):
|
||||
pass
|
||||
for i in files:
|
||||
if ".json" in i:
|
||||
|
@ -123,7 +126,7 @@ class UpdateListFilterCache(apt.Cache):
|
|||
# 在分组中
|
||||
# 获取每个对应json文件中的upgrade_list
|
||||
if i in jsonfiles:
|
||||
filepath = os.path.join(self.window_main.config_path, i)
|
||||
filepath = os.path.join(self.config_path, i)
|
||||
filepath = filepath+".json"
|
||||
with open(filepath, 'r') as f:
|
||||
pkgdict = f.read()
|
||||
|
|
|
@ -10,6 +10,7 @@ from gi.repository import Gio
|
|||
from .OriginFilter import UpdateListFilterCache
|
||||
from .errors import *
|
||||
from .enums import *
|
||||
from SystemUpdater.Core.utils import get_config_patch
|
||||
|
||||
class LocalUpgradeDataList:
|
||||
"""
|
||||
|
@ -56,8 +57,9 @@ class UpdateList():
|
|||
self.application_dirs = [os.path.join(base, 'applications')
|
||||
for base in data_dirs.split(':')]
|
||||
|
||||
if self.parent.options.close_filter == False and self.parent.source_info.is_disc == False and \
|
||||
self.parent.configs_cover.getWithDefault("SystemStatusCover", "close_source_filter", False) == False :
|
||||
self.config_path = get_config_patch()
|
||||
|
||||
if self.parent.install_mode.check_filter() == True:
|
||||
#开启原过滤
|
||||
self.fu = UpdateListFilterCache(self.parent)
|
||||
else:
|
||||
|
@ -255,7 +257,7 @@ class UpdateList():
|
|||
group_json = {}
|
||||
for ug in self.upgrade_meta.groups_pkgs:
|
||||
pkgs_json = {}
|
||||
with open(self.parent.config_path + str(ug) + ".yaml", "r") as stream:
|
||||
with open(self.config_path + str(ug) + ".yaml", "r") as stream:
|
||||
try:
|
||||
data_yaml = yaml.safe_load(stream)
|
||||
pkgs_json.update({"cur_version":""})
|
||||
|
@ -355,17 +357,17 @@ class UpdateList():
|
|||
return downgrade_raw,downgrade_pkgs
|
||||
|
||||
def _make_groups_upgrade(self,cache,group_list, pkgs_upgrade = []):
|
||||
if os.path.isdir(self.parent.config_path) == False:
|
||||
logging.warning("configPath(%s) is not exists...",self.parent.config_path)
|
||||
if os.path.isdir(self.config_path) == False:
|
||||
logging.warning("configPath(%s) is not exists...",self.config_path)
|
||||
return
|
||||
|
||||
files = os.listdir(self.parent.config_path) #获得文件夹中所有文件的名称列表
|
||||
files = os.listdir(self.config_path) #获得文件夹中所有文件的名称列表
|
||||
|
||||
for ifile in files:
|
||||
#判是否是目录以及是否以JSON结尾
|
||||
if ifile.endswith('.json'):
|
||||
#读取组JSON文件
|
||||
with open(self.parent.config_path+ifile,'r') as f:
|
||||
with open(self.config_path+ifile,'r') as f:
|
||||
try:
|
||||
data = json.load(f)
|
||||
except Exception as exc:
|
||||
|
@ -374,7 +376,7 @@ class UpdateList():
|
|||
|
||||
group_name = data['package']
|
||||
#读取组的yaml 文件的changelog的信息
|
||||
with open(self.parent.config_path + group_name + ".yaml", "r") as stream:
|
||||
with open(self.config_path + group_name + ".yaml", "r") as stream:
|
||||
try:
|
||||
data_yaml = yaml.safe_load(stream)
|
||||
except Exception as exc:
|
||||
|
|
|
@ -202,16 +202,10 @@ def country_mirror():
|
|||
|
||||
def get_dist():
|
||||
" return the codename of the current runing distro "
|
||||
# support debug overwrite
|
||||
dist = os.environ.get("META_RELEASE_FAKE_CODENAME")
|
||||
if dist:
|
||||
logging.warning("using fake release name '%s' (because of "
|
||||
"META_RELEASE_FAKE_CODENAME environment) " % dist)
|
||||
return dist
|
||||
# then check the real one
|
||||
from subprocess import Popen, PIPE
|
||||
p = Popen(["lsb_release", "-c", "-s"], stdout=PIPE,
|
||||
universal_newlines=True)
|
||||
p = Popen(["lsb_release", "-i", "-s"], stdout=PIPE,
|
||||
universal_newlines=True)
|
||||
res = p.wait()
|
||||
if res != 0:
|
||||
sys.stderr.write("lsb_release returned exitcode: %i\n" % res)
|
||||
|
@ -223,16 +217,10 @@ def get_dist():
|
|||
|
||||
def get_dist_version():
|
||||
" return the version of the current running distro "
|
||||
# support debug overwrite
|
||||
desc = os.environ.get("META_RELEASE_FAKE_VERSION")
|
||||
if desc:
|
||||
logging.warning("using fake release version '%s' (because of "
|
||||
"META_RELEASE_FAKE_VERSION environment) " % desc)
|
||||
return desc
|
||||
# then check the real one
|
||||
from subprocess import Popen, PIPE
|
||||
p = Popen(["lsb_release", "-r", "-s"], stdout=PIPE,
|
||||
universal_newlines=True)
|
||||
universal_newlines=True)
|
||||
res = p.wait()
|
||||
if res != 0:
|
||||
sys.stderr.write("lsb_release returned exitcode: %i\n" % res)
|
||||
|
@ -473,6 +461,17 @@ def _split_package_id(package):
|
|||
return name, arch
|
||||
|
||||
|
||||
def get_config_patch():
|
||||
#检查组配置文件当前的目录
|
||||
NOW_UPDATE_CONFIG = '/usr/share/kylin-update-desktop-config/config/'
|
||||
OLD_UPDATE_CONFIG = '/usr/share/kylin-update-desktop-config/data/'
|
||||
if os.path.exists(NOW_UPDATE_CONFIG):
|
||||
return NOW_UPDATE_CONFIG
|
||||
elif os.path.exists(OLD_UPDATE_CONFIG):
|
||||
return OLD_UPDATE_CONFIG
|
||||
else:
|
||||
return NOW_UPDATE_CONFIG
|
||||
|
||||
def get_broken_details(cache,now=True):
|
||||
"""Return a message which provides debugging information about
|
||||
broken packages.
|
||||
|
|
|
@ -30,7 +30,7 @@ from .Core.DataAcquisition import UpdateMsgCollector
|
|||
from SystemUpdater.Core.UpdaterConfigParser import UpgradeConfig
|
||||
from SystemUpdater.Core.utils import kill_process
|
||||
from SystemUpdater.Core.DpkgInstallProgress import LogInstallProgress
|
||||
from SystemUpdater.Core.utils import deb_verify,PolicyKit_Authority,get_proc_from_dbus_name,whether_to_quit_uu
|
||||
from SystemUpdater.Core.utils import deb_verify,PolicyKit_Authority,get_proc_from_dbus_name,whether_to_quit_uu,get_dist
|
||||
|
||||
class UpdateManager():
|
||||
BACKEND_PKG_NAME = 'kylin-system-updater'
|
||||
|
@ -49,7 +49,6 @@ class UpdateManager():
|
|||
self.init_config_aptdeamon = False
|
||||
self.aptd_lang_switch = False
|
||||
self.retry_limit = self.RETRY_LIMIT_NUM
|
||||
self.config_path = self.refresh_config_patch()
|
||||
self.now_working = InstallBackend.ACTION_DEFUALT_STATUS
|
||||
#dbus
|
||||
self.dbusController = self._setup_dbus()
|
||||
|
@ -63,7 +62,6 @@ class UpdateManager():
|
|||
#连接数据库
|
||||
self.sqlite3_server = Sqlite3Server(self)
|
||||
self.simulate_mode = SimulateTerminal()
|
||||
self.source_info = MakeSourceInit()
|
||||
self.install_mode = UpdateInstallMode(self)
|
||||
self.apt_p2p_config = AptP2pConfigManager()
|
||||
self._refresh_cache_only()
|
||||
|
@ -72,17 +70,6 @@ class UpdateManager():
|
|||
logging.error(e)
|
||||
traceback.print_exc()
|
||||
|
||||
def refresh_config_patch(self):
|
||||
#检查组配置文件当前的目录
|
||||
NOW_UPDATE_CONFIG = '/usr/share/kylin-update-desktop-config/config/'
|
||||
OLD_UPDATE_CONFIG = '/usr/share/kylin-update-desktop-config/data/'
|
||||
if os.path.exists(NOW_UPDATE_CONFIG):
|
||||
return NOW_UPDATE_CONFIG
|
||||
elif os.path.exists(OLD_UPDATE_CONFIG):
|
||||
return OLD_UPDATE_CONFIG
|
||||
else:
|
||||
return NOW_UPDATE_CONFIG
|
||||
|
||||
def check_frontend_pkg(self):
|
||||
#控制面板前端包的检查升级
|
||||
if self.FRONTEND_PKG_NAME in self.cache:
|
||||
|
@ -163,12 +150,12 @@ class UpdateManager():
|
|||
self.install_mode.reset_shutdown_mode()
|
||||
|
||||
#检查 光盘源
|
||||
self.source_info.check_source()
|
||||
self.install_mode.check_source()
|
||||
|
||||
if self.options.no_check_network is False and self.source_info.is_disc == False:
|
||||
if self.install_mode.check_network() == True:
|
||||
self.dbusController.check_connectivity()
|
||||
|
||||
if self.options.no_update_source is False:
|
||||
if self.install_mode.update_important() == True:
|
||||
self.dbusController.on_update_important_list()
|
||||
return
|
||||
|
||||
|
@ -194,7 +181,6 @@ class UpdateManager():
|
|||
|
||||
def start_available(self):
|
||||
try:
|
||||
self.config_path = self.refresh_config_patch()
|
||||
self.refresh_cache()
|
||||
|
||||
self.update_list = UpdateList(self)
|
||||
|
@ -258,22 +244,25 @@ class UpdateManager():
|
|||
for pkg_name in [self.BACKEND_PKG_NAME,self.APTD_PKG_NAME,self.FRONTEND_PKG_NAME]:
|
||||
if pkg_name in cache:
|
||||
self_pkg = cache[pkg_name]
|
||||
if self_pkg.is_installed and self_pkg.is_upgradable:
|
||||
logging.info("Check: (%s) will upgrading From %s to %s...",pkg_name,\
|
||||
self_pkg.installed.source_version,self_pkg.candidate.source_version)
|
||||
if pkg_name in important_list:
|
||||
try:
|
||||
logging.info("Check: (%s) start upgrading From %s to %s...",pkg_name,\
|
||||
self_pkg.installed.source_version,self_pkg.candidate.source_version)
|
||||
self_pkg.mark_install(True,False,True)
|
||||
self_upgrade.append(pkg_name)
|
||||
need_upgrade = True
|
||||
except SystemError:
|
||||
self.simulate_mode.thread_install([pkg_name])
|
||||
logging.error("Check: mark %s to upgrade Failed...",pkg_name)
|
||||
raise UpdateBaseError(ERROR_NOT_SELFPKG_DEPENDENCIES)
|
||||
if self_pkg.is_installed:
|
||||
if self_pkg.is_upgradable:
|
||||
logging.info("Check: (%s) will upgrading From %s to %s...",pkg_name,\
|
||||
self_pkg.installed.source_version,self_pkg.candidate.source_version)
|
||||
if pkg_name in important_list:
|
||||
try:
|
||||
logging.info("Check: (%s) start upgrading From %s to %s...",pkg_name,\
|
||||
self_pkg.installed.source_version,self_pkg.candidate.source_version)
|
||||
self_pkg.mark_install(True,False,True)
|
||||
self_upgrade.append(pkg_name)
|
||||
need_upgrade = True
|
||||
except SystemError:
|
||||
self.simulate_mode.thread_install([pkg_name])
|
||||
logging.error("Check: mark %s to upgrade Failed...",pkg_name)
|
||||
raise UpdateBaseError(ERROR_NOT_SELFPKG_DEPENDENCIES)
|
||||
else:
|
||||
logging.info("Check: (%s:%s) No need to upgrade and duo to not pust...",pkg_name,self_pkg.installed.source_version)
|
||||
else:
|
||||
logging.info("Check: (%s:%s) No need to upgrade and duo to not pust...",pkg_name,self_pkg.installed.source_version)
|
||||
logging.info("Check: (%s:%s) No need to upgrade...",pkg_name,self_pkg.installed.source_version)
|
||||
else:
|
||||
logging.info("Check: (%s) Not to be installed...",pkg_name)
|
||||
else:
|
||||
|
@ -965,8 +954,17 @@ class UpdateSafeManager():
|
|||
return False
|
||||
|
||||
class UpdateInstallMode():
|
||||
OPENKYLIN_DISTTRIBUTOR = "Openkylin"
|
||||
KYLIN_DISTTRIBUTOR = "Kylin"
|
||||
DIR_MRDIA = "/media/"
|
||||
MOUNT_SQUASHFS_PATH = "/media/kylin/kylin-test-upgrade/upgrade-pool/"
|
||||
|
||||
def __init__(self,parent):
|
||||
self.parent = parent
|
||||
self.is_disc = False
|
||||
self.is_mounted = False
|
||||
|
||||
self.dist = get_dist()
|
||||
|
||||
if self.shutdown_mode() == True:
|
||||
logging.info("Initialize Shutdown Install Model...")
|
||||
|
@ -976,6 +974,27 @@ class UpdateInstallMode():
|
|||
self.tmp_content = []
|
||||
self.inhibit_lock = None
|
||||
|
||||
def is_openkylin_desktop(self):
|
||||
return self.dist == self.OPENKYLIN_DISTTRIBUTOR
|
||||
|
||||
def check_network(self):
|
||||
if self.parent.options.no_check_network is False and self.is_disc == False:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def update_important(self):
|
||||
if self.parent.options.no_update_source is False:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def check_filter(self):
|
||||
if self.parent.options.close_filter == False and self.is_disc == False:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def _plymouth_splash(self):
|
||||
if os.path.exists("/bin/plymouth"):
|
||||
logging.debug("Running plymouth --splash")
|
||||
|
@ -1092,37 +1111,61 @@ class UpdateInstallMode():
|
|||
logging.error("Prepare inhibit lock failed...")
|
||||
|
||||
#当检查失败时 再切换到ping再进行一次检查
|
||||
def _check_network_ping(self):
|
||||
header = ''
|
||||
desc = ''
|
||||
slist = apt_pkg.SourceList()
|
||||
slist.read_main_list()
|
||||
def mount_squashfs(self,mount_source):
|
||||
args = ["mount", "-o","loop",mount_source,self.MOUNT_SQUASHFS_PATH]
|
||||
|
||||
#多个源 也只循环一次
|
||||
for uri in [lis.uri for lis in slist.list]:
|
||||
#只要是使用光盘源 就不进行检查了 默认检查网络成功 进行之后的动作
|
||||
if "file://" in uri:
|
||||
logging.info("Current exites of CD-ROM source in sources.list and return network ok...")
|
||||
return True,header,desc
|
||||
p = subprocess.run(args, stdout=subprocess.PIPE,stderr=subprocess.STDOUT,text=True)
|
||||
logging.info(str(p.stdout))
|
||||
if p.returncode == 0:
|
||||
self.is_mounted = True
|
||||
return True,' '
|
||||
elif p.returncode == 1:
|
||||
self.is_mounted = True
|
||||
return True,' '
|
||||
else:
|
||||
self.is_mounted = False
|
||||
return False,str(p.stdout)
|
||||
|
||||
if "localhost:9977" in uri:
|
||||
#deb http://localhost:9977/172.17.126.249:8098/deb/kylin/ 需要去除localhost:9977 在apt-p2p的模式下
|
||||
network_uri = uri.split("//")[1].split("/")[1]
|
||||
def check_mount(self):
|
||||
if self.is_mounted == True:
|
||||
args = ["umount",self.MOUNT_SQUASHFS_PATH]
|
||||
logging.info("Will be to umount the offlinesource...")
|
||||
p = subprocess.run(args, stdout=subprocess.PIPE,stderr=subprocess.STDOUT,text=True)
|
||||
logging.info(str(p.stdout))
|
||||
if p.returncode == 0:
|
||||
self.is_mounted = False
|
||||
return True
|
||||
else:
|
||||
#只拿去 网站主地址 例如http://ppa.launchpad.dev/luoxueyi/v101/kylin-desktop 只截取ppa.launchpad.dev 使用此来检查网络
|
||||
network_uri = uri.split("//")[1].split("/")[0]
|
||||
return False
|
||||
|
||||
#去除这个问题172.17.126.249:8098 带端口号的
|
||||
if ":" in network_uri:
|
||||
network_uri = network_uri.split(":")[0]
|
||||
|
||||
logging.info("Check network connectivity to use ping %s...",network_uri)
|
||||
#ping 一次,总超时时间为5S
|
||||
response = os.system("ping -c 1 -w 5 "+network_uri+" 2>&1 >/dev/null")
|
||||
if response == 0:
|
||||
return True,header,desc
|
||||
else:
|
||||
header = _("Please check your network connection and retry.")
|
||||
return False,header,desc
|
||||
#当源列表为空时 从此反回,这种认为这是一种正常的状况 进行之后的动作
|
||||
return True,header,desc
|
||||
#判断是否为光盘源
|
||||
#光盘源格式 deb file:///home/someone/packs/
|
||||
def check_source(self):
|
||||
logging.info("Check: Whether to use CD-ROM source updates Successfully...")
|
||||
if os.path.exists(self.DIR_MRDIA):
|
||||
for first_dir in os.listdir(self.DIR_MRDIA):
|
||||
#到/media/x
|
||||
check_dir_one = self.DIR_MRDIA + first_dir + "/"
|
||||
|
||||
if not os.path.isdir(check_dir_one):
|
||||
continue
|
||||
|
||||
for second_dir in os.listdir(check_dir_one):
|
||||
#到/media/x/test
|
||||
check_dir_two = check_dir_one + second_dir + "/"
|
||||
|
||||
if not os.path.isdir(check_dir_two):
|
||||
continue
|
||||
check_file = check_dir_two + "ss.map"
|
||||
|
||||
logging.info("Check: CD-ROM source File(%s)",check_file)
|
||||
if os.path.exists(check_file):
|
||||
self.is_disc = True
|
||||
logging.info("Use to CD-Source and Turn off NetworkCheck and CloseFiter...")
|
||||
return
|
||||
#没有返回存在光盘源就说明不存在
|
||||
self.is_disc = False
|
||||
return
|
||||
else:
|
||||
self.is_disc = False
|
||||
return
|
||||
|
|
|
@ -17,6 +17,7 @@ from SystemUpdater.Core.enums import *
|
|||
from SystemUpdater.Core.DataAcquisition import get_east_8_time
|
||||
from SystemUpdater.Core.UpdateList import LocalUpgradeDataList
|
||||
from SystemUpdater.Core.DistUpgradeCache import NotEnoughFreeSpaceError
|
||||
from SystemUpdater.Core.utils import get_config_patch
|
||||
|
||||
class NowUpgradeMeta:
|
||||
"""
|
||||
|
@ -76,7 +77,7 @@ class UpdateEssentialItem():
|
|||
self.essential_pkgs = []
|
||||
self.remove_white = []
|
||||
|
||||
self.read_path = parent.window_main.config_path + 'kylin-update-desktop-system.json'
|
||||
self.read_path = get_config_patch() + 'kylin-update-desktop-system.json'
|
||||
self.update()
|
||||
|
||||
def update(self):
|
||||
|
|
Loading…
Reference in New Issue