我正在查看由提供的这段代码,python_apt
但它似乎有点过时了:
https://github.com/jolicloud/python-apt/blob/master/doc/examples/inst.py
我在这里要做的就是跟踪commit()
方法的进度;目前,当我们调用commit()
并传入fprogress
andiprogress
时,我可以在控制台上看到其中的所有包pkg_list
都已正确下载,问题似乎出现在此之后。
程序继续执行并且它没有dpkg_status_change()
像我认为的那样触发?
我无法知道多个软件包的安装是否成功?
import apt
from apt.progress.base import InstallProgress
class InstallStatusUpdate(InstallProgress):
def conffile(self, current, new):
print "conffile prompt: %s %s" % (current, new)
def processing(self, pkg, stage):
print "Processing ", pkg, " stage: ", stage
def error(self, pkg, errormsg):
print "Package ", pkg, " error: ", errormsg
def finish_update(self):
print "Installation is complete"
def status_change(self, pkg, percent, status):
print "Package: ", pkg, " at ", percent, " -> ", status
def dpkg_status_change(self, pkg, status):
print "Package ", pkg, ", Status: ", status
def install_updates(self, pkg_list):
fprogress = apt.progress.TextFetchProgress()
iprogress = InstallStatusUpdate()
cache_tmp = apt.Cache()
cache_tmp.update()
cache_tmp.open(None)
for pkg in pkg_list:
try:
self.pkgname = cache_tmp[pkg.name]
if self.pkgname.is_installed and self.pkgname.is_upgradable:
self.pkgname.mark_upgrade()
else:
self.pkgname.mark_install()
except Exception as e:
print e.message
result = self.pkgname.commit(fprogress, iprogress)
#Maybe i'm doing something wrong here but result always = None...