Created
February 13, 2013 01:37
-
-
Save funkaoshi/4827204 to your computer and use it in GitHub Desktop.
Merge versions in two puppet files.
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 sys | |
import re | |
from pkg_resources import parse_version | |
updates = sys.stdin.read() | |
records = updates.split(';') | |
packages = {} | |
for record in records: | |
fields = [r.strip() for r in record.split('\n') if r.strip()] | |
if not fields: | |
continue | |
p = re.match(r"'(.*)':", fields[0]).group(1) # package | |
e = re.match(r"ensure\s+=>\s+'(.*)'", fields[1]).group(1) # ensure | |
v = parse_version(e) | |
if packages.has_key(p): | |
# replace the stored version number if it's smaller, otherwise | |
# no change. | |
if parse_version(packages[p]) < v: | |
print '%s: %s -> %s' % (p, packages[p], e) | |
packages[p] = e | |
elif parse_version(packages[p]) > v: | |
print '%s: %s -> %s' % (p, e, packages[p]) | |
else: | |
packages[p] = e | |
for package, ensure in sorted(packages.items()): | |
print "'%s':" % package | |
print " ensure => '%s'," % ensure | |
print " provider => 'aptitude';" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment