Created
February 21, 2014 12:18
-
-
Save bchretien/9133305 to your computer and use it in GitHub Desktop.
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 python2 | |
import subprocess | |
import re | |
pkg_list = subprocess.check_output(['pacman','-Qii']) | |
pkg_list = re.split("\n\n", pkg_list)[:-1] | |
# List of dictionaries containing, for each package, its name and what it provides | |
pkg_info = list() | |
pattern_dict = {'name': r"Name[ ]*: ([\w_.-]*)", | |
'provides': r"Provides[ ]*: ([\w_.-]*)"} | |
for pkg in pkg_list: | |
filtered_data = re.split("\n", pkg) | |
filtered_dict = dict() | |
for data in filtered_data: | |
for field,pattern in pattern_dict.iteritems(): | |
m = re.search(pattern, data) | |
if m: | |
filtered_dict[field] = m.groups()[0] | |
if len(filtered_dict) > 0: | |
pkg_info.append(filtered_dict) | |
# Search for names and provides: | |
def find_providers(pkg_name): | |
""" | |
Search for packages providing "pkg_name". | |
""" | |
providers = list() | |
for pkg in pkg_info: | |
for value in pkg.values(): | |
if value == pkg_name: | |
providers.append(pkg['name']) | |
return providers | |
print find_providers("ogre") | |
print find_providers("yaml-cpp") | |
print find_providers("sddm") | |
print find_providers("vim") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment