diff --git a/ietf/utils/management/commands/populate_yang_model_dirs.py b/ietf/utils/management/commands/populate_yang_model_dirs.py index 9ea4e9ab4..28631c74f 100644 --- a/ietf/utils/management/commands/populate_yang_model_dirs.py +++ b/ietf/utils/management/commands/populate_yang_model_dirs.py @@ -1,3 +1,4 @@ +# Copyright The IETF Trust 2016-2019, All Rights Reserved from __future__ import print_function, unicode_literals import os @@ -78,7 +79,7 @@ class Command(BaseCommand): modfile.rename(str(moddir/name)) model_list = [ n.replace('"','') for n in model_list ] except Exception as e: - print("** Error when extracting from %s: %s" % (file, str(e))) + self.stderr.write("** Error when extracting from %s: %s" % (file, str(e))) sys.stdout = saved_stdout sys.stderr = saved_stderr # @@ -103,7 +104,8 @@ class Command(BaseCommand): if item.stat().st_mtime > latest: latest = item.stat().st_mtime - print("Extracting to %s ..." % moddir) + if verbosity > 0: + self.stdout.write("Extracting to %s ..." % moddir) for item in rfcdir.iterdir(): if item.is_file() and item.name.startswith('rfc') and item.name.endswith('.txt') and item.name[3:-4].isdigit(): if item.stat().st_mtime > latest: @@ -111,16 +113,17 @@ class Command(BaseCommand): for name in model_list: if name.startswith('ietf') or name.startswith('iana'): if verbosity > 1: - print(" Extracted from %s: %s" % (item, name)) - else: - sys.stdout.write('.') - sys.stdout.flush() + self.stdout.write(" Extracted from %s: %s" % (item, name)) + elif verbosity > 0: + self.stdout.write('.', ending='') + self.stdout.flush() else: modfile = moddir / name modfile.unlink() if verbosity > 1: - print(" Skipped module from %s: %s" % (item, name)) - print("") + self.stdout.write(" Skipped module from %s: %s" % (item, name)) + if verbosity > 0: + self.stdout.write("") # Extract valid modules from drafts @@ -133,11 +136,13 @@ class Command(BaseCommand): moddir = Path(settings.SUBMIT_YANG_DRAFT_MODEL_DIR) if not moddir.exists(): moddir.mkdir(parents=True) - print("Emptying %s ..." % moddir) + if verbosity > 0: + self.stdout.write("Emptying %s ..." % moddir) for item in moddir.iterdir(): item.unlink() - print("Extracting to %s ..." % moddir) + if verbosity > 0: + self.stdout.write("Extracting to %s ..." % moddir) for item in draftdir.iterdir(): try: if item.is_file() and item.name.startswith('draft') and item.name.endswith('.txt') and active(item): @@ -145,18 +150,19 @@ class Command(BaseCommand): for name in model_list: if not name.startswith('example'): if verbosity > 1: - print(" Extracted module from %s: %s" % (item, name)) - else: - sys.stdout.write('.') - sys.stdout.flush() + self.stdout.write(" Extracted module from %s: %s" % (item, name)) + elif verbosity > 0: + self.stdout.write('.', ending='') + self.stdout.flush() else: modfile = moddir / name modfile.unlink() if verbosity > 1: - print(" Skipped module from %s: %s" % (item, name)) + self.stdout.write(" Skipped module from %s: %s" % (item, name)) except UnicodeDecodeError as e: - sys.stderr.write('\nError: %s\n' % (e, )) - sys.stderr.write(item.name) - sys.stderr.write('\n') - print("") + self.stderr.write('\nError: %s' % (e, )) + self.stderr.write(item.name) + self.stderr.write('') + if verbosity > 0: + self.stdout.write('') diff --git a/ietf/utils/management/commands/run_yang_model_checks.py b/ietf/utils/management/commands/run_yang_model_checks.py index 75569e611..7a931f2aa 100644 --- a/ietf/utils/management/commands/run_yang_model_checks.py +++ b/ietf/utils/management/commands/run_yang_model_checks.py @@ -1,3 +1,4 @@ +# Copyright The IETF Trust 2017-2019, All Rights Reserved from __future__ import print_function, unicode_literals import sys @@ -36,8 +37,8 @@ class Command(BaseCommand): def check_yang(self, checker, draft, force=False): if self.verbosity > 1: self.stdout.write("Checking %s-%s" % (draft.name, draft.rev)) - else: - sys.stderr.write('.') + elif self.verbosity > 0: + self.stderr.write('.', ending='') submission = Submission.objects.filter(name=draft.name, rev=draft.rev).order_by('-id').first() if submission or force: check = submission.checks.filter(checker=checker.name).order_by('-id').first() @@ -58,7 +59,7 @@ class Command(BaseCommand): message=message, errors=errors, warnings=warnings, items=items, symbol=checker.symbol) else: - self.stderr.write("Error: did not find any submission object for %s-%s\n" % (draft.name, draft.rev)) + self.stderr.write("Error: did not find any submission object for %s-%s" % (draft.name, draft.rev)) def handle(self, *filenames, **options): """