by using python apt, i can install packages. Before and after installing the package, i updated the cache. However, before and after installing the package, is_installed returns the same, in other words, it gives wrong result.
After installing the package, i need to check whether the package is installed or not. Here is my code :
import apt.cache
def cache_update():
cache = apt.cache.Cache()
cache.update()
pkg = cache["p7zip-full"]
print pkg.is_installed # prints false
if pkg.is_installed:
print "it is already installed. Invalid request! "
pkg.mark_delete()
else:
print "it is not installed.Now you are installing..."
pkg.mark_install()
cache.commit()
print "DONE."
cache.update()
print pkg.is_installed # prints false.
if __name__ == '__main__':
cache_update()