misc/cmp_schema.py
author Julien Cristau <julien.cristau@logilab.fr>
Thu, 23 Feb 2012 19:05:36 +0100
branchstable
changeset 8261 d4d9c88d4a5f
parent 5372 b74eed7e8b37
permissions -rw-r--r--
[devtools] make a copy of the xvfb-run script so we can kill it properly Since changeset a3d3bdd46463 we don't run firefox directly but through a wrapper script. This meant that on stopping the test, we would kill that wrapper script but leave the Xvfb server and firefox processes running. So make a local copy of xvfb-run, and make it kill Xvfb when it goes down, not just when its client exits.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5372
b74eed7e8b37 Add a basic script to compare the db_schema to the fs_schema.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     1
"""This module compare the Schema on the file system to the one in the database"""
b74eed7e8b37 Add a basic script to compare the db_schema to the fs_schema.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     2
b74eed7e8b37 Add a basic script to compare the db_schema to the fs_schema.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     3
from cStringIO import StringIO
b74eed7e8b37 Add a basic script to compare the db_schema to the fs_schema.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     4
from cubicweb.web.schemaviewer import SchemaViewer
b74eed7e8b37 Add a basic script to compare the db_schema to the fs_schema.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     5
from logilab.common.ureports import TextWriter
b74eed7e8b37 Add a basic script to compare the db_schema to the fs_schema.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     6
import difflib
b74eed7e8b37 Add a basic script to compare the db_schema to the fs_schema.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     7
b74eed7e8b37 Add a basic script to compare the db_schema to the fs_schema.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     8
viewer = SchemaViewer()
b74eed7e8b37 Add a basic script to compare the db_schema to the fs_schema.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     9
layout_db = viewer.visit_schema(schema, display_relations=True)
b74eed7e8b37 Add a basic script to compare the db_schema to the fs_schema.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    10
layout_fs = viewer.visit_schema(fsschema, display_relations=True)
b74eed7e8b37 Add a basic script to compare the db_schema to the fs_schema.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    11
writer = TextWriter()
b74eed7e8b37 Add a basic script to compare the db_schema to the fs_schema.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    12
stream_db = StringIO()
b74eed7e8b37 Add a basic script to compare the db_schema to the fs_schema.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    13
stream_fs = StringIO()
b74eed7e8b37 Add a basic script to compare the db_schema to the fs_schema.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    14
writer.format(layout_db, stream=stream_db)
b74eed7e8b37 Add a basic script to compare the db_schema to the fs_schema.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    15
writer.format(layout_fs, stream=stream_fs)
b74eed7e8b37 Add a basic script to compare the db_schema to the fs_schema.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    16
b74eed7e8b37 Add a basic script to compare the db_schema to the fs_schema.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    17
stream_db.seek(0)
b74eed7e8b37 Add a basic script to compare the db_schema to the fs_schema.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    18
stream_fs.seek(0)
b74eed7e8b37 Add a basic script to compare the db_schema to the fs_schema.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    19
db = stream_db.getvalue().splitlines()
b74eed7e8b37 Add a basic script to compare the db_schema to the fs_schema.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    20
fs = stream_fs.getvalue().splitlines()
b74eed7e8b37 Add a basic script to compare the db_schema to the fs_schema.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    21
open('db_schema.txt', 'w').write(stream_db.getvalue())
b74eed7e8b37 Add a basic script to compare the db_schema to the fs_schema.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    22
open('fs_schema.txt', 'w').write(stream_fs.getvalue())
b74eed7e8b37 Add a basic script to compare the db_schema to the fs_schema.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    23
#for diff in difflib.ndiff(fs, db):
b74eed7e8b37 Add a basic script to compare the db_schema to the fs_schema.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    24
#    print diff