Change migration linting prints to use conditined methods
This commit is contained in:
1 parent
3b8e86fdf7
commit
ceabb40a62
1 file changed
+27
-12
@@ -121,18 +121,19 @@ class MigrationLinter(object):
|
|||||||
app_label = migration.app_label
|
app_label = migration.app_label
|
||||||
migration_name = migration.name
|
migration_name = migration.name
|
||||||
operations = migration.operations
|
operations = migration.operations
|
||||||
print("({0}, {1})... ".format(app_label, migration_name), end="")
|
|
||||||
self.nb_total += 1
|
self.nb_total += 1
|
||||||
|
|
||||||
md5hash = self.get_migration_hash(app_label, migration_name)
|
md5hash = self.get_migration_hash(app_label, migration_name)
|
||||||
|
|
||||||
if self.should_ignore_migration(app_label, migration_name, operations):
|
if self.should_ignore_migration(app_label, migration_name, operations):
|
||||||
print("IGNORE")
|
self.print_linting_msg(
|
||||||
|
app_label, migration_name, "IGNORE", MessageType.IGNORE
|
||||||
|
)
|
||||||
self.nb_ignored += 1
|
self.nb_ignored += 1
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.should_use_cache() and md5hash in self.old_cache:
|
if self.should_use_cache() and md5hash in self.old_cache:
|
||||||
self.lint_cached_migration(md5hash)
|
self.lint_cached_migration(app_label, migration_name, md5hash)
|
||||||
return
|
return
|
||||||
|
|
||||||
sql_statements = self.get_sql(app_label, migration_name)
|
sql_statements = self.get_sql(app_label, migration_name)
|
||||||
@@ -145,16 +146,18 @@ class MigrationLinter(object):
|
|||||||
|
|
||||||
if not errors:
|
if not errors:
|
||||||
if ignored:
|
if ignored:
|
||||||
print("OK (ignored)")
|
self.print_linting_msg(
|
||||||
|
app_label, migration_name, "OK (ignored)", MessageType.IGNORE
|
||||||
|
)
|
||||||
self.print_errors(ignored)
|
self.print_errors(ignored)
|
||||||
else:
|
else:
|
||||||
print("OK")
|
self.print_linting_msg(app_label, migration_name, "OK", MessageType.OK)
|
||||||
self.nb_valid += 1
|
self.nb_valid += 1
|
||||||
if self.should_use_cache():
|
if self.should_use_cache():
|
||||||
self.new_cache[md5hash] = {"result": "OK"}
|
self.new_cache[md5hash] = {"result": "OK"}
|
||||||
return
|
return
|
||||||
|
|
||||||
print("ERR")
|
self.print_linting_msg(app_label, migration_name, "ERR", MessageType.ERROR)
|
||||||
self.nb_erroneous += 1
|
self.nb_erroneous += 1
|
||||||
self.print_errors(errors)
|
self.print_errors(errors)
|
||||||
if self.should_use_cache():
|
if self.should_use_cache():
|
||||||
@@ -168,24 +171,36 @@ class MigrationLinter(object):
|
|||||||
hash_md5.update(chunk)
|
hash_md5.update(chunk)
|
||||||
return hash_md5.hexdigest()
|
return hash_md5.hexdigest()
|
||||||
|
|
||||||
def lint_cached_migration(self, md5hash):
|
def lint_cached_migration(self, app_label, migration_name, md5hash):
|
||||||
cached_value = self.old_cache[md5hash]
|
cached_value = self.old_cache[md5hash]
|
||||||
if cached_value["result"] == "IGNORE":
|
if cached_value["result"] == "IGNORE":
|
||||||
print("IGNORE (cached)")
|
self.print_linting_msg(
|
||||||
|
app_label, migration_name, "IGNORE (cached)", MessageType.IGNORE
|
||||||
|
)
|
||||||
self.nb_ignored += 1
|
self.nb_ignored += 1
|
||||||
elif cached_value["result"] == "OK":
|
elif cached_value["result"] == "OK":
|
||||||
print("OK (cached)")
|
self.print_linting_msg(
|
||||||
|
app_label, migration_name, "OK (cached)", MessageType.OK
|
||||||
|
)
|
||||||
self.nb_valid += 1
|
self.nb_valid += 1
|
||||||
else:
|
else:
|
||||||
print("ERR (cached)")
|
self.print_linting_msg(
|
||||||
|
app_label, migration_name, "ERR (cached)", MessageType.ERROR
|
||||||
|
)
|
||||||
self.nb_erroneous += 1
|
self.nb_erroneous += 1
|
||||||
if "errors" in cached_value:
|
if "errors" in cached_value:
|
||||||
self.print_errors(cached_value["errors"])
|
self.print_errors(cached_value["errors"])
|
||||||
|
|
||||||
self.new_cache[md5hash] = cached_value
|
self.new_cache[md5hash] = cached_value
|
||||||
|
|
||||||
@staticmethod
|
def print_linting_msg(self, app_label, migration_name, msg, lint_result):
|
||||||
def print_errors(errors):
|
if lint_result.value in self.quiet:
|
||||||
|
return
|
||||||
|
print("({0}, {1})... {2}".format(app_label, migration_name, msg))
|
||||||
|
|
||||||
|
def print_errors(self, errors):
|
||||||
|
if MessageType.ERROR.value in self.quiet:
|
||||||
|
return
|
||||||
for err in errors:
|
for err in errors:
|
||||||
error_str = "\t{0}".format(err["err_msg"])
|
error_str = "\t{0}".format(err["err_msg"])
|
||||||
if err["table"]:
|
if err["table"]:
|
||||||
|
|||||||
Reference in new issue
Block a user