1 from django.core.management.base import NoArgsCommand, CommandError |
1 from optparse import make_option |
2 |
2 |
3 class Command(NoArgsCommand): |
3 from django.core.management.base import BaseCommand, CommandError |
4 help = "Runs the command-line client for the current DATABASE_ENGINE." |
4 from django.db import connections, DEFAULT_DB_ALIAS |
|
5 |
|
6 class Command(BaseCommand): |
|
7 help = ("Runs the command-line client for specified database, or the " |
|
8 "default database if none is provided.") |
|
9 |
|
10 option_list = BaseCommand.option_list + ( |
|
11 make_option('--database', action='store', dest='database', |
|
12 default=DEFAULT_DB_ALIAS, help='Nominates a database onto which to ' |
|
13 'open a shell. Defaults to the "default" database.'), |
|
14 ) |
5 |
15 |
6 requires_model_validation = False |
16 requires_model_validation = False |
7 |
17 |
8 def handle_noargs(self, **options): |
18 def handle(self, **options): |
9 from django.db import connection |
19 connection = connections[options.get('database', DEFAULT_DB_ALIAS)] |
10 try: |
20 try: |
11 connection.client.runshell() |
21 connection.client.runshell() |
12 except OSError: |
22 except OSError: |
13 # Note that we're assuming OSError means that the client program |
23 # Note that we're assuming OSError means that the client program |
14 # isn't installed. There's a possibility OSError would be raised |
24 # isn't installed. There's a possibility OSError would be raised |