dpkg流程:查找本地依赖

This commit is contained in:
luoxueyi 2021-12-04 16:21:30 +08:00
parent ed23d20c1b
commit 0a3846b098
1 changed files with 70 additions and 4 deletions

View File

@ -162,13 +162,12 @@ class UpdateManager():
if broken_count > 0:
# 走 dpkg 安装流程说明本地apt环境已经损坏
try:
deb = DebPackage(filename=deb_path)
deb.install()
self._deb_install(deb_path, _check_local_dep)
except Exception as e:
logging.error(str(e))
else:
# apt 安装流程
dep_satisfy, header, desc = self._attempt_depends(deb_path,_check_local_dep,_auto_satisfy)
dep_satisfy, header, desc = 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 = _auto_satisfy)
@ -510,4 +509,71 @@ class UpdateManager():
error_string = ''
error_desc=''
return _local_satisfy,error_string,error_desc
def _deb_install(self, deb_path, _check_local_dep):
depends_list = []
depends_pkg = []
satisfy_list = []
depends_count = 0
_status = False
error_string = ''
absolute_path, debname = os.path.split(deb_path)
try:
deb_cache = Cache()
deb = DebPackage(deb_path, deb_cache)
deb.check()
(install, remove, unauth) = deb.required_changes
except Exception as e:
logging.error(str(e))
self.dbusController.InstalldebFinished(_status, header=str(e))
# 依赖不满足的情况
if len(install) > 0:
if _check_local_dep: #查找本地
# 需要查找本地依赖
if len(install) > 0:
for pkg in deb_cache:
if pkg.marked_install and pkg.name != str(debname.split("_")[0]):
depends_pkg.append(pkg)
elif pkg.marked_upgrade and pkg.name != str(debname.split("_")[0]):
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:
depends_count += 1
satisfy_list.append(debfile)
if depends_count < len(depends_pkg):
#本地依赖不满足
_status = False
error_string = str(debname.split("_")[0])+" dependency is not satisfied. "+",".join(install)
logging.error(error_string)
self.dbusController.InstalldebFinished(_status, header=error_string)
else:
#安装依赖包
if debname not in satisfy_list:
satisfy_list.append(debname)
for satisfy in satisfy_list:
try:
deb = DebPackage(os.path.join(absolute_path,satisfy))
ret = deb.install()
except Exception as e:
logging.error(e)
self.dbusController.InstalldebFinished(_status, header=str(e))
_status = True
self.dbusController.InstalldebFinished(_status,'','')
elif not _check_local_dep:
_status = False
if install:
error_string = str(debname.split("_")[0])+" dependency is not satisfied. "+",".join(install)
logging.error(error_string)
self.dbusController.InstalldebFinished(_status, header=error_string)
# 依赖满足
else:
try:
deb = DebPackage(deb_path)
ret = deb.install()
except Exception as e:
logging.error(e)
_status = True
self.dbusController.InstalldebFinished(_status,'','')