martinrusev
4/20/2014 - 10:17 AM

Checks for available package updates in Ubuntu

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()