Tôi đang kiểm tra ra mã này được cung cấp bởi python_apt
nhưng nó dường như là một chút lỗi thời:Làm thế nào để kiểm tra tiến trình commit() trong python_apt bằng cách sử dụng lớp apt.progress?
https://github.com/jolicloud/python-apt/blob/master/doc/examples/inst.py
Tất cả Tôi đang cố gắng làm ở đây là làm theo sự tiến bộ của phương pháp commit()
; hiện tại khi chúng tôi gọi commit()
và vượt qua trong fprogress
và iprogress
, tôi có thể thấy trên bảng điều khiển rằng tất cả các gói trong số pkg_list
được tải xuống chính xác, sự cố có vẻ như sau này.
Chương trình tiếp tục thực thi và nó không kích hoạt dpkg_status_change()
như tôi tin?
Tôi không biết cách cài đặt nhiều gói có thành công không?
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...