Created
June 12, 2013 03:38
-
-
Save adam-stokes/5762670 to your computer and use it in GitHub Desktop.
Python generator for searching if a package is installed on an Ubuntu system
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
import apt_pkg | |
def packages(): | |
""" Generator that returns all packages found on system | |
""" | |
apt_pkg.init_config() | |
apt_pkg.init_system() | |
package_cache = apt_pkg.Cache() | |
for package in package_cache.packages: | |
if package.current_state is apt_pkg.CURSTATE_INSTALLED: | |
yield package.name | |
def is_installed(package): | |
""" Checks if package is installed | |
""" | |
return any(package in x for x in packages()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment