Created
May 29, 2018 10:51
-
-
Save hoefling/314565368a66c308b4d7d407a3028cb7 to your computer and use it in GitHub Desktop.
List python packages with Pacman package owners, see https://unix.stackexchange.com/questions/444195/
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 python3 | |
import operator | |
import subprocess | |
import sys | |
import pkg_resources | |
try: | |
from pip._internal.commands.list import tabulate | |
except ImportError: | |
from pip.commands.list import tabulate | |
def query(file): | |
proc = subprocess.Popen(['pacman', '-Qqo', file], stdout=subprocess.PIPE, | |
stderr=subprocess.PIPE, universal_newlines=True) | |
out, err = proc.communicate() | |
return out.strip() | |
def main(): | |
packages = sorted(pkg_resources.WorkingSet(), key=operator.attrgetter('project_name')) | |
if not packages: | |
return 0 | |
data = [(pkg.project_name, pkg.version, query(pkg.egg_info or pkg.path), ) for pkg in packages] | |
data.insert(0, ('Package', 'Version', 'Owner', )) | |
rows, sizes = tabulate(data) | |
rows.insert(1, ' '.join(map(lambda x: '-' * x, sizes))) | |
for row in rows: | |
print(row) | |
return 0 | |
if __name__ == '__main__': | |
sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage example:
tqdm
has noOwner
, as expected.For more info, check out this answer on Unix & Linux SO site.