Created
February 19, 2015 20:25
-
-
Save rafael-neri/8ebb3ec493e8e8a6cf87 to your computer and use it in GitHub Desktop.
Instalando aplicativo usando python-apt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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