Created
April 3, 2014 16:19
-
-
Save flyte/9957604 to your computer and use it in GitHub Desktop.
Loop through cookbook directories and find out which versions you've got.
This file contains hidden or 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 os | |
from distutils.version import LooseVersion as Version | |
if __name__ == "__main__": | |
cb_versions = {} | |
for cb_dir in os.listdir("."): | |
if cb_dir.startswith("cookbooks"): | |
print "Scanning %s" % cb_dir | |
for cb in os.listdir(cb_dir): | |
if not os.path.isdir(os.path.join(cb_dir, cb)): | |
print "Skipping %s as it is not a directory" % cb | |
continue | |
try: | |
metadata = open(os.path.join(cb_dir, cb, "metadata.rb")).readlines() | |
except IOError, e: | |
print "Failed to open metadata.rb: %s" % e | |
continue | |
version_line = [x for x in metadata if x.startswith("version")][0] | |
version = Version(version_line.split()[1].strip('"')) | |
if cb in cb_versions and cb_versions[cb] >= version: | |
continue | |
if cb in cb_versions: | |
print "Replacing %s with new version." % cb | |
cb_versions[cb] = version | |
print cb_versions |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment