Skip to content

Instantly share code, notes, and snippets.

@cryzed
Last active January 6, 2017 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cryzed/0b88defc9371cf76b2f5c8d52685732c to your computer and use it in GitHub Desktop.
Save cryzed/0b88defc9371cf76b2f5c8d52685732c to your computer and use it in GitHub Desktop.
import os
import shlex
import subprocess
PATH = '/usr/lib/python3.5/site-packages'
def main():
if not os.path.exists(PATH):
print(PATH, 'could not be found. No packages will need to be rebuilt.')
return
packages = set()
for name in os.listdir(PATH):
command = ['pacman', '-Qoq', os.path.join(PATH, name)]
try:
output = subprocess.check_output(command, stderr=subprocess.PIPE, universal_newlines=True)
except subprocess.CalledProcessError as exception:
print(f'Failed to execute "{" ".join(shlex.quote(part) for part in command)}": {exception.stderr.strip()}')
continue
# a file or folder might be owned by many packages, for example __pycache__
packages.update(output.strip().split('\n'))
print('The following packages will need to be rebuilt:', ' '.join(sorted(packages)))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment