From 0303dc173a59e1827630150ac7fbb4e19446adfb Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 8 Apr 2010 22:47:39 -0400 Subject: [PATCH] [liveimage-diff] New tool to diff livecds --- tools/liveimage-diff | 83 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100755 tools/liveimage-diff diff --git a/tools/liveimage-diff b/tools/liveimage-diff new file mode 100755 index 0000000..3722431 --- /dev/null +++ b/tools/liveimage-diff @@ -0,0 +1,83 @@ +#!/usr/bin/python +# Given as input two live images, print out differences in their RPM content. +# +# Licensed under the new-BSD license (http://www.opensource.org/licenses/bsd-license.php) +# Copyright (C) 2010 Red Hat, Inc. +# Written by Colin Walters + +import os +import sys +import tempfile +import subprocess +import getopt + + +def usage(ecode): + print "Usage: %s img1.iso img2.iso" % (sys.argv[0], ) + print "Print differences between two live images" + sys.exit(ecode) + +def main(): + try: + opts,args = getopt.getopt(sys.argv[1:], 'h', ['help', 'debug']) + except getopt.GetoptError, e: + usage(1) + + version = None + debug = False + for o,a in opts: + if o in ('-h', '--help'): + usage(0) + elif o in ('--debug', ): + debug = True + + if len(args) != 2: + usage(1) + original = args[0] + new = args[1] + + mount_temp = tempfile.mkdtemp() + + (fd, original_rpmdata) = tempfile.mkstemp() + subprocess.check_call(['../livecd/tools/liveimage-mount', '--mount-hacks', '--chroot', + original, mount_temp, 'rpm', '-qa', '--queryformat="%{NAME} %{SIZE}\n'], + stdout=fd, stderr=sys.stderr) + os.close(fd) + (fd, new_rpmdata) = tempfile.mkstemp() + subprocess.check_call(['../livecd/tools/liveimage-mount', '--mount-hacks', '--chroot', + new, mount_temp, 'rpm', '-qa', '--queryformat="%{NAME} %{SIZE}\n'], + stdout=fd, stderr=sys.stderr) + os.close(fd) + + os.rmdir(mount_temp) + + original_rpms = {} + new_rpms = {} + + def read_rpmdata(filename, data): + f = open(filename) + for line in f: + line = line.strip() + if not line: break + (rpm, size) = line.split(' ', 1) + data[rpm] = int(size) + f.close() + read_rpmdata(original_rpmdata, original_rpms) + read_rpmdata(new_rpmdata, new_rpms) + + for rpm in original_rpms: + if rpm in new_rpms: + sizedelta = new_rpms[rpm] - original_rpms[rpm] + print '= %s: %d' % (rpm, sizedelta) + else: + print "- %s %d" % (rpm, original_rpms[rpm]) + for rpm in new_rpms: + if rpm in original_rpms: + continue + print "+ %s %d" % (rpm, new_rpms[rpm]) + + sys.exit(0) + +if __name__ == '__main__': + main() +