south.db: 24 total statements, 0.0% covered

Generated: Wed 2013-03-13 10:33 CET

Source file: /media/Envs/Envs/filer-gallery/lib/python2.7/site-packages/south/db/__init__.py

Stats: 0 executed, 21 missed, 3 excluded, 57 ignored

  1. # Establish the common DatabaseOperations instance, which we call 'db'.
  2. # Much thanks to cmkmrr for a lot of the code base here
  3. from django.conf import settings
  4. import sys
  5. # A few aliases, because there's FQMNs now
  6. engine_modules = {
  7. 'django.db.backends.postgresql_psycopg2': 'postgresql_psycopg2',
  8. 'django.db.backends.sqlite3': 'sqlite3',
  9. 'django.db.backends.mysql': 'mysql',
  10. 'django.db.backends.oracle': 'oracle',
  11. 'sql_server.pyodbc': 'sql_server.pyodbc', #django-pyodbc
  12. 'sqlserver_ado': 'sql_server.pyodbc', #django-mssql
  13. 'firebird': 'firebird', #django-firebird
  14. 'django.contrib.gis.db.backends.postgis': 'postgresql_psycopg2',
  15. 'django.contrib.gis.db.backends.spatialite': 'sqlite3',
  16. 'django.contrib.gis.db.backends.mysql': 'mysql',
  17. 'django.contrib.gis.db.backends.oracle': 'oracle',
  18. 'doj.backends.zxjdbc.postgresql': 'postgresql_psycopg2', #django-jython
  19. 'doj.backends.zxjdbc.mysql': 'mysql', #django-jython
  20. 'doj.backends.zxjdbc.oracle': 'oracle', #django-jython
  21. }
  22. # First, work out if we're multi-db or not, and which databases we have
  23. try:
  24. from django.db import DEFAULT_DB_ALIAS
  25. except ImportError:
  26. #### 1.1 or below ####
  27. # We'll 'fake' multi-db; set the default alias
  28. DEFAULT_DB_ALIAS = 'default'
  29. # SOUTH_DATABASE_ADAPTER is an optional override if you have a different module
  30. engine = getattr(settings, "SOUTH_DATABASE_ADAPTER", "south.db.%s" % settings.DATABASE_ENGINE)
  31. # And then, we have one database with one engine
  32. db_engines = {DEFAULT_DB_ALIAS: engine}
  33. else:
  34. #### 1.2 or above ####
  35. # Loop over the defined databases, gathering up their engines
  36. db_engines = dict([
  37. # Note we check to see if contrib.gis has overridden us.
  38. (alias, "south.db.%s" % engine_modules[db_settings['ENGINE']])
  39. for alias, db_settings in settings.DATABASES.items()
  40. if db_settings['ENGINE'] in engine_modules
  41. ])
  42. # Update with any overrides
  43. db_engines.update(getattr(settings, "SOUTH_DATABASE_ADAPTERS", {}))
  44. # Check there's no None engines, or...
  45. for alias, engine in db_engines.items():
  46. if engine is None:
  47. # They've used a backend we don't support
  48. sys.stderr.write(
  49. (
  50. "There is no South database module for your database backend '%s'. " + \
  51. "Please either choose a supported database, check for " + \
  52. "SOUTH_DATABASE_ADAPTER[S] settings, " + \
  53. "or remove South from INSTALLED_APPS.\n"
  54. ) % (settings.DATABASES[alias]['ENGINE'],)
  55. )
  56. sys.exit(1)
  57. # Now, turn that into a dict of <alias: south db module>
  58. dbs = {}
  59. try:
  60. for alias, module_name in db_engines.items():
  61. module = __import__(module_name, {}, {}, [''])
  62. dbs[alias] = module.DatabaseOperations(alias)
  63. except ImportError:
  64. # This error should only be triggered on 1.1 and below.
  65. sys.stderr.write(
  66. (
  67. "There is no South database module '%s' for your database. " + \
  68. "Please either choose a supported database, check for " + \
  69. "SOUTH_DATABASE_ADAPTER[S] settings, " + \
  70. "or remove South from INSTALLED_APPS.\n"
  71. ) % (module_name,)
  72. )
  73. sys.exit(1)
  74. # Finally, to make old migrations work, keep 'db' around as the default database
  75. db = dbs[DEFAULT_DB_ALIAS]