#!/usr/bin/python

# Copyright (C) 2007 Jan Luebbe <jluebbe@lasnet.de>
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import os
from os.path import isfile, join

OM_PATH='/home/jluebbe/oe/build/openmoko/om-trunk/oe'
OE_PATH='/home/jluebbe/oe/build/openmoko/org.openembedded.dev'
DEST_PATH='/home/jluebbe/oe/build/openmoko/oe-overlay-diff'

os.system('rm -rf %s' % (DEST_PATH, ))
for (dirpath, dirnames, filenames) in os.walk(OM_PATH):
  subdir = dirpath[len(OM_PATH)+1:]
  for filename in filenames:
    subpath = join(subdir, filename)
    if isfile(join(OE_PATH, subpath)):
      os.system('mkdir -p %s' % (join(DEST_PATH, 'changed', subdir), ))
      print "Changed: ", filename
      os.system('diff -urN %s %s > %s.diff' % (
        join(OE_PATH, subpath), join(OM_PATH, subpath),
        join(DEST_PATH, 'changed', subpath)
        ))
      os.system('wdiff %s %s > %s.wdiff' % (
        join(OE_PATH, subpath), join(OM_PATH, subpath),
        join(DEST_PATH, 'changed', subpath)
        ))
    else:
      os.system('mkdir -p %s' % (join(DEST_PATH, 'added', subdir), ))
      print "Added: ", filename
      os.system('diff -urN /dev/null %s > %s' % (
        join(OM_PATH, subpath),
        join(DEST_PATH, 'added', subpath)
        ))


