Created
April 20, 2014 10:17
-
-
Save martinrusev/11110503 to your computer and use it in GitHub Desktop.
Checks for available package updates in Ubuntu
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
import subprocess | |
import re | |
packages_for_upgrade = subprocess.Popen(["apt-get",'-q','-V', '-s', 'upgrade', '2>&1'], stdout=subprocess.PIPE, close_fds=True, | |
).communicate()[0] | |
upgrades_index = False | |
for index, line in enumerate(packages_for_upgrade.splitlines()): | |
if line.startswith('The following packages will be upgraded'): | |
upgrades_index = True | |
if upgrades_index is True: | |
regex = re.compile('^\s+(\S+)\s+\((\S+)\s+=>\s+(\S+)\)') | |
match = regex.match(line) | |
if match: | |
name, current, updated = match.groups() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment