Skip to content

Instantly share code, notes, and snippets.

@lost-theory
Created September 18, 2012 22:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save lost-theory/3746543 to your computer and use it in GitHub Desktop.
Save lost-theory/3746543 to your computer and use it in GitHub Desktop.
chef cookbook diff
#!/usr/bin/env python
'''\
Usage: cookbookdiff COOKBOOK_NAME COOKBOOK_VER LOCAL_PATH [--nocolor]
Diff your LOCAL_PATH against what is on the chef server for a
given cookbook and version.
--nocolor: don't pipe output through 'colordiff' (in case you want to pipe to something else)
Examples:
cookbookdiff percona_toolkit 0.0.4 ~/chef-repo/cookbooks/percona_toolkit
cookbookdiff percona_toolkit 0.0.4 ~/chef-repo/cookbooks/percona_toolkit --nocolor
'''
import os
def system(cmd):
print "#", cmd
os.system(cmd)
def main(name, ver, local, color):
system("rm -rf /tmp/%s-%s" % (name, ver))
system("knife cookbook download %s %s -d /tmp/" % (name, ver))
pipeoutput = "| colordiff" if color else ""
system("diff -ur %s /tmp/%s-%s %s" % (local, name, ver, pipeoutput))
if __name__ == "__main__":
import sys
sys.argv.pop(0)
try:
(name, ver, local) = sys.argv[:3]
sys.argv = sys.argv[3:]
except ValueError:
print __doc__
raise SystemExit(1)
color = '--nocolor' not in sys.argv
main(name, ver, local, color)
require 'chef/knife'
class CookbookDiff < Chef::Knife
banner "knife cookbook diff NAME VERSION LOCALPATH"
option :nocolor,
:long => '--nocolor',
:boolean => true,
:description => "Turn off colordiff (if you don't have it or want to pipe to something else)"
def run
name, ver, local = name_args
if [name,ver,local].include?(nil)
show_usage
exit 1
end
pipeoutput = config[:nocolor] ? "" : "| colordiff"
system("rm -rf /tmp/#{name}-#{ver}")
system("knife cookbook download #{name} #{ver} -d /tmp/")
system("diff -ur #{local} /tmp/#{name}-#{ver} #{pipeoutput}")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment