Skip to content

Instantly share code, notes, and snippets.

@iTrooz
Created November 21, 2024 13:39
Show Gist options
  • Save iTrooz/d36e7c0eed01ee77aee4a64ec2af0ed5 to your computer and use it in GitHub Desktop.
Save iTrooz/d36e7c0eed01ee77aee4a64ec2af0ed5 to your computer and use it in GitHub Desktop.
Arch list explicitly installed packages that are are depended on by other softwares
#!/usr/bin/env python3
"""
list explicitly installed packages that are are depended on by other softwares
"""
import subprocess
def parse_pacman_output(data: str):
packages = {}
current_package = None
for line in data.split("\n"):
if line.startswith('Name'):
current_package = line.split(':')[1].strip()
packages[current_package] = {'explicit': False, 'required_by': []}
elif line.startswith('Install Reason'):
if 'Explicitly installed' in line:
packages[current_package]['explicit'] = True
elif line.startswith('Required By'):
required_by = line.split(':')[1].strip()
if required_by != 'None':
packages[current_package]['required_by'] = required_by.split()
return packages
def find_explicit_and_required_packages(packages):
result = []
for package, details in packages.items():
if details['explicit'] and details['required_by']:
result.append(package)
return result
if __name__ == "__main__":
data = subprocess.check_output(['pacman', '-Qi'], text=True)
packages = parse_pacman_output(data)
explicit_and_required_packages = find_explicit_and_required_packages(packages)
for package in explicit_and_required_packages:
print(package)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment