From cc5009109dca26f316a39dacd8a12f9c51cf0a0c Mon Sep 17 00:00:00 2001 From: david_wobrock Date: Fri, 26 May 2017 10:19:39 +0200 Subject: [PATCH] Add basic a verbosity arg --- README.md | 1 + migration_linter.py | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/README.md b/README.md index f7caed5..63c9c97 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ Detect backward incompatible migrations for your django project. All in one file * `--ignore-name-contains IGNORE_NAME_CONTAINS`- ignore migrations containing this name * `--include-apps INCLUDE_APPS [INCLUDE_APPS ...]` - check only migrations that are in the specified django apps * `--exclude-apps EXCLUDE_APPS [EXCLUDE_APPS ...]` - ignore migrations that are in the specified django apps +* `--verbose` or `-v` - print more information during execution ## Requirements diff --git a/migration_linter.py b/migration_linter.py index abd0a8c..7c54c45 100644 --- a/migration_linter.py +++ b/migration_linter.py @@ -14,6 +14,7 @@ from __future__ import print_function import argparse +import logging as log import os import re from subprocess import Popen, PIPE @@ -127,7 +128,9 @@ class MigrationLinter: def _test_sql_statement_for_backward_incompatibility(self, sql_statement): for test in self.migration_tests: if test['fn'](sql_statement): + log.info('Testing {0} -- ERROR'.format(sql_statement)) return False, test['err_msg'] + log.info('Testing {0} -- PASSED'.format(sql_statement)) return True, None @@ -160,11 +163,16 @@ if __name__ == '__main__': parser.add_argument('django_folder', metavar='DJANGO_FOLDER', type=str, nargs=1, help='the path to the django project') parser.add_argument('commit_id', metavar='GIT_COMMIT_ID', type=str, nargs='?', help='if specified, only migrations since this commit will be taken into account. If not specified, the initial repo commit will be used') parser.add_argument('--ignore-name-contains', type=str, nargs='?', help='ignore migrations containing this name') + parser.add_argument('--verbose', '-v', action='store_true', help='print more information during execution') incl_excl_group = parser.add_mutually_exclusive_group(required=False) incl_excl_group.add_argument('--include-apps', type=str, nargs='*', help='check only migrations that are in the specified django apps') incl_excl_group.add_argument('--exclude-apps', type=str, nargs='*', help='ignore migrations that are in the specified django apps') args = parser.parse_args() + if args.verbose: + log.basicConfig(format='%(message)s', level=log.DEBUG) + else: + log.basicConfig(format='%(message)s') folder_name = args.django_folder[0] if valid_folder(folder_name):