author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Tue, 10 Jun 2014 15:06:44 +0200 | |
changeset 10359 | 8e4ba1028f55 |
parent 5372 | b74eed7e8b37 |
permissions | -rw-r--r-- |
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 |