deb包网络下载标志位

deb安装过程与结束信号
This commit is contained in:
luoxueyi 2021-12-02 14:59:59 +08:00
parent 4da50aa4e5
commit 320218dab7
4 changed files with 98 additions and 58 deletions

View File

@ -136,25 +136,26 @@ class UpdateManager():
logging.error(e)
# 进行本地deb包安装的操作
def start_deb_install(self, deb_path = "", is_install = False, auto_satisfy = False):
def start_deb_install(self, deb_path = "", _check_local_dep = False, _auto_satisfy = False):
# _check_local_dep : 是否查询本地依赖
# _auto_satisfy : 是否通过网络下载依赖
# 包常规检查
absolute_path, debname = os.path.split(deb_path)
if not os.path.exists(deb_path):
if not os.path.exists(deb_path):
logging.error("<%s> does not exist.",debname)
return False,"<"+debname+"> does not exist."
elif not debname.endswith(".deb"):
logging.error("<%s> Not a DEB package.",debname)
return False,"<"+debname+"> Not a DEB package."
logging.info("About to Install Package: %s.",str(debname))
try:
if not auto_satisfy:
(status,_error_str) = self._attempt_depends(deb_path,is_install)
if not status:
return status,_error_str
install_backend = get_backend(self, InstallBackend.ACTION_INSTALL_DEB)
install_backend.start_alone(partial_upgrade_list = deb_path, _is_install = is_install)
dep_satisfy = self._attempt_depends(deb_path,_check_local_dep,_auto_satisfy)
if dep_satisfy:
install_backend = get_backend(self, InstallBackend.ACTION_INSTALL_DEB)
install_backend.start_alone(partial_upgrade_list = deb_path, _is_install = _check_local_dep)
except Exception as e:
logging.info(str(e))
#进行升级的操作
def start_install(self,upgrade_mode,is_install = False,partial_upgrade_list = []):
try:
@ -409,56 +410,77 @@ class UpdateManager():
return UpdateManagerDbusController(self, bus_name)
# 是否查找本地依赖
def _attempt_depends(self,deb_path,force):
def _attempt_depends(self,deb_path,_check_local_dep,_auto_satisfy):
depends_list = []
depends_pkg = []
satisfy_list = []
depends_count = 0
_error_str = ""
_local_satisfy = False
absolute_path, debname = os.path.split(deb_path)
if self.cache == None:
logging.warning('Perform \"UpdateDetect\" first')
return _local_satisfy
try:
deb = DebPackage(deb_path, self.cache)
deb.check()
(install, remove, unauth) = deb.required_changes
except Exception as e:
logging.error(str(e))
if force: #查找
if remove:
logging.error("Need uninstall: %s.",str(remove))
_error_str = "Installing "+str(debname.split("_")[0])+" requires uninstalling "+str(remove)
return False,_error_str
if force == False and len(install) > 0:
_error_str = str(debname.split("_")[0])+" dependency is not satisfied:\n"+str(install)
return False,_error_str
# 需要查找本地依赖
elif len(install) > 0:
for pkg in self.cache:
if pkg.marked_install:
depends_pkg.append(pkg)
elif pkg.marked_upgrade:
depends_pkg.append(pkg)
if depends_pkg: #查找本地deb包
depends_list = [debfile for debfile in os.listdir(absolute_path) if debfile.endswith(".deb")]
for depends in depends_pkg:
for debfile in depends_list:
if depends.name in debfile and depends.candidate.version in debfile:
#FIXME:检查depends包的合法性,高阶依赖
depends_count += 1
satisfy_list.append(debfile)
if depends_count < len(depends_pkg)-1 and force == False:
#本地依赖不满足
return False
else:
#将应用包与依赖包拷贝至archive目录安装
try:
for satisfy in satisfy_list:
shutil.copy(os.path.join(absolute_path,satisfy),"/var/cache/apt/archives/")
except Exception as e:
logging.info(str(e))
else: # 不查找
if install or remove:
_error_str = str(debname.split("_")[0])+"dependency is not satisfied: "+",".join(install)
return False,_error_str
return True,_error_str
# 依赖不满足的情况
if len(install) > 0:
if _check_local_dep: #查找本地
if remove:
logging.error("Need uninstall: %s.",str(remove))
_error_str = "Installing "+str(debname.split("_")[0])+" requires uninstalling: "+str(remove)
logging.error(_error_str)
# return False
# 需要查找本地依赖
elif len(install) > 0:
for pkg in self.cache:
if pkg.marked_install:
depends_pkg.append(pkg)
elif pkg.marked_upgrade:
depends_pkg.append(pkg)
if len(depends_pkg)>0: #查找本地deb包
depends_list = [debfile for debfile in os.listdir(absolute_path) if debfile.endswith(".deb")]
for depends in depends_pkg:
for debfile in depends_list:
if depends.name in debfile and depends.candidate.version in debfile:
#FIXME:检查depends包的合法性
depends_count += 1
satisfy_list.append(debfile)
if depends_count < len(depends_pkg)-1 and _check_local_dep == False:
#本地依赖不满足 判断源下载
if _auto_satisfy:
_local_satisfy = True
elif not _auto_satisfy:
_local_satisfy = False
else:
#将应用包与依赖包拷贝至archive目录安装
try:
if debname not in satisfy_list:
satisfy_list.append(debname)
for satisfy in satisfy_list:
shutil.copy(os.path.join(absolute_path,satisfy),"/var/cache/apt/archives/")
except Exception as e:
logging.info(str(e))
_local_satisfy = True
return _local_satisfy
elif not _check_local_dep and _auto_satisfy:
_local_satisfy = True
if install:
_error_str = str(debname.split("_")[0])+"dependency is not satisfied, will download: "+",".join(install)
logging.error(_error_str)
return _local_satisfy
elif not _check_local_dep and not _auto_satisfy:
_local_satisfy = False
if install:
_error_str = str(debname.split("_")[0])+" dependency is not satisfied: "+",".join(install)
logging.error(_error_str)
return _local_satisfy
# 依赖满足
else:
_local_satisfy = True
return _local_satisfy

View File

@ -308,19 +308,19 @@ class UpdateManagerDbusController(dbus.service.Object):
return (False, str(e))
# 安装本地deb包
@dbus.service.method(UPDATER_DBUS_INTERFACE,in_signature='ssb',out_signature='bs')
def InstallDebFile(self,source = "unKnown", path = "", _is_install = False):
@dbus.service.method(UPDATER_DBUS_INTERFACE,in_signature='ssbb',out_signature='b')
def InstallDebFile(self,source = "unKnown", path = "", _check_local_dep = False, _auto_satisfy = False):
try:
is_install = bool(_is_install)
check_local_dep = bool(_check_local_dep)
auto_satisfy = bool(_auto_satisfy)
deb_path = str(path)
logging.info(COLORMETHOR_PREFIX+'method'+COLORLOG_SUFFIX+' InstallDebFile and is_install:%r...',is_install)
(status,_error_str) = self.parent.start_deb_install(deb_path, is_install)
if not status:
return status,_error_str
return True,'success'
logging.info(COLORMETHOR_PREFIX+'method'+COLORLOG_SUFFIX+' InstallDebFile and check_local_dep:%r, auto_satisfy:%r.',\
check_local_dep,auto_satisfy)
self.parent.start_deb_install(deb_path, _check_local_dep, _auto_satisfy)
return True
except Exception as e:
logging.error(False, str(e))
return (False, str(e))
return (False)
# dbus接口向数据库display表中插入数据
@dbus.service.method(UPDATER_DBUS_INTERFACE, in_signature='ss', sender_keyword='sender')
@ -486,3 +486,16 @@ class UpdateManagerDbusController(dbus.service.Object):
def PurgePkgStatusChanged(self,progress,status,current_details):
logging.info(COLORLOG_PREFIX + "emit" + COLORLOG_SUFFIX +" PurgePkgStatusChanged progress = %d , status = %s ,current_details = %s",\
progress,status,current_details)
#安装deb包完成的信号
@dbus.service.signal(UPDATER_DBUS_INTERFACE,signature='bss')
def InstalldebFinished(self, success,error_string='',error_desc=''):
logging.info(COLORLOG_PREFIX + "emit"+ COLORLOG_SUFFIX + " InstalldebFinished success = %r , error_string = %s , error_desc = %s ",\
success,error_string,error_desc)
#安装进度信息 0~100 进度信息 101为非预期的信号
@dbus.service.signal(UPDATER_DBUS_INTERFACE,signature='bss')
def InstalldebStatusChanged(self, success,error_string='',error_desc=''):
logging.info(COLORLOG_PREFIX + "emit"+ COLORLOG_SUFFIX + " InstalldebStatusChanged success = %r , error_string = %s , error_desc = %s ",\
success,error_string,error_desc)

View File

@ -291,6 +291,8 @@ class InstallBackendAptdaemon(InstallBackend):
self.window_main.dbusController.FixBrokenStatusChanged(False,True,progress,status,'','')
elif action == self.ACTION_REMOVE_PACKAGES:
self.window_main.dbusController.PurgePkgStatusChanged(progress,status,details)
elif action == self.ACTION_INSTALL_DEB:
self.window_main.dbusController.PurgePkgStatusChanged(progress,status,details)
else:
logging.info("Other Action:progress = %d , status = %s ,details = %s",progress,status,details)

View File

@ -434,6 +434,9 @@ class InstallBackend():
elif action == self.ACTION_REMOVE_PACKAGES:
self.window_main.dbusController.PurgePackagesFinished(success,error_string,error_desc)
elif action == self.ACTION_INSTALL_DEB:
self.window_main.dbusController.InstalldebFinished(success,error_string,error_desc)
def _make_insert_info(self,success,is_cancelled,upgrade_mode,error_string,error_desc):
try: