对各种小功能检查做出统一化判断

This commit is contained in:
wangsong 2022-08-31 09:51:25 +08:00
parent 051ea46203
commit d77f116b2b
3 changed files with 92 additions and 63 deletions

View File

@ -59,8 +59,7 @@ class UpdateList():
self.config_path = get_config_patch() self.config_path = get_config_patch()
if self.parent.options.close_filter == False and self.parent.source_info.is_disc == False and \ if self.parent.install_mode.check_filter() == True:
self.parent.configs_cover.getWithDefault("SystemStatusCover", "close_source_filter", False) == False :
#开启原过滤 #开启原过滤
self.fu = UpdateListFilterCache(self.parent) self.fu = UpdateListFilterCache(self.parent)
else: else:

View File

@ -202,16 +202,10 @@ def country_mirror():
def get_dist(): def get_dist():
" return the codename of the current runing distro " " 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 # then check the real one
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
p = Popen(["lsb_release", "-c", "-s"], stdout=PIPE, p = Popen(["lsb_release", "-i", "-s"], stdout=PIPE,
universal_newlines=True) universal_newlines=True)
res = p.wait() res = p.wait()
if res != 0: if res != 0:
sys.stderr.write("lsb_release returned exitcode: %i\n" % res) sys.stderr.write("lsb_release returned exitcode: %i\n" % res)
@ -223,16 +217,10 @@ def get_dist():
def get_dist_version(): def get_dist_version():
" return the version of the current running distro " " 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 # then check the real one
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
p = Popen(["lsb_release", "-r", "-s"], stdout=PIPE, p = Popen(["lsb_release", "-r", "-s"], stdout=PIPE,
universal_newlines=True) universal_newlines=True)
res = p.wait() res = p.wait()
if res != 0: if res != 0:
sys.stderr.write("lsb_release returned exitcode: %i\n" % res) sys.stderr.write("lsb_release returned exitcode: %i\n" % res)

View File

@ -30,7 +30,7 @@ from .Core.DataAcquisition import UpdateMsgCollector
from SystemUpdater.Core.UpdaterConfigParser import UpgradeConfig from SystemUpdater.Core.UpdaterConfigParser import UpgradeConfig
from SystemUpdater.Core.utils import kill_process from SystemUpdater.Core.utils import kill_process
from SystemUpdater.Core.DpkgInstallProgress import LogInstallProgress 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(): class UpdateManager():
BACKEND_PKG_NAME = 'kylin-system-updater' BACKEND_PKG_NAME = 'kylin-system-updater'
@ -62,7 +62,6 @@ class UpdateManager():
#连接数据库 #连接数据库
self.sqlite3_server = Sqlite3Server(self) self.sqlite3_server = Sqlite3Server(self)
self.simulate_mode = SimulateTerminal() self.simulate_mode = SimulateTerminal()
self.source_info = MakeSourceInit()
self.install_mode = UpdateInstallMode(self) self.install_mode = UpdateInstallMode(self)
self.apt_p2p_config = AptP2pConfigManager() self.apt_p2p_config = AptP2pConfigManager()
self._refresh_cache_only() self._refresh_cache_only()
@ -71,17 +70,6 @@ class UpdateManager():
logging.error(e) logging.error(e)
traceback.print_exc() 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): def check_frontend_pkg(self):
#控制面板前端包的检查升级 #控制面板前端包的检查升级
if self.FRONTEND_PKG_NAME in self.cache: if self.FRONTEND_PKG_NAME in self.cache:
@ -162,12 +150,12 @@ class UpdateManager():
self.install_mode.reset_shutdown_mode() 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() 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() self.dbusController.on_update_important_list()
return return
@ -966,8 +954,17 @@ class UpdateSafeManager():
return False return False
class UpdateInstallMode(): 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): def __init__(self,parent):
self.parent = parent self.parent = parent
self.is_disc = False
self.is_mounted = False
self.dist = get_dist()
if self.shutdown_mode() == True: if self.shutdown_mode() == True:
logging.info("Initialize Shutdown Install Model...") logging.info("Initialize Shutdown Install Model...")
@ -977,6 +974,27 @@ class UpdateInstallMode():
self.tmp_content = [] self.tmp_content = []
self.inhibit_lock = None 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): def _plymouth_splash(self):
if os.path.exists("/bin/plymouth"): if os.path.exists("/bin/plymouth"):
logging.debug("Running plymouth --splash") logging.debug("Running plymouth --splash")
@ -1093,37 +1111,61 @@ class UpdateInstallMode():
logging.error("Prepare inhibit lock failed...") logging.error("Prepare inhibit lock failed...")
#当检查失败时 再切换到ping再进行一次检查 #当检查失败时 再切换到ping再进行一次检查
def _check_network_ping(self): def mount_squashfs(self,mount_source):
header = '' args = ["mount", "-o","loop",mount_source,self.MOUNT_SQUASHFS_PATH]
desc = ''
slist = apt_pkg.SourceList()
slist.read_main_list()
#多个源 也只循环一次 p = subprocess.run(args, stdout=subprocess.PIPE,stderr=subprocess.STDOUT,text=True)
for uri in [lis.uri for lis in slist.list]: logging.info(str(p.stdout))
#只要是使用光盘源 就不进行检查了 默认检查网络成功 进行之后的动作 if p.returncode == 0:
if "file://" in uri: self.is_mounted = True
logging.info("Current exites of CD-ROM source in sources.list and return network ok...") return True,' '
return True,header,desc 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: def check_mount(self):
#deb http://localhost:9977/172.17.126.249:8098/deb/kylin/ 需要去除localhost:9977 在apt-p2p的模式下 if self.is_mounted == True:
network_uri = uri.split("//")[1].split("/")[1] 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: else:
#只拿去 网站主地址 例如http://ppa.launchpad.dev/luoxueyi/v101/kylin-desktop 只截取ppa.launchpad.dev 使用此来检查网络 return False
network_uri = uri.split("//")[1].split("/")[0]
#去除这个问题172.17.126.249:8098 带端口号的 #判断是否为光盘源
if ":" in network_uri: #光盘源格式 deb file:///home/someone/packs/
network_uri = network_uri.split(":")[0] def check_source(self):
logging.info("Check: Whether to use CD-ROM source updates Successfully...")
logging.info("Check network connectivity to use ping %s...",network_uri) if os.path.exists(self.DIR_MRDIA):
#ping 一次总超时时间为5S for first_dir in os.listdir(self.DIR_MRDIA):
response = os.system("ping -c 1 -w 5 "+network_uri+" 2>&1 >/dev/null") #到/media/x
if response == 0: check_dir_one = self.DIR_MRDIA + first_dir + "/"
return True,header,desc
else: if not os.path.isdir(check_dir_one):
header = _("Please check your network connection and retry.") continue
return False,header,desc
#当源列表为空时 从此反回,这种认为这是一种正常的状况 进行之后的动作 for second_dir in os.listdir(check_dir_one):
return True,header,desc #到/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