#!/usr/bin/env python
import coral
import os
import copy
import glob

xmlfiles = glob.glob("*.xml")

import itertools

for i in xmlfiles:
    p1 = coral.loadDocument(i)
    p2 = coral.Project()
    for r in p1.contents():
      rc = coral.ModelCopy_One(r,
                               coral.MODELCOPY_DONT_CREATE_NEW_UUIDS \
                               + coral.MODELCOPY_DONT_ATTACH_TO_PARENTS)
      rc.__setProject__(p2)
    print "M1 == M2, file ", i

    itertools.imap(coral.isSameModel, p1.contents(), p2.contents())
    p2.setFilename("tmp/out_DeepcopyAll.xml")
    coral.saveDocument(p2)
    os.rename("tmp/out_DeepcopyAll.xml", "tmp/out2_DeepcopyAll.xml")
    p3 = coral.loadDocument("tmp/out2_DeepcopyAll.xml")
    assert p3
    itertools.imap(coral.isSameModel, p1.contents(), p3.contents())
    itertools.imap(coral.isSameModel, p2.contents(), p3.contents())
    itertools.imap(coral.isSameModel, p3.contents(), p2.contents())
    itertools.imap(coral.isSameModel, p3.contents(), p1.contents())
