0
私はLinux mintでこれを試していました。私はpython-apt APIを使ってパッケージを削除する方法を研究してきました。以下のコードは私が思いつくことができたものでしたが、実行すると何も起こりません。私は今、単一のパッケージを削除しようとしていますが、後で、テキストファイルからパッケージのリストを削除したいと思います。 this postにある答えを使用しようとしましたが、削除のために再設計しましたが、ロジックが機能しません。入力をお願いします。python apt APIを使ってdebianパッケージを削除するには
#!/usr/bin/env python
# aptuninnstall.py
import apt
import sys
def remove():
pkg_name = "chromium-browser"
cache = apt.cache.Cache()
cache.update()
pkg = cache[pkg_name]
pkg.marked_delete
resolver = apt.cache.ProblemResolver(cache)
for pkg in cache.get_changes():
if pkg.is_installed:
resolver.remove(pkg)
else:
print (pkg_name + " not installed so not removed")
try:
cache.commit()
except Exception, arg:
print >> sys.stderr, "Sorry, package removal failed [{err}]".format(err=str(arg))
remove()