Skip to content

Instantly share code, notes, and snippets.

@rafael-neri
Created February 19, 2015 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafael-neri/8ebb3ec493e8e8a6cf87 to your computer and use it in GitHub Desktop.
Save rafael-neri/8ebb3ec493e8e8a6cf87 to your computer and use it in GitHub Desktop.
Instalando aplicativo usando python-apt
#!/usr/bin/env python
# aptinstall.py
import apt
import sys
pkg_name = "firefox"
cache = apt.cache.Cache()
cache.update()
pkg = cache[pkg_name]
if pkg.is_installed:
print "{pkg_name} ja esta instalado".format(pkg_name=pkg_name)
else:
pkg.mark_install()
try:
cache.commit()
except Exception, arg:
print >> sys.stderr, "Desculpa, a instalacao do pacote falhou [{err}]".format(err=str(arg))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment