Process outfile-infile-arggroup combinations.

def process_combinations(combinations, engine,
                         tolerant=False,
                         read_old=False,
                         delete_empty=False,
                         ):
    """Process outfile-infile-arggroup combinations."""
    outfiles = set()

    templatereader = CachedTemplateReader(engine, tolerant=tolerant)

    for outfile, infile, arggroup in combinations:
        template = templatereader.read(infile)
        properties = make_path_properties(outfile, prefix='ez_')

        if read_old:
            if is_filelike(outfile):
                raise Exception("cannot read already open output streams")
            try:
                with open(outfile, 'r') as f:
                    properties['ez_content'] = f.read()
            except IOError:
                properties['ez_content'] = None

        result = template.apply(dict(arggroup, **properties))

        if is_filelike(outfile):
            if result:
                outfile.write(result)
        elif result or not delete_empty:
            if outfile in outfiles:
                raise IOError("trying to write twice to the same file")
            outfiles.add(outfile)
            with open(outfile, 'w') as f:
                f.write(result)
        else:
            try:
                os.remove(outfile)
            except OSError as e:
                if e.errno != errno.ENOENT:
                    raise