Last active
April 15, 2020 11:54
-
-
Save iainlane/10465ca8f5ddb1c90950ed836f9cf778 to your computer and use it in GitHub Desktop.
should we remove this?
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 apt | |
| import sys | |
| def should_we_remove(pkg_name): | |
| cache = apt.cache.Cache() | |
| try: | |
| pkg = cache[pkg_name] | |
| except KeyError: | |
| return False | |
| # If pkg itself is not installed or is manually installed, we leave it | |
| # alone | |
| if not (pkg.installed and pkg.is_auto_installed): | |
| return False | |
| pkg.mark_delete() | |
| for pkg in cache.get_changes(): | |
| # If this resulted in anything else that the user manually installed | |
| # being uninstalled too, they wanted the package, so keep it. | |
| if ( | |
| pkg.is_installed | |
| and not pkg.is_auto_installed | |
| and pkg.marked_delete | |
| and pkg.name != pkg_name | |
| ): | |
| ret = False | |
| break | |
| else: | |
| ret = True | |
| # Don't really do it | |
| cache.clear() | |
| return ret | |
| if __name__ == "__main__": | |
| print(f"Should we remove {sys.argv[1]}? {should_we_remove(sys.argv[1])}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment