local路径下查找依赖包

This commit is contained in:
luoxueyi 2021-11-05 11:06:05 +08:00
parent 2feab116e6
commit 2239bd86ed
3 changed files with 44 additions and 6 deletions

View File

@ -3,9 +3,13 @@
import os
import sys
import apt
from apt import cache
import shutil
import dbus
import logging
import dbus.service
from apt.debfile import DebPackage
from dbus.mainloop.glib import DBusGMainLoop
DBusGMainLoop(set_as_default=True)
@ -92,9 +96,43 @@ class UpdateManager():
# 进行本地deb包安装的操作
def start_deb_install(self, deb_path = "", is_install = False):
absolute_path, debname = os.path.split(deb_path)
logging.info("About to Install Package: %s.",str(debname))
depends_list = []
depends_pkg = []
satisfy_list = []
depends_count = 0
try:
absolute_path, debname = os.path.split(deb_path)
logging.info("About to Install Package: %s.",str(debname))
deb = DebPackage(deb_path, self.cache)
deb.check()
(install, remove, unauth) = deb.required_changes
if len(install) > 1:
for pkg in self.cache:
if pkg.marked_install:
print(pkg.name)
depends_pkg.append(pkg)
elif pkg.marked_upgrade:
print(pkg.name)
depends_pkg.append(pkg)
if depends_pkg: #查找本地deb包
depends_list = [debfile for debfile in os.listdir(absolute_path) if debfile.endswith(".deb")]
print(depends_list)
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 is_install == 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))
install_backend = get_backend(self, InstallBackend.ACTION_INSTALL_DEB)
install_backend.start_alone(partial_upgrade_list = deb_path, _is_install = is_install)
except Exception as e:

View File

@ -65,7 +65,7 @@ class UpdateManagerDbusController(dbus.service.Object):
obj = bus.get_object('com.kylin.software.properties', '/com/kylin/software/properties')
interface = dbus.Interface(obj, dbus_interface='com.kylin.software.properties.interface')
lock.acquire()
retval = interface.updateSourceTemplate()
retval = True #interface.updateSourceTemplate()
lock.release()
except Exception as e:
header = _("update important list occur Exception")
@ -241,8 +241,9 @@ class UpdateManagerDbusController(dbus.service.Object):
def InstallDebFile(self,source = "unKnown", path = "", _is_install = False):
try:
is_install = bool(_is_install)
deb_path = str(path)
logging.info('method InstallDebFile and is_install:%r...',is_install)
self.parent.start_deb_install(deb_path = path, is_install = is_install)
self.parent.start_deb_install(deb_path, is_install)
return True,'success'
except Exception as e:
logging.error(False, str(e))

View File

@ -153,7 +153,6 @@ class InstallBackend():
self.install_deb(install_path = partial_upgrade_list, install_force = True)
except Exception as e:
logging.error(str(e))
def update(self):
"""Run a update to refresh the package list"""
@ -366,7 +365,7 @@ class InstallBackend():
else:
self.window_main.dbusController.UpdateDetectFinished(success,[],'','')
elif action == self.ACTION_INSTALL_DEB:
pass
print("run hear...")
unLockedEnableShutdown()
# try aptdaemon