Skip to content

Instantly share code, notes, and snippets.

@martinrusev
Created April 20, 2014 10:17
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 martinrusev/11110503 to your computer and use it in GitHub Desktop.
Save martinrusev/11110503 to your computer and use it in GitHub Desktop.
Checks for available package updates in Ubuntu
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