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

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()
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 :
if self.parent.install_mode.check_filter() == True:
#开启原过滤
self.fu = UpdateListFilterCache(self.parent)
else:

View File

@ -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)

View File

@ -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'
@ -62,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()
@ -71,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:
@ -162,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
@ -966,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...")
@ -977,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")
@ -1093,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