<commit_before>import logging

from django.contrib.auth import get_user_model
from django.core.management import BaseCommand, call_command
from django.conf import settings


logger = logging.getLogger(__name__)


class Command(BaseCommand):
    def add_arguments(self, parser):
        parser.add_argument('--test', action='store_true', default=False)

    def handle(self, *args, **options):
        test = options['test']

        management_commands = [
            (('collectstatic',), dict(interactive=False)),
            (('migrate',), dict()),
            (('setup_default_media_specs',), dict()),
        ]

        if 'kompassi_oauth2' in settings.INSTALLED_APPS:
            management_commands.append((('setup_kompassi_oauth2',), dict()))

        if 'test':
            management_commands.append((('setup_example_content',), dict()))

        for pargs, opts in management_commands:
            call_command(*pargs, **opts)

        if test:
            user, created = get_user_model().objects.get_or_create(
                username='mahti',
                first_name='Markku',
                last_name='Mahtinen',
                is_staff=True,
                is_superuser=True,
            )

            if created:
                user.set_password('<PASSWORD>')
                user.save()
                logger.warn('Creating superuser "mahti" with password "<PASSWORD>"')<commit_msg>instead of setup --test, make test mode setup dependent on settings.DEBUG<commit_after>import logging

from django.contrib.auth import get_user_model
from django.core.management import BaseCommand, call_command
from django.conf import settings


logger = logging.getLogger(__name__)


class Command(BaseCommand):
    def handle(self, *args, **options):
        management_commands = [
            (('collectstatic',), dict(interactive=False)),
            (('migrate',), dict()),
            (('setup_default_media_specs',), dict()),
        ]

        if 'kompassi_oauth2' in settings.INSTALLED_APPS:
            management_commands.append((('setup_kompassi_oauth2',), dict()))

        if settings.DEBUG:
            management_commands.append((('setup_example_content',), dict()))

        for pargs, opts in management_commands:
            call_command(*pargs, **opts)

        if settings.DEBUG:
            user, created = get_user_model().objects.get_or_create(
                username='mahti',
                first_name='Markku',
                last_name='Mahtinen',
                is_staff=True,
                is_superuser=True,
            )

            if created:
                user.set_password('<PASSWORD>')
                user.save()
                logger.warn('Creating superuser "mahti" with password "<PASSWORD>"')
{'fraction_non_alphanumeric': 0.11764705882352941, 'fraction_numerical': 0.0014524328249818446, 'mean_word_length': 2.367970660146699, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6629054', 'n_tokens_mistral': 765, 'n_tokens_neox': 725, 'n_words': 151}