-
-
Save matthiasroos/70744952887f1a2d14aeaed7f1e810a5 to your computer and use it in GitHub Desktop.
Parse installed packages from /var/log/apt/history.log
This file contains hidden or 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/python3 | |
| import re | |
| import sys | |
| fileAPTHISTORY = sys.argv[1] | |
| INSTALL_STRING = ('Install: ', 'Upgrade: ') | |
| REMOVE_STRING = ('Remove: ', 'Purge: ') | |
| pattern = re.compile('([a-z0-9-.+]+?):[a-z0-9]+? \(.+?\),?') | |
| installed_packages_set = set() | |
| removed_packages_set = set() | |
| with open(fileAPTHISTORY, 'r') as file_handle: | |
| for line in file_handle: | |
| line = line.strip() | |
| if line.startswith(INSTALL_STRING): | |
| installed_packages_set.update(pattern.findall(line)) | |
| elif line.startswith(REMOVE_STRING): | |
| removed_packages_set.update(pattern.findall(line)) | |
| installed_packages = list(installed_packages_set) | |
| removed_packages = list(removed_packages_set) | |
| installed_packages.sort() | |
| removed_packages.sort() | |
| print(' '.join(installed_packages)) | |
| print(' '.join(removed_packages)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment