diff --git a/LL1_Academy/management/commands/populate.py b/LL1_Academy/management/commands/populate.py index 26e05fd..7b57c62 100644 --- a/LL1_Academy/management/commands/populate.py +++ b/LL1_Academy/management/commands/populate.py @@ -1,15 +1,36 @@ from django.core.management.base import BaseCommand, CommandError from LL1_Academy.tools import MassGrammarGenerator +from LL1_Academy.models import Grammar import os +import sys import time +from django.core.management import call_command + class Command(BaseCommand): help = 'This command will add grammars to the database, starting from grammars and gradually filtering them down to a valid set (which may be much less than )' def add_arguments(self, parser): parser.add_argument('num', type=int) + parser.add_argument('--reset', + action='store_true', + dest='reset_db', + default=False, + help='Clear database and repopulate it', + ) + parser.add_argument('--silent', + action='store_true', + dest='silent', + default=False, + help='Will not show the actual grammars being generated', + ) + def handle(self, *args, **options): + if (options['reset_db']): + call_command('cleardatabase') + + print("Grammar objects initially in database: {}".format(Grammar.objects.count())) #Number of randomly generated grammars num = options['num'] @@ -21,8 +42,20 @@ def handle(self, *args, **options): nonTerminals = ['A','B','C','D'] terminals = ['x','y','z','w'] + + + if options['silent']: + sys.stdout = open(os.devnull, "w") + for n in nVariables: start_time = time.time() mg = MassGrammarGenerator.MassGrammarGenerator(n) mg.run(num,nonTerminals[:n],terminals) print("{}Variables: {} seconds---".format(n,(time.time() - start_time))) + + if options['silent']: + sys.stdout = sys.__stdout__ + + print("Grammar objects finally in database: {}".format(Grammar.objects.count())) + + diff --git a/LL1_Academy/templates/LL1_Academy/_base.html b/LL1_Academy/templates/LL1_Academy/_base.html index a984255..ee7a86e 100644 --- a/LL1_Academy/templates/LL1_Academy/_base.html +++ b/LL1_Academy/templates/LL1_Academy/_base.html @@ -4,11 +4,16 @@ LL(1) Academy - {% block title %}{% endblock %} - - - + + + + + + + + diff --git a/LL1_Academy/templates/LL1_Academy/_navbarPages.html b/LL1_Academy/templates/LL1_Academy/_navbarPages.html index 8307ab8..52c7591 100644 --- a/LL1_Academy/templates/LL1_Academy/_navbarPages.html +++ b/LL1_Academy/templates/LL1_Academy/_navbarPages.html @@ -23,13 +23,19 @@