<commit_before>"""
originally from http://www.djangosnippets.org/snippets/828/ by dnordberg
"""

from six.moves import input
from django.conf import settings
from django.core.management.base import CommandError, BaseCommand
import django
import logging
import re
from optparse import make_option


class Command(BaseCommand):
    option_list = BaseCommand.option_list + (
        make_option('--noinput', action='store_false',
                    dest='interactive', default=True,
                    help='Tells Django to NOT prompt the user for input of any kind.'),
        make_option('--no-utf8', action='store_true',
                    dest='no_utf8_support', default=False,
                    help='Tells Django to not create a UTF-8 charset database'),
        make_option('-U', '--user', action='store',
                    dest='user', default=None,
                    help='Use another user for the database then defined in settings.py'),
        make_option('-P', '--password', action='store',
                    dest='password', default=None,
                    help='Use another password for the database then defined in settings.py'),
        make_option('-D', '--dbname', action='store',
                    dest='dbname', default=None,
                    help='Use another database name then defined in settings.py (For PostgreSQL this defaults to "template1")'),
        make_option('-R', '--router', action='store',
                    dest='router', default=None,
                    help='Use this router-database other then defined in settings.py'),
    )
    help = "Resets the database for this project."

    def handle(self, *args, **options):
        """
        Resets the database for this project.

        Note: Transaction wrappers are in reverse as a work around for
        autocommit, anybody know how to do this the right way?
        """

        router = options.get('router')
        if router is None:
            return False

        # retrieve this with the 'using' argument
        dbinfo = settings.DATABASES.get(router)
        settings.DATABASE_ENGINE = dbinfo.get('ENGINE').split('.')[-1]
        settings.DATABASE_USER = dbinfo.get('USER')
        settings.DATABASE_PASSWORD = dbinfo.get('PASSWORD')
        settings.DATABASE_NAME = dbinfo.get('NAME')
        settings.DATABASE_HOST = dbinfo.get('HOST')
        settings.DATABASE_PORT = dbinfo.get('PORT')

        verbosity = int(options.get('verbosity', 1))
        if options.get('interactive'):
            confirm = input("""
You have requested a database reset.
This will IRREVERSIBLY DESTROY
ALL data in the database "%s".
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: """ % (settings.DATABASE_NAME,))
        else:
            confirm = 'yes'

        if confirm != 'yes':
            print("Reset cancelled.")
            return

        postgis = re.compile('.*postgis')
        engine = settings.DATABASE_ENGINE
        user = options.get('user', settings.DATABASE_USER)
        if user is None:<commit_msg>Set default router as default<commit_after>"""
originally from http://www.djangosnippets.org/snippets/828/ by dnordberg
"""

from six.moves import input
from django.conf import settings
from django.core.management.base import CommandError, BaseCommand
import django
import logging
import re
from optparse import make_option


class Command(BaseCommand):
    option_list = BaseCommand.option_list + (
        make_option('--noinput', action='store_false',
                    dest='interactive', default=True,
                    help='Tells Django to NOT prompt the user for input of any kind.'),
        make_option('--no-utf8', action='store_true',
                    dest='no_utf8_support', default=False,
                    help='Tells Django to not create a UTF-8 charset database'),
        make_option('-U', '--user', action='store',
                    dest='user', default=None,
                    help='Use another user for the database then defined in settings.py'),
        make_option('-P', '--password', action='store',
                    dest='password', default=None,
                    help='Use another password for the database then defined in settings.py'),
        make_option('-D', '--dbname', action='store',
                    dest='dbname', default=None,
                    help='Use another database name then defined in settings.py (For PostgreSQL this defaults to "template1")'),
        make_option('-R', '--router', action='store',
                    dest='router', default='default',
                    help='Use this router-database other then defined in settings.py'),
    )
    help = "Resets the database for this project."

    def handle(self, *args, **options):
        """
        Resets the database for this project.

        Note: Transaction wrappers are in reverse as a work around for
        autocommit, anybody know how to do this the right way?
        """

        # retrieve this with the 'using' argument
        dbinfo = settings.DATABASES.get(options.get('router'))
        settings.DATABASE_ENGINE = dbinfo.get('ENGINE').split('.')[-1]
        settings.DATABASE_USER = dbinfo.get('USER')
        settings.DATABASE_PASSWORD = dbinfo.get('PASSWORD')
        settings.DATABASE_NAME = dbinfo.get('NAME')
        settings.DATABASE_HOST = dbinfo.get('HOST')
        settings.DATABASE_PORT = dbinfo.get('PORT')

        verbosity = int(options.get('verbosity', 1))
        if options.get('interactive'):
            confirm = input("""
You have requested a database reset.
This will IRREVERSIBLY DESTROY
ALL data in the database "%s".
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: """ % (settings.DATABASE_NAME,))
        else:
            confirm = 'yes'

        if confirm != 'yes':
            print("Reset cancelled.")
            return

        postgis = re.compile('.*postgis')
        engine = settings.DATABASE_ENGINE
        user = options.get('user', settings.DATABASE_USER)
        if user is None:
{'fraction_non_alphanumeric': 0.11463495209778658, 'fraction_numerical': 0.002973240832507433, 'mean_word_length': 2.41897233201581, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5005404', 'n_tokens_mistral': 1671, 'n_tokens_neox': 1605, 'n_words': 495}