Ticket #10803: db_executable_name.2.diff

File db_executable_name.2.diff, 5.7 KB (added by Håkan W, 16 years ago)

Better diff

  • django/db/backends/postgresql/client.py

     
    1 import os
    2 import sys
    3 
    41from django.db.backends import BaseDatabaseClient
    52
    63class DatabaseClient(BaseDatabaseClient):
    7     executable_name = 'psql'
     4    executable_names = ('psql',)
    85
    96    def runshell(self):
    107        settings_dict = self.connection.settings_dict
    11         args = [self.executable_name]
     8        args = []
    129        if settings_dict['DATABASE_USER']:
    1310            args += ["-U", settings_dict['DATABASE_USER']]
    1411        if settings_dict['DATABASE_HOST']:
     
    1613        if settings_dict['DATABASE_PORT']:
    1714            args.extend(["-p", str(settings_dict['DATABASE_PORT'])])
    1815        args += [settings_dict['DATABASE_NAME']]
    19         if os.name == 'nt':
    20             sys.exit(os.system(" ".join(args)))
    21         else:
    22             os.execvp(self.executable_name, args)
     16        self.run_executable(args)
    2317
  • django/db/backends/sqlite3/client.py

     
    1 import os
    2 import sys
    3 
    41from django.db.backends import BaseDatabaseClient
    52
    63class DatabaseClient(BaseDatabaseClient):
    7     executable_name = 'sqlite3'
     4    executable_names = ('sqlite3',)
    85
    96    def runshell(self):
    10         args = [self.executable_name,
    11                 self.connection.settings_dict['DATABASE_NAME']]
    12         if os.name == 'nt':
    13             sys.exit(os.system(" ".join(args)))
    14         else:
    15             os.execvp(self.executable_name, args)
     7        args = [self.connection.settings_dict['DATABASE_NAME']]
     8        self.run_executable(args)
    169
  • django/db/backends/mysql/client.py

     
    1 import os
    2 import sys
    3 
    41from django.db.backends import BaseDatabaseClient
    52
    63class DatabaseClient(BaseDatabaseClient):
    7     executable_name = 'mysql'
     4    executable_names = ('mysql', 'mysql5')
    85
    96    def runshell(self):
    107        settings_dict = self.connection.settings_dict
    11         args = [self.executable_name]
    128        db = settings_dict['DATABASE_OPTIONS'].get('db', settings_dict['DATABASE_NAME'])
    139        user = settings_dict['DATABASE_OPTIONS'].get('user', settings_dict['DATABASE_USER'])
    1410        passwd = settings_dict['DATABASE_OPTIONS'].get('passwd', settings_dict['DATABASE_PASSWORD'])
     
    1713        defaults_file = settings_dict['DATABASE_OPTIONS'].get('read_default_file')
    1814        # Seems to be no good way to set sql_mode with CLI.
    1915
     16        args = []
    2017        if defaults_file:
    2118            args += ["--defaults-file=%s" % defaults_file]
    2219        if user:
     
    3027        if db:
    3128            args += [db]
    3229
    33         if os.name == 'nt':
    34             sys.exit(os.system(" ".join(args)))
    35         else:
    36             os.execvp(self.executable_name, args)
     30        self.run_executable(args)
    3731
  • django/db/backends/oracle/client.py

     
    1 import os
    2 import sys
    3 
    41from django.db.backends import BaseDatabaseClient
    52
    63class DatabaseClient(BaseDatabaseClient):
    7     executable_name = 'sqlplus'
     4    executable_names = ('sqlplus',)
    85
    96    def runshell(self):
    107        conn_string = self.connection._connect_string()
    11         args = [self.executable_name, "-L", conn_string]
    12         if os.name == 'nt':
    13             sys.exit(os.system(" ".join(args)))
    14         else:
    15             os.execvp(self.executable_name, args)
    16 
     8        args = ["-L", conn_string]
     9        self.run_executable(args)
  • django/db/backends/__init__.py

     
    1616    # Python 2.3 fallback
    1717    from django.utils import _decimal as decimal
    1818
     19import os
     20import sys
     21
    1922from django.db.backends import util
    2023from django.utils import datetime_safe
    2124
     
    539542    This class encapsulates all backend-specific methods for opening a
    540543    client shell.
    541544    """
    542     # This should be a string representing the name of the executable
    543     # (e.g., "psql"). Subclasses must override this.
    544     executable_name = None
     545    # This should be a tuple with strings representing the name (or names) of the executable
     546    # names to try (e.g., ("mysql", "mysql5")). Subclasses must override this.
     547    executable_names = None
    545548
    546549    def __init__(self, connection):
    547550        # connection is an instance of BaseDatabaseWrapper.
     
    549552
    550553    def runshell(self):
    551554        raise NotImplementedError()
     555       
     556    def run_executable(self, args):
     557        """
     558        Will try to run the first executable it finds in the
     559        executable_names tuple.
     560        """
     561        for executable_name in self.executable_names:
     562            try:
     563                cmd = (executable_name,) + tuple(args)
     564                if os.name == 'nt':
     565                    sys.exit(os.system(" ".join(cmd)))
     566                else:
     567                    os.execvp(executable_name, cmd)
     568            except OSError:
     569                # The executable was not found; try the next
     570                # one in the tuple.
     571                continue
     572            break
    552573
    553574class BaseDatabaseValidation(object):
    554575    """
Back to Top