/
specdiff.py
executable file
·79 lines (64 loc) · 2.01 KB
/
specdiff.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python
import argparse
import os
import sys
import getpass
import MySQLdb
import logging
import re
import P4
import schemadiff
import dsn
import string
import p4credentials
import subprocess
from warnings import filterwarnings
if __name__ == '__main__':
filterwarnings('ignore', category = MySQLdb.Warning)
FORMAT = "%(asctime)-15s %(funcName)s %(levelname)s %(message)s"
logging.basicConfig(format=FORMAT, level=logging.DEBUG)
parser = argparse.ArgumentParser()
parser.add_argument("oldspec",
help="p4 filespec for old version of schema")
parser.add_argument("newspec",
help="p4 filespec for new version of schema")
parser.add_argument("--dmlfile", help="file to write dml statements")
parser.add_argument("--validate", help="verify that the changes work",
action="store_true")
args = parser.parse_args()
validate = False
if args.validate:
validate = True
oldspec = args.oldspec
newspec = args.newspec
dmlfile = args.dmlfile
p4 = P4.P4()
conn = None
cursor = None
try:
schemadiff.log_in_to_p4(p4)
conn = dsn.getConnection()
cursor = conn.cursor()
schema1 = schemadiff.get_schema_from_filespec(p4, oldspec)
schema2 = schemadiff.get_schema_from_filespec(p4, newspec)
schemadiff.diff_schemas(cursor,
schema1,
schema2,
"specdiff_old",
"specdiff_new",
dmlfile=dmlfile,
validate=validate)
except P4.P4Exception as p4e:
logging.error(p4e)
for e in p4.warnings:
logging.warning(e)
for e in p4.errors:
logging.error(e)
except Exception as e:
logging.error(e)
finally:
p4.disconnect()
if conn:
conn.close()
if cursor:
cursor.close()