head	1.18;
access;
symbols
	start:1.1.1.1 gvermeul:1.1.1;
locks; strict;
comment	@# @;


1.18
date	2010.07.08.05.21.53;	author gvermeul;	state Exp;
branches;
next	1.17;

1.17
date	2009.09.19.03.55.30;	author gvermeul;	state Exp;
branches;
next	1.16;

1.16
date	2009.04.18.07.15.40;	author gvermeul;	state Exp;
branches;
next	1.15;

1.15
date	2008.05.25.08.20.53;	author gvermeul;	state Exp;
branches;
next	1.14;

1.14
date	2008.05.16.16.25.43;	author gvermeul;	state Exp;
branches;
next	1.13;

1.13
date	2008.05.04.16.50.09;	author gvermeul;	state Exp;
branches;
next	1.12;

1.12
date	2008.04.05.12.52.41;	author gvermeul;	state Exp;
branches;
next	1.11;

1.11
date	2008.04.05.09.40.05;	author gvermeul;	state Exp;
branches;
next	1.10;

1.10
date	2008.03.23.18.04.57;	author gvermeul;	state Exp;
branches;
next	1.9;

1.9
date	2008.03.23.08.58.02;	author gvermeul;	state Exp;
branches;
next	1.8;

1.8
date	2008.03.22.12.06.01;	author gvermeul;	state Exp;
branches;
next	1.7;

1.7
date	2007.07.10.04.13.43;	author gvermeul;	state Exp;
branches;
next	1.6;

1.6
date	2007.03.20.11.18.29;	author gvermeul;	state Exp;
branches;
next	1.5;

1.5
date	2007.01.07.22.18.41;	author gvermeul;	state Exp;
branches;
next	1.4;

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

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

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

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

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


desc
@@


1.18
log
@Fix custom scales.
Fix QwtText assingment helper bug.
@
text
@#!/usr/bin/env python

import cStringIO
import difflib
import glob
import os
import pprint
import re
import shutil
import sys

from distutils.dep_util import newer

from declaration import *
from gccxmlparser import GccXmlParser
from boilerplate import head, keywords, tail, sip_spec_for
import fill


def get_exported_classes(headers, export_specifier):
    result = {}

    pattern = re.compile(
        r'\s*(class)\s+(%s)\s+(?P<name>\w+)' % export_specifier
        )

    for header in headers:
        classes = []
        for line in open(header):
            match = re.match(pattern, line)
            if match:
                table = match.groupdict()
                classes.append(table['name'])
        result[header] = classes

    return result

# get_exported_classes

def get_qt_access(headers):
    result = {}
    pattern = re.compile(r'\s*Q_OBJECT'
                        '|\s*public\s+slots\s*:'
                        '|\s*protected\s+slots\s*:'
                        '|\s*private\s+slots\s*:'
                        '|\s*signals\s*:'
                        '|\s*public\s*:'
                        '|\s*protected\s*:'
                        '|\s*private\s*:'
                        )
    for header in headers:
        tags = []
        for i, line in enumerate(open(header)):
            match = re.match(pattern, line)
            if match:
                if match.group(0).endswith('Q_OBJECT'):
                    tags.append((i+1, 'Q_OBJECT'))
                else:
                    # remove trailing ':' and collapse multiple spaces
                    tags.append((i+1, ' '.join(match.group(0)[:-1].split())))
        result[header] = tags

    return result

# get_qt_access()


def run_gccxml(gccxml, input_files, exported_classes, xmldir, force=False):
    output_files = []
    for header_file in input_files:
        class_names = exported_classes.get(header_file, [])
        if class_names == []:
            continue
        xml_file = os.path.join(
            xmldir,
            os.path.splitext(os.path.basename(header_file))[0]) + '.xml'
        output_files.append((header_file, xml_file))

        if newer(header_file, xml_file) or force:
            command = gccxml % (header_file, xml_file, ','.join(class_names))
            print command
            os.system(command)
            
    return output_files

# run_gccxml()


def xml2sip(header_file, xml_file, sip_file,
            exported_classes, qt_access, substitutions, force=False):
    if newer(xml_file, sip_file) or force:
        parser = GccXmlParser()
        parser.parse(xml_file)

        print "Handling", header_file

        declarations = []
        chunks = [head]
        contents = []
        skip = ['QwtCPointerData']

        name2key = {}
        for key, (what, declaration) in parser.elements.iteritems():
            if (isinstance(declaration, Class)
                and declaration.name in exported_classes
                and declaration.name not in skip
                and declaration.location[0] == header_file
                and type(declaration) != NestedClass
                ):
                name2key[declaration.name] = key

        names = name2key.keys()
        names.sort()

        for name in names:
            what, declaration = parser.elements[name2key[name]]
            print '..', declaration.name, '..'
            contents.append(declaration.name)
            declaration.qtfy(qt_access)
            chunks.append(declaration.sipify(
                excluded_bases=[],
                ))

        if not contents:
            print "Skipping", header_file
            return

        keywords['description'] = sip_spec_for(contents)
        chunks[0] %= keywords
        chunks.append(tail)

        text = '\n\n'.join(chunks)
        for old, new in substitutions:
            text = text.replace(old, new)

        lines = text.split('\n')
        for (i, line) in enumerate(lines):
            target = line[:]
            if target.startswith('    const') and target.endswith(' const;'):
                target = target.replace('    const ', '    ', 1)
                target = target.replace(' const;', ';')
                if target != line and -1 != text.find(target):
                    lines[i] = line.replace(
                        '    const', '    // signature: const')

        text = '\n'.join(lines)

        open(sip_file, 'w').write(text)

# xml2sip()


def run_xml2sip(input_files, sipdir,
                exported_classes, qt_access, substitutions, force=False):
    output_files = []
    for header_file, xml_file in input_files:
        sip_file = os.path.join(
            sipdir,
            os.path.splitext(os.path.basename(xml_file))[0]) + '.sip'
        output_files.append((header_file, xml_file, sip_file))

        if not (newer(xml_file, sip_file) or force):
            continue

        xml2sip(header_file,
                xml_file,
                sip_file,
                exported_classes[header_file],
                qt_access[header_file],
                substitutions)
        
    return output_files

# run_xml2sip()


def run_h2sip(pyqwt, sources, mix, gccxml, substitutions, force=False):
    for d in (os.path.join('xml', mix), os.path.join('sip', mix)):
        if not os.path.exists(d):
            os.makedirs(d)
    headers = glob.glob(os.path.join(os.pardir, pyqwt, sources))
    exported_classes = get_exported_classes(headers, 'QWT_EXPORT')
    qt_access = get_qt_access(headers)
    xml_files = run_gccxml(gccxml,
                           headers,
                           exported_classes,
                           os.path.join('xml', mix),
                           force)
    sip_files = run_xml2sip(xml_files,
                            os.path.join('sip', mix),
                            exported_classes,
                            qt_access,
                            substitutions,
                            force)

# def run_h2sip()


def merge(texts):
    if len(texts) == 1:
        return texts.values()[0]
    timelines = sorted(texts.keys())
    timelines.append('')
    heads = []
    bodies = []
    tails = []
    for (t0, t1) in zip(timelines[:-1], timelines[1:]):
        text = texts[t0]
        i = text.find(os.linesep*3)+len(os.linesep)*3
        j = text.find(os.linesep*3+'//', i)
        head = text[:i-len(os.linesep)]
        if head not in heads:
            heads.append(head)
        body = text[i:j]
        body = ('\n%%If (%s - %s)\n'
                '%s'
                '\n%%End // (%s - %s)\n') % (t0, t1, body, t0, t1)
        bodies.append(body)
        tail = text[j+len(os.linesep):]
        if tail not in tails:
            tails.append(tail)
    chunks = []
    chunks.extend(heads)
    chunks.extend(bodies)
    chunks.extend(tails)
    return ''.join(chunks)

# merge()


def main():
    force = False
    run_h2sip('pyqwt4',
              os.path.join('qwt-4.2.0', 'include', '*.h'),
              '4.2.0-3.3.8',
              ('gccxml'
               ' -I.'
               ' -I/home/gav/usr/lib/qt3.3/include'
               ' %s -fxml=%s -fxml-start=%s'),
              (('QMemArray<double>', 'QwtArrayDouble'),
               ('QMemArray<int>', 'QwtArrayInt',),
               ('QMemArray<long int>', 'QwtArrayLong',),
               ('QMemArray<QwtDoublePoint>', 'QwtArrayQwtDoublePoint'),
               ('QwtPlotItemList', 'QValueList<QwtPlotItem*>'),
               ),
              force)
 
    for sources, mix in (
        (os.path.join('qwt-5.0.0', 'src', '*.h'), '5.0.0-3.3.8'),
        (os.path.join('qwt-5.0.1', 'src', '*.h'), '5.0.1-3.3.8'),
        (os.path.join('qwt-5.0.2', 'src', '*.h'), '5.0.2-3.3.8'),
        (os.path.join('qwt-5.1.0', 'src', '*.h'), '5.1.0-3.3.8'),
        (os.path.join('qwt-5.1.1', 'src', '*.h'), '5.1.1-3.3.8'),
        (os.path.join('qwt-5.1.2', 'src', '*.h'), '5.1.2-3.3.8'),
        (os.path.join('qwt-5.2.0', 'src', '*.h'), '5.2.0-3.3.8'),
        (os.path.join('qwt-5.0', 'src', '*.h'), '5.0.3-3.3.8'),
        (os.path.join('qwt-5.1', 'src', '*.h'), '5.1.3-3.3.8'),
        (os.path.join('qwt-5.2', 'src', '*.h'), '5.2.1-3.3.8'),
        ):
        run_h2sip('pyqwt5',
                  sources,
                  mix,
                  ('gccxml'
                   ' -I.'
                   ' -I/home/gav/usr/lib/qt3.3/include'
                   ' %s -fxml=%s -fxml-start=%s'),
                  (('QMemArray<double>', 'QwtArrayDouble'),
                   ('QMemArray<int>', 'QwtArrayInt',),
                   ('QMemArray<QwtDoublePoint>', 'QwtArrayQwtDoublePoint'),
                   ('QwtPlotItemList', 'QValueList<QwtPlotItem*>'),
                   ),
                  force)

    for sources, mix in (
        (os.path.join('qwt-5.0.0', 'src', '*.h'), '5.0.0-4.6.3'),
        (os.path.join('qwt-5.0.1', 'src', '*.h'), '5.0.1-4.6.3'),
        (os.path.join('qwt-5.0.2', 'src', '*.h'), '5.0.2-4.6.3'),
        (os.path.join('qwt-5.1.0', 'src', '*.h'), '5.1.0-4.6.3'),
        (os.path.join('qwt-5.1.1', 'src', '*.h'), '5.1.1-4.6.3'),
        (os.path.join('qwt-5.1.2', 'src', '*.h'), '5.1.2-4.6.3'),
        (os.path.join('qwt-5.2.0', 'src', '*.h'), '5.2.0-4.6.3'),
        (os.path.join('qwt-5.0',   'src', '*.h'), '5.0.3-4.6.3'),
        (os.path.join('qwt-5.1',   'src', '*.h'), '5.1.3-4.6.3'),
        (os.path.join('qwt-5.2',   'src', '*.h'), '5.2.1-4.6.3'),
        ):
        run_h2sip('pyqwt5',
                  sources,
                  mix,
                  ('gccxml'
                   ' -I.'
                   ' -I/usr/include/qt4'
                   ' -I/usr/include/qt4/QtCore'
                   ' -I/usr/include/qt4/QtGui'
                   ' %s -fxml=%s -fxml-start=%s'),
                  (('QPointFData', 'QwtDoublePointData'),
                   ('QVector<double>', 'QwtArrayDouble'),
                   ('QVector<int>', 'QwtArrayInt'),
                   ('QVector<QPointF>', 'QwtArrayQwtDoublePoint'),
                   ('QwtPlotItemList', 'QList<QwtPlotItem*>'),
                   # FIXME: implement more restrictive replacements.
                   # This undoes replacements which are too greedy!!
                   ('QPolygonFData', 'QwtPolygonFData'),
                   ),
                  force)


    for pyqwt, target in (('pyqwt4', 'qwt4qt3'),
                          ('pyqwt5', 'qwt5qt3'),
                          ('pyqwt5', 'qwt5qt4')):
        for d in (os.path.join('sip', target),
                  os.path.join(os.pardir, pyqwt, 'sip', target)):
            if not os.path.exists(d):
                os.makedirs(d)
        fill.main(target)

    for sip_file in glob.glob(os.path.join('sip', '4.2.0-3.3.8', '*.sip')):
        shutil.copyfile(sip_file, os.path.join(
            '..', 'pyqwt4', 'sip', 'qwt4qt3', os.path.basename(sip_file)))
    for sip_file in glob.glob(os.path.join('sip', 'qwt4qt3', '*.sip')):
        shutil.copyfile(sip_file, os.path.join(
            '..', 'pyqwt4', 'sip', 'qwt4qt3', os.path.basename(sip_file)))

    jobs = {'qwt5qt3': (('Qwt_5_0_0', '5.0.0-3.3.8'),
                        ('Qwt_5_0_1', '5.0.1-3.3.8'),
                        ('Qwt_5_0_2', '5.0.2-3.3.8'),
                        ('Qwt_5_0_3', '5.0.3-3.3.8'),
                        ('Qwt_5_1_0', '5.1.0-3.3.8'),
                        ('Qwt_5_1_1', '5.1.1-3.3.8'),
                        ('Qwt_5_1_2', '5.1.2-3.3.8'),
                        ('Qwt_5_1_3', '5.1.3-3.3.8'),
                        ('Qwt_5_2_0', '5.2.0-3.3.8'),
                        ('Qwt_5_2_1', '5.2.1-3.3.8'),
                        ),
            'qwt5qt4': (('Qwt_5_0_0', '5.0.0-4.6.3'),
                        ('Qwt_5_0_1', '5.0.1-4.6.3'),
                        ('Qwt_5_0_2', '5.0.2-4.6.3'),
                        ('Qwt_5_0_3', '5.0.3-4.6.3'),
                        ('Qwt_5_1_0', '5.1.0-4.6.3'),
                        ('Qwt_5_1_1', '5.1.1-4.6.3'),
                        ('Qwt_5_1_2', '5.1.2-4.6.3'),
                        ('Qwt_5_1_3', '5.1.3-4.6.3'),
                        ('Qwt_5_2_0', '5.2.0-4.6.3'),
                        ('Qwt_5_2_1', '5.2.1-4.6.3'),
                        ),
            }
    for target, pairs in jobs.iteritems():
        sources = set()
        for timeline, mix in pairs:
            sources.update([os.path.basename(source) for source
                            in glob.glob(os.path.join('sip', mix, '*.sip'))])
        for source in sources:
            texts = {}
            old = ''
            for timeline, mix in pairs:
                try:
                    new = open(os.path.join('sip', mix, source)).read()
                    if new != old:
                        texts[timeline] = new
                        old = new
                except IOError:
                    pass
            text = merge(texts)
            if isinstance(text, str):
                open(os.path.join('sip', target, source), 'w').write(text)
        for sip_file in glob.glob(os.path.join('sip', target, '*.sip')):
            shutil.copyfile(sip_file, os.path.join('..', 'pyqwt5', sip_file))

# main()

if __name__ == '__main__':
    main()

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


1.17
log
@Copy a few remaining automagically generated files.
@
text
@d238 1
a238 1
               ' -I/usr/qt/3/include'
d265 1
a265 1
                   ' -I/usr/qt/3/include'
d275 10
a284 10
        (os.path.join('qwt-5.0.0', 'src', '*.h'), '5.0.0-4.5.0'),
        (os.path.join('qwt-5.0.1', 'src', '*.h'), '5.0.1-4.5.0'),
        (os.path.join('qwt-5.0.2', 'src', '*.h'), '5.0.2-4.5.0'),
        (os.path.join('qwt-5.1.0', 'src', '*.h'), '5.1.0-4.5.0'),
        (os.path.join('qwt-5.1.1', 'src', '*.h'), '5.1.1-4.5.0'),
        (os.path.join('qwt-5.1.2', 'src', '*.h'), '5.1.2-4.5.0'),
        (os.path.join('qwt-5.2.0', 'src', '*.h'), '5.2.0-4.5.0'),
        (os.path.join('qwt-5.0', 'src', '*.h'), '5.0.3-4.5.0'),
        (os.path.join('qwt-5.1', 'src', '*.h'), '5.1.3-4.5.0'),
        (os.path.join('qwt-5.2', 'src', '*.h'), '5.2.1-4.5.0'),
d334 10
a343 10
            'qwt5qt4': (('Qwt_5_0_0', '5.0.0-4.5.0'),
                        ('Qwt_5_0_1', '5.0.1-4.5.0'),
                        ('Qwt_5_0_2', '5.0.2-4.5.0'),
                        ('Qwt_5_0_3', '5.0.3-4.5.0'),
                        ('Qwt_5_1_0', '5.1.0-4.5.0'),
                        ('Qwt_5_1_1', '5.1.1-4.5.0'),
                        ('Qwt_5_1_2', '5.1.2-4.5.0'),
                        ('Qwt_5_1_3', '5.1.3-4.5.0'),
                        ('Qwt_5_2_0', '5.2.0-4.5.0'),
                        ('Qwt_5_2_1', '5.2.1-4.5.0'),
@


1.16
log
@Update for Qwt-5.2.
@
text
@d319 3
@


1.15
log
@Sync with Qwt-5.1.1 and Qwt subversion revision 406.
@
text
@d253 3
a255 1
        (os.path.join('qwt-5.1.1', 'src', '*.h'), '5.1.0-3.3.8'),
d257 2
a258 1
        (os.path.join('qwt-5.1', 'src', '*.h'), '5.1.1-3.3.8'),
d275 10
a284 7
        (os.path.join('qwt-5.0.0', 'src', '*.h'), '5.0.0-4.4.0'),
        (os.path.join('qwt-5.0.1', 'src', '*.h'), '5.0.1-4.4.0'),
        (os.path.join('qwt-5.0.2', 'src', '*.h'), '5.0.2-4.4.0'),
        (os.path.join('qwt-5.1.0', 'src', '*.h'), '5.1.0-4.4.0'),
        (os.path.join('qwt-5.1.1', 'src', '*.h'), '5.1.0-4.4.0'),
        (os.path.join('qwt-5.0', 'src', '*.h'), '5.0.3-4.4.0'),
        (os.path.join('qwt-5.1', 'src', '*.h'), '5.1.1-4.4.0'),
d326 4
a329 1
                        ('Qwt_5_1_2', '5.1.1-3.3.8'),
d331 10
a340 7
            'qwt5qt4': (('Qwt_5_0_0', '5.0.0-4.4.0'),
                        ('Qwt_5_0_1', '5.0.1-4.4.0'),
                        ('Qwt_5_0_2', '5.0.2-4.4.0'),
                        ('Qwt_5_0_3', '5.0.3-4.4.0'),
                        ('Qwt_5_1_0', '5.1.0-4.4.0'),
                        ('Qwt_5_1_1', '5.1.1-4.4.0'),
                        ('Qwt_5_1_2', '5.1.1-4.4.0'),
@


1.14
log
@Add the Qwt-5.1.0 release.
@
text
@d253 1
d272 7
a278 6
        (os.path.join('qwt-5.0.0', 'src', '*.h'), '5.0.0-4.3.4'),
        (os.path.join('qwt-5.0.1', 'src', '*.h'), '5.0.1-4.3.4'),
        (os.path.join('qwt-5.0.2', 'src', '*.h'), '5.0.2-4.3.4'),
        (os.path.join('qwt-5.1.0', 'src', '*.h'), '5.1.0-4.3.4'),
        (os.path.join('qwt-5.0', 'src', '*.h'), '5.0.3-4.3.4'),
        (os.path.join('qwt-5.1', 'src', '*.h'), '5.1.1-4.3.4'),
d320 1
d322 7
a328 6
            'qwt5qt4': (('Qwt_5_0_0', '5.0.0-4.3.4'),
                        ('Qwt_5_0_1', '5.0.1-4.3.4'),
                        ('Qwt_5_0_2', '5.0.2-4.3.4'),
                        ('Qwt_5_0_3', '5.0.3-4.3.4'),
                        ('Qwt_5_1_0', '5.1.0-4.3.4'),
                        ('Qwt_5_1_1', '5.1.1-4.3.4'),
@


1.13
log
@Simplify the merging of different timelines.
@
text
@d252 1
d254 1
a254 1
        (os.path.join('qwt-5.1', 'src', '*.h'), '5.1.0-3.3.8'),
d274 1
d276 1
a276 1
        (os.path.join('qwt-5.1', 'src', '*.h'), '5.1.0-4.3.4'),
d317 1
d324 1
@


1.12
log
@Code cleanup.
@
text
@d199 28
a226 47
def merge(texts, source):
    pairs = []
    versions = sorted(texts.keys())
    for (v0, v1) in zip(versions[:-1], versions[1:]):
        t0 = texts[v0]
        t1 = texts[v1]
        if t0 is not None and t1 is not None and t0 != t1:
            pairs.append((v0, v1))
    if not pairs:
        for text in texts.itervalues():
            if text is not None:
                return text
    else:
        lines = texts[versions[0]].splitlines(1)
        times = [('', '') for line in lines]
        for version in versions[1:]:
            newlines = []
            newtimes = []
            for line in difflib.Differ().compare(lines,
                                                 texts[version].splitlines(1)):
                if line[0] == ' ':
                    newlines.append(line[2:])
                    newtimes.append(times.pop(0))
                if line[0] == '+':
                    newlines.append(line[2:])
                    newtimes.append((version, ''))
                if line[0] == '-':
                    newlines.append(line[2:])
                    if times[0][1] == '':
                        newtimes.append((times.pop(0)[0], version))
                    else:
                        newtimes.append(times.pop(0))
            lines = newlines
            times = newtimes
        last = ('', '')
        io = cStringIO.StringIO()        
        for pair, line in zip(times, lines):
            if pair == last:
                io.write(line)
            else:
                if last != ('', ''):
                    io.write('%%End // (%s - %s)\n' % last)
                if pair != ('', ''):
                    io.write('%%If (%s - %s)\n' % pair)
                io.write(line)
                last = pair
        return io.getvalue(True)
d310 12
a321 12
    jobs = {'qwt5qt3': {'Qwt_5_0_0': '5.0.0-3.3.8',
                        'Qwt_5_0_1': '5.0.1-3.3.8',
                        'Qwt_5_0_2': '5.0.2-3.3.8',
                        'Qwt_5_0_3': '5.0.3-3.3.8',
                        'Qwt_5_1_0': '5.1.0-3.3.8',
                        },
            'qwt5qt4': {'Qwt_5_0_0': '5.0.0-4.3.4',
                        'Qwt_5_0_1': '5.0.1-4.3.4',
                        'Qwt_5_0_2': '5.0.2-4.3.4',
                        'Qwt_5_0_3': '5.0.3-4.3.4',
                        'Qwt_5_1_0': '5.1.0-4.3.4',
                        },
d323 1
a323 1
    for target, versions in jobs.iteritems():
d325 1
a325 1
        for directory in versions.itervalues():
d330 2
a331 1
            for timeline, directory in versions.iteritems():
d333 4
a336 1
                    text = open(os.path.join('sip', directory, source)).read()
d338 2
a339 3
                    text = None
                texts[timeline] = text
            text = merge(texts, source)
@


1.11
log
@Finish the automatic generation of all %If (v0-v1) directives.
@
text
@a346 1
        pprint.pprint(sources)
@


1.10
log
@Make a start with a code cleanup to do all %If (v0-v1) directives
properly.  Not yet finished.
@
text
@d3 1
d212 34
a245 2
        print source, pairs
        return None
a360 60
            
                                
    # FIXME: merge qwt50qt3 and qwt51qt3
##     for timeline, versions, target in (
##         ('Qwt_5_1_0', ('qwt50qt3', 'qwt51qt3'), 'qwt5qt3'),
##         ('Qwt_5_1_0', ('qwt50qt4', 'qwt51qt4'), 'qwt5qt4'),
##         ):
##         sources = set()
##         for version in versions:
##             sources.update(
##                 [os.path.basename(source) for source
##                  in glob.glob(os.path.join('sip', version, '*.sip'))])
##     for timeline, versions, target in (
##         ('Qwt_5_1_0', ('qwt50qt3', 'qwt51qt3'), 'qwt5qt3'),
##         ('Qwt_5_1_0', ('qwt50qt4', 'qwt51qt4'), 'qwt5qt4'),
##         ):
##         for source in sources:
##             texts = []
##             for version in versions:
##                 try:
##                     texts.append(
##                         open(os.path.join('sip', version, source)).read())
##                 except IOError:
##                     texts.append(None)
##             if texts[0] is None:
##                 open(os.path.join(
##                     'sip', target, source), 'w').write(texts[1])
##             elif texts[1] is None:
##                 open(os.path.join(
##                     'sip', target, source), 'w').write(texts[0])
##             elif texts[0] == texts[1]:
##                 open(os.path.join(
##                     'sip', target, source), 'w').write(texts[0])
##             else:
##                 lines = []
##                 last = ' '
##                 for line in difflib.Differ().compare(texts[0].splitlines(1),
##                                                      texts[1].splitlines(1)):
##                     if line[0] == ' ':
##                         if last == '+':
##                             lines.append('%%End // (%s -)\n' % timeline) 
##                         elif last == '-':
##                             lines.append('%%End // (- %s)\n' % timeline)
##                         lines.append(line[2:])
##                         last = ' '
##                     elif line[0] == '+':
##                         if last == '-':
##                             lines.append('%%End // (- %s)\n' % timeline)
##                         if last != '+': 
##                             lines.append('%%If (%s -)\n' % timeline)
##                         lines.append(line[2:])
##                         last = '+'
##                     elif line[0] == '-':
##                         if last == '+':
##                             lines.append('%%End // (%s -)\n' % timeline)
##                         if last != '-':
##                             lines.append('%%If (- %s)\n' % timeline)
##                         lines.append(line[2:])
##                         last = '-'
##                 open(os.path.join('sip', target, source), 'w').writelines(lines)
@


1.9
log
@A first stab at generating SIP's timeline directive.
@
text
@d89 55
a143 53
            exported_classes, qt_access, substitutions):
    parser = GccXmlParser()
    parser.parse(xml_file)

    print "Handling", header_file

    declarations = []
    chunks = [head]
    contents = []
    skip = ['QwtCPointerData']

    name2key = {}
    for key, (what, declaration) in parser.elements.iteritems():
        if (isinstance(declaration, Class)
            and declaration.name in exported_classes
            and declaration.name not in skip
            and declaration.location[0] == header_file
            and type(declaration) != NestedClass
            ):
            name2key[declaration.name] = key

    names = name2key.keys()
    names.sort()
    
    for name in names:
        what, declaration = parser.elements[name2key[name]]
        print '..', declaration.name, '..'
        contents.append(declaration.name)
        declaration.qtfy(qt_access)
        chunks.append(declaration.sipify(
            excluded_bases=[],
            ))

    if not contents:
        print "Skipping", header_file
        return
    
    keywords['description'] = sip_spec_for(contents)
    chunks[0] %= keywords
    chunks.append(tail)

    text = '\n\n'.join(chunks)
    for old, new in substitutions:
        text = text.replace(old, new)

    lines = text.split('\n')
    for (i, line) in enumerate(lines):
        target = line[:]
        if target.startswith('    const') and target.endswith(' const;'):
            target = target.replace('    const ', '    ', 1)
            target = target.replace(' const;', ';')
            if target != line and -1 != text.find(target):
                lines[i] = line.replace('    const', '    // signature: const')
d145 1
a145 1
    text = '\n'.join(lines)
d147 1
a147 1
    open(sip_file, 'w').write(text)
d176 41
d218 43
a260 78

    for pyqwt, sources, target, mix, gccxml, substitutions in (
        ('pyqwt4',
         os.path.join('qwt-4.2.0', 'include'),
         'qwt4qt3',
         'qwt4qt3',
         ('gccxml'
          ' -I.'
          ' -I/usr/qt/3/include'
          ' %s -fxml=%s -fxml-start=%s'),
         (('QMemArray<double>', 'QwtArrayDouble'),
          ('QMemArray<int>', 'QwtArrayInt',),
          ('QMemArray<long int>', 'QwtArrayLong',),
          ('QMemArray<QwtDoublePoint>', 'QwtArrayQwtDoublePoint'),
          ('QwtPlotItemList', 'QValueList<QwtPlotItem*>'),
          )),
        ('pyqwt5',
         os.path.join('qwt-5.0', 'src'),
         'qwt5qt3',
         'qwt50qt3',
         ('gccxml'
          ' -I.'
          ' -I/usr/qt/3/include'
          ' %s -fxml=%s -fxml-start=%s'),
         (('QMemArray<double>', 'QwtArrayDouble'),
          ('QMemArray<int>', 'QwtArrayInt',),
          ('QMemArray<QwtDoublePoint>', 'QwtArrayQwtDoublePoint'),
          ('QwtPlotItemList', 'QValueList<QwtPlotItem*>'),
          )),
        ('pyqwt5',
         os.path.join('qwt-5.0', 'src'),
         'qwt5qt4',
         'qwt50qt4',
         ('gccxml'
          ' -I.'
          ' -I/usr/include/qt4'
          ' -I/usr/include/qt4/QtCore'
          ' -I/usr/include/qt4/QtGui'
          ' %s -fxml=%s -fxml-start=%s'),
         (('QPointFData', 'QwtDoublePointData'),
          ('QVector<double>', 'QwtArrayDouble'),
          ('QVector<int>', 'QwtArrayInt'),
          ('QVector<QPointF>', 'QwtArrayQwtDoublePoint'),
          ('QwtPlotItemList', 'QList<QwtPlotItem*>'),
          # FIXME: implement more restrictive replacements. This undoes!!
          ('QPolygonFData', 'QwtPolygonFData'),
          )),
        ('pyqwt5',
         os.path.join('qwt-5.1', 'src'),
         'qwt5qt3',
         'qwt51qt3',
         ('gccxml'
          ' -I.'
          ' -I/usr/qt/3/include'
          ' %s -fxml=%s -fxml-start=%s'),
         (('QMemArray<double>', 'QwtArrayDouble'),
          ('QMemArray<int>', 'QwtArrayInt',),
          ('QMemArray<QwtDoublePoint>', 'QwtArrayQwtDoublePoint'),
          ('QwtPlotItemList', 'QValueList<QwtPlotItem*>'),
          )),
        ('pyqwt5',
         os.path.join('qwt-5.1', 'src'),
         'qwt5qt4',
         'qwt51qt4',
         ('gccxml'
          ' -I.'
          ' -I/usr/include/qt4'
          ' -I/usr/include/qt4/QtCore'
          ' -I/usr/include/qt4/QtGui'
          ' %s -fxml=%s -fxml-start=%s'),
         (('QPointFData', 'QwtDoublePointData'),
          ('QVector<double>', 'QwtArrayDouble'),
          ('QVector<int>', 'QwtArrayInt'),
          ('QVector<QPointF>', 'QwtArrayQwtDoublePoint'),
          ('QwtPlotItemList', 'QList<QwtPlotItem*>'),
          # FIXME: implement more restrictive replacements. This undoes!!
          ('QPolygonFData', 'QwtPolygonFData'),
          )),
d262 26
a287 6
        # setup directories
        for d in (os.path.join('xml', mix),
                  os.path.join('sip', mix),
                  os.path.join('sip', target),
                  os.path.join('..', pyqwt, 'sip', target),
                  ):
a289 20

        # get qwt header files
        headers = glob.glob(
            os.path.join('..', pyqwt, sources, '*.h'))
        exported_classes = get_exported_classes(headers, 'QWT_EXPORT')
        qt_access = get_qt_access(headers)
    
        xml_files = run_gccxml(gccxml,
                               headers,
                               exported_classes,
                               os.path.join('xml', mix),
                               force=False)

        sip_files = run_xml2sip(xml_files,
                                os.path.join('sip', mix),
                                exported_classes,
                                qt_access,
                                substitutions,
                                force=True)

d292 1
a292 1
    for sip_file in glob.glob(os.path.join('sip', 'qwt4qt3', '*.sip')):
d295 15
a309 5
    # FIXME: merge qwt50qt3 and qwt51qt3
    for timeline, versions, target in (
        ('Qwt_5_1_0', ('qwt50qt3', 'qwt51qt3'), 'qwt5qt3'),
        ('Qwt_5_1_0', ('qwt50qt4', 'qwt51qt4'), 'qwt5qt4'),
        ):
d311 4
a314 8
        for version in versions:
            sources.update(
                [os.path.basename(source) for source
                 in glob.glob(os.path.join('sip', version, '*.sip'))])
    for timeline, versions, target in (
        ('Qwt_5_1_0', ('qwt50qt3', 'qwt51qt3'), 'qwt5qt3'),
        ('Qwt_5_1_0', ('qwt50qt4', 'qwt51qt4'), 'qwt5qt4'),
        ):
d316 2
a317 2
            texts = []
            for version in versions:
d319 1
a319 2
                    texts.append(
                        open(os.path.join('sip', version, source)).read())
d321 5
a325 37
                    texts.append(None)
            if texts[0] is None:
                open(os.path.join(
                    'sip', target, source), 'w').write(texts[1])
            elif texts[1] is None:
                open(os.path.join(
                    'sip', target, source), 'w').write(texts[0])
            elif texts[0] == texts[1]:
                open(os.path.join(
                    'sip', target, source), 'w').write(texts[0])
            else:
                lines = []
                last = ' '
                for line in difflib.Differ().compare(texts[0].splitlines(1),
                                                     texts[1].splitlines(1)):
                    if line[0] == ' ':
                        if last == '+':
                            lines.append('%%End // (%s -)\n' % timeline) 
                        elif last == '-':
                            lines.append('%%End // (- %s)\n' % timeline)
                        lines.append(line[2:])
                        last = ' '
                    elif line[0] == '+':
                        if last == '-':
                            lines.append('%%End // (- %s)\n' % timeline)
                        if last != '+': 
                            lines.append('%%If (%s -)\n' % timeline)
                        lines.append(line[2:])
                        last = '+'
                    elif line[0] == '-':
                        if last == '+':
                            lines.append('%%End // (%s -)\n' % timeline)
                        if last != '-':
                            lines.append('%%If (- %s)\n' % timeline)
                        lines.append(line[2:])
                        last = '-'
                open(os.path.join('sip', target, source), 'w').writelines(lines)
d327 61
a387 1
           shutil.copyfile(sip_file, os.path.join('..', 'pyqwt5', sip_file))
@


1.8
log
@A first stab at wrapping Qwt-5.1.
@
text
@d3 1
d288 59
a346 13
    for sip_file in glob.glob(os.path.join('sip', 'qwt50qt3', '*.sip')):
        shutil.copyfile(sip_file, os.path.join(
            '..', 'pyqwt5', 'sip', 'qwt5qt3', os.path.basename(sip_file)))
    for sip_file in glob.glob(os.path.join('sip', 'qwt5qt3', '*.sip')):
        shutil.copyfile(sip_file, os.path.join(
            '..', 'pyqwt5', 'sip', 'qwt5qt3', os.path.basename(sip_file)))
    # FIXME: merge qwt50qt4 and qwt51qt4
    for sip_file in glob.glob(os.path.join('sip', 'qwt50qt4', '*.sip')):
        shutil.copyfile(sip_file, os.path.join(
            '..', 'pyqwt5', 'sip', 'qwt5qt4', os.path.basename(sip_file)))
    for sip_file in glob.glob(os.path.join('sip', 'qwt5qt4', '*.sip')):
        shutil.copyfile(sip_file, os.path.join(
            '..', 'pyqwt5', 'sip', 'qwt5qt4', os.path.basename(sip_file)))
@


1.7
log
@Adjust include paths for Qt-4.3.
----------------------------------------------------------------------
@
text
@d175 1
a175 1
    for pyqwt, sources, qwt, gccxml, substitutions in (
d179 1
d182 1
a182 1
          ' -I/home/packer/usr/lib/qt3.3/include'
d193 1
d196 1
a196 1
          ' -I/home/packer/usr/lib/qt3.3/include'
d206 1
d209 34
a242 4
          ' -I/home/packer/usr/lib/qt4.3/mkspecs/linux-g++'
          ' -I/home/packer/usr/lib/qt4.3/include'
          ' -I/home/packer/usr/lib/qt4.3/include/QtCore'
          ' -I/home/packer/usr/lib/qt4.3/include/QtGui'
d254 4
a257 3
        for d in (os.path.join('xml', qwt),
                  os.path.join('sip', qwt),
                  os.path.join('..', pyqwt, 'sip', qwt),
d271 1
a271 1
                               os.path.join('xml', qwt),
d275 1
a275 1
                                os.path.join('sip', qwt),
d281 1
a281 5
        fill.main(qwt)

        for sip_file in glob.glob(os.path.join('sip', qwt, '*.sip')):
            shutil.copyfile(sip_file, os.path.join(
                '..', pyqwt, 'sip', qwt, os.path.basename(sip_file)))
d283 17
@


1.6
log
@Adapt to renaming qwt-svn to qwt-5.0 in the pyqwt5 tree.
@
text
@d206 4
a209 4
          ' -I/home/packer/usr/lib/qt4.2/mkspecs/linux-g++'
          ' -I/home/packer/usr/lib/qt4.2/include'
          ' -I/home/packer/usr/lib/qt4.2/include/QtCore'
          ' -I/home/packer/usr/lib/qt4.2/include/QtGui'
@


1.5
log
@Work around a code generation bug in SIP-4.5.x with respect to the table
of typedefs.
@
text
@d190 1
a190 1
         os.path.join('qwt-svn', 'src'),
d202 1
a202 1
         os.path.join('qwt-svn', 'src'),
@


1.4
log
@Adapt to the move by Qwt from CVS to SVN.
@
text
@d211 1
a211 5
         (('QwtDoublePoint', 'QPointF'), # typedefs are risky in signals
          ('QwtDoubleSize', 'QSizeF'),
          ('QwtDoubleRect', 'QRectF'),
          ('QwtPolygon', 'QPolygon'),
          ('QPointFData', 'QwtDoublePointData'),
@


1.3
log
@Sync with Qwt-20061008 and build against Qt-4.2.0.

----------------------------------------------------------------------
@
text
@d177 1
a177 1
         'qwt-4.2.0',
d190 1
a190 1
         'qwt-cvs',
d202 1
a202 1
         'qwt-cvs',
d234 1
a234 1
            os.path.join('..', pyqwt, sources, 'include', '*.h'))
@


1.2
log
@Tweaks to build Qwt-20060910.
@
text
@d206 4
a209 4
          ' -I/home/packer/usr/lib/qt4.1/mkspecs/linux-g++'
          ' -I/home/packer/usr/lib/qt4.1/include'
          ' -I/home/packer/usr/lib/qt4.1/include/QtCore'
          ' -I/home/packer/usr/lib/qt4.1/include/QtGui'
@


1.1
log
@Initial revision
@
text
@d220 2
@


1.1.1.1
log
@Import the .h to .sip file translator.

@
text
@@
