def diff_branches(p4, cursor, filespec, frombranch, tobranch, database, dmlfile, validate): """ show the changes needed to turn the schema in frombranch to the one in tobranch. """ fromschema = get_schema_for_branch(p4, filespec, frombranch) toschema = get_schema_for_branch(p4, filespec, tobranch) # we will use the branch names as database names. mysql doesn't like # database names with hyphens. frombranch = string.replace(frombranch, '-', '') tobranch = string.replace(tobranch, '-', '') db1 = "%(branch)s_%(db)s" % { "branch" : frombranch, "db" : database } db2 = "%(branch)s_%(db)s" % { "branch" : tobranch, "db" : database } schemadiff.diff_schemas(cursor, fromschema, toschema, db1, db2, dmlfile=dmlfile, validate=validate)
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:
# # need 2 hash objects in order to use them independently # # for each path # # hash1 = hashlib.md5() # hash2 = hash1.copy() # # hash1.update(path1) # hash2.update(path2) db1 = "%s" % (os.path.splitext(file1)[0]) db2 = "%s" % (os.path.splitext(file2)[0]) if db1 == db2: print 'not dealing with same-name schema files right now' sys.exit(1) # finally. let's get to work. schema1 = read_schema_from_file(file1) schema2 = read_schema_from_file(file2) conn = dsn.getConnection() cursor = conn.cursor() schemadiff.diff_schemas(cursor, schema1, schema2, db1, db2, dmlfile=dmlfile, validate=validate) cursor.close() conn.close()