cubicweb/misc/cmp_schema.py
author Philippe Pepiot <philippe.pepiot@logilab.fr>
Wed, 18 Mar 2020 13:18:21 +0100
branch3.27
changeset 12920 018b6445aef1
parent 11057 0b59724cb3f2
permissions -rw-r--r--
Added tag 3.27.3, debian/3.27.3-1 for changeset 85284f028266
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