web/lib/django/core/management/commands/sqlflush.py
author ymh <ymh.work@gmail.com>
Fri, 04 Mar 2011 16:45:48 +0100
changeset 57 1984c3b5f299
parent 38 77b6da96e6f1
permissions -rw-r--r--
Create new version
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
38
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
from optparse import make_option
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
from django.core.management.base import NoArgsCommand
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
from django.core.management.sql import sql_flush
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
from django.db import connections, DEFAULT_DB_ALIAS
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
class Command(NoArgsCommand):
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
    help = "Returns a list of the SQL statements required to return all tables in the database to the state they were in just after they were installed."
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
    option_list = NoArgsCommand.option_list + (
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
        make_option('--database', action='store', dest='database',
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
            default=DEFAULT_DB_ALIAS, help='Nominates a database to print the '
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
                'SQL for.  Defaults to the "default" database.'),
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
    )
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
    output_transaction = True
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
    def handle_noargs(self, **options):
77b6da96e6f1 update django
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
        return u'\n'.join(sql_flush(self.style, connections[options.get('database', DEFAULT_DB_ALIAS)], only_django=True)).encode('utf-8')