head	1.4;
access;
symbols
	PyQwt-4_1-fixes:1.4.0.4
	PyQwt-4_1:1.4
	PyQwt-4_0rc0:1.4
	PyQwt-3_8-fixes:1.4.0.2
	PyQwt-3_8:1.4
	PyQwt-3_7:1.3
	start:1.1.1.1
	gvermeul:1.1.1;
locks; strict;
comment	@# @;


1.4
date	2003.07.14.17.35.25;	author gvermeul;	state Exp;
branches;
next	1.3;

1.3
date	2003.06.20.07.08.46;	author gvermeul;	state Exp;
branches;
next	1.2;

1.2
date	2003.06.17.07.57.59;	author gvermeul;	state Exp;
branches;
next	1.1;

1.1
date	2003.06.15.09.15.53;	author gvermeul;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	2003.06.15.09.15.53;	author gvermeul;	state Exp;
branches;
next	;


desc
@@


1.4
log
@Sync with Qwt-2003-07-14 and packaging
@
text
@#!/usr/bin/env python

import getopt
import glob
import os
import sys


def diff(suffixes, directories):
    patches = {}
    for suffix in suffixes:
        patch = ''
        for directory in directories:
            backups = glob.glob(os.path.join(directory, '*' + suffix))
            backups.sort()
            for backup in backups:
                file = backup[:-len(suffix)]
                if os.path.exists(file):
                    command = 'diff -au %s %s'% (backup, file)
                    stdin, stdout, stderr = os.popen3(command)
                    patch += stdout.read()
                    error = stderr.read()
                    print command
                    if error:
                        print error
        patches[suffix] = patch
    return patches

# diff()


def really_differ(new_patches, old_patches):
    """Checks if two dictionaries {suffix: patch} really differ.

    This function focuses on the content by skipping the patch header.
    """
    
    if type(new_patches) != type(old_patches):
        return 1
    if len(new_patches) != len(old_patches):
        return 1
    for key, new_value in new_patches.items():
        if not old_patches.has_key(key):
            return 1
        old_value = old_patches[key]
        new_lines = new_value.split('\n')
        old_lines = old_value.split('\n')
        if len(new_lines) != len(old_lines):
            return 1
        for new_line, old_line in zip(new_lines, old_lines):
            if new_line[:3] == '---' and old_line[:3] == '---':
                if new_line.split()[1] != old_line.split()[1]:
                    return 1
                continue
            if new_line[:3] == '+++' and old_line[:3] == '+++':
                if new_line.split()[1] != old_line.split()[1]:
                    return 1
                continue
            if new_line != old_line:
                return 1
    return 0

# really_differ()
    
    
def usage():
    print "DIFFER [-h] [-d 'dir1 dir2 ..'] [-s 'suf1 suf2 ..']" 

# usage()


def main():
    try:
        options, arguments = getopt.getopt(sys.argv[1:], "hs:d:")
    except getopt.GetoptError:
        usage()
        sys.exit()

    suffixes = []
    directories = []
    for (option, argument) in options:
        if option in ('-d', '--directories'):
            directories = argument.split()
        elif option in ('-h', '--help'):
            usage()
            sys.exit()
        elif option in ('-s', '--suffixes'):
            suffixes = argument.split()

    if os.path.exists('patches.py'):
        local = {}
        execfile('patches.py', globals(), local)
        old_patches = local['patches']
    else:
        old_patches = {}

    patches = diff(suffixes, directories)

    if really_differ(patches, old_patches):
        output = open('patches.py', 'w')
        print >> output, 'patches =', patches
        for suffix, patch in patches.items():
            output = open('qwt%s.patch' % suffix, 'w')
            print >> output, patch,

# main()


if __name__ == '__main__':
    main()

# Local Variables: ***
# mode: python ***
# End: ***
@


1.3
log
@Minimize regeneration of patches.py
@
text
@d102 1
a102 1
        for suffix, patch in patches.items:
@


1.2
log
@Minimize regeneration of patches.py
@
text
@d9 2
a10 2
def differ(suffixes, directories):
    patches = []
d15 1
d19 2
a20 2
                    stdin, stdout = os.popen2('diff -au %s %s'
                                              % (backup, file))
d22 5
a26 1
        patches.append((suffix, patch))
d29 1
a29 1
# differ()
d31 35
d71 1
d95 3
a97 1
        old_patches = []
d99 1
a99 3
    patches = differ(suffixes, directories)
    
    if patches != old_patches:
d102 1
a102 1
        for suffix, patch in patches:
d107 1
@


1.1
log
@Initial revision
@
text
@d3 1
d6 1
a6 1
import popen2
d8 61
a68 28
suffixes = [
    '.array',
    '.canvas',
    '.version'
    ]

directories = [
    os.path.join('qwt-sources', 'include'),
    os.path.join('qwt-sources', 'src')
    ]

patches = []

for suffix in suffixes:
    patch = ''
    for directory in directories:
        backups = glob.glob(os.path.join(directory, '*' + suffix))
        for backup in backups:
            file = backup[:-len(suffix)]
            if os.path.exists(file):
                stdin, stdout = os.popen2('diff -au %s %s' % (backup, file))
                patch += stdout.read() 
    patches.append((suffix, patch))
    output = open('qwt%s.patch' % suffix, 'w')
    print >> output, patch,
                
output = open('patches.py', 'w')
print >> output, 'patches =', patches    
a72 1

@


1.1.1.1
log
@Initial import into CVS
@
text
@@
