Skip to content

Instantly share code, notes, and snippets.

@martinrusev
Created April 20, 2014 12:52
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/11113482 to your computer and use it in GitHub Desktop.
Save martinrusev/11113482 to your computer and use it in GitHub Desktop.
Checks for available package updates in CentOS
# Run in Docker
# docker run -v /home/martin/temp/:/var/scripts -i -t centos:latest python /var/scripts/packagecentos.py
import subprocess
import re
installed_packages_dict = {}
installed_packages = subprocess.Popen(["yum",'--color=never','list', 'installed'], stdout=subprocess.PIPE, close_fds=True,
).communicate()[0]
for index, line in enumerate(installed_packages.splitlines()):
regex = re.compile('^(.*?)\s+(.*?)\s+@(.*)$')
match = regex.match(line)
if match:
name, version, repo = match.groups()
installed_packages_dict[name] = version
packages_for_upgrade_list = []
packages_for_upgrade = subprocess.Popen(["yum",'check-update'], stdout=subprocess.PIPE, close_fds=True,
).communicate()[0]
for index, line in enumerate(packages_for_upgrade.splitlines()):
regex = re.compile('^(\S+\.\S+)\s+(\S+)\s+\S+$')
match = regex.match(line)
if match:
name, new_version = match.groups()
# Check if this version is new
currently_installed_version = installed_packages_dict.get(name)
if currently_installed_version != None:
if currently_installed_version != new_version:
package_dict = {'name': name,
'current_version': currently_installed_version,
'new_version': new_version
}
packages_for_upgrade_list.append(package_dict)
print packages_for_upgrade_list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment