Por exemplo, digamos que eu queira remover o navegador chromium no ubuntu através do meu script abaixo. Como posso monitorar o progresso da remoção?
#!/usr/bin/env python
# aptremove.py
import apt
import apt_pkg
import sys
def remove():
pkg_name = "chromium-browser"
cache = apt.cache.Cache()
cache.open(None)
pkg = cache[pkg_name]
cache.update()
pkg.mark_delete(True, purge=True)
resolver = apt.cache.ProblemResolver(cache)
if pkg.is_installed is False:
print (pkg_name + " not installed so not removed")
else:
for pkg in cache.get_changes():
if pkg.mark_delete:
print pkg_name + " is installed and will be removed"
print " %d package(s) will be removed" % cache.delete_count
resolver.remove(pkg)
try:
cache.commit()
cache.close()
except Exception, arg:
print >> sys.stderr, "Sorry, package removal failed [{err}]".format(err=str(arg))
remove()