Last active
May 21, 2020 00:21
-
-
Save seasonedgeek/34cb1c3dd03291f5bbef67e24a55a0b2 to your computer and use it in GitHub Desktop.
Identifies outdated packages managed by Homebrew and then automates each package's upgrade process.
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
"""This module seeks to help the user save time, by identifying outdated | |
packages managed by Homebrew and then automating each package's upgrade | |
processes.""" | |
#!/usr/bin/env python3 | |
import subprocess | |
def main(): | |
"""Function creates a list of outdated packages to upgrade (if any)""" | |
# create a list of outdated packages | |
completedProcess = subprocess.run(["brew", "outdated"], capture_output=True, text=True) | |
if completedProcess.returncode == 0: | |
package_names = completedProcess.stdout | |
package_names_list = package_names.split('\n') | |
# attempt to upgrade each named package | |
for package_name in package_names_list: | |
if len(package_name) > 0: | |
upgrade_process = subprocess.run(["brew", "upgrade", package_name]) | |
process_result = 'Yes' if upgrade_process.returncode == 0 else 'No' | |
print(f"--> '{package_name}' upgraded? {process_result}") | |
if __name__ == "__main__": | |
# execute only if run as a script | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment