Forked mumble-django project from https://bitbucket.org/Svedrin/mumble-django
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
2.0 KiB

  1. # -*- coding: utf-8 -*-
  2. # kate: space-indent on; indent-width 4; replace-tabs on;
  3. """
  4. * Copyright © 2009-2010, Michael "Svedrin" Ziegler <diese-addy@funzt-halt.net>
  5. *
  6. * Mumble-Django is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This package is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. """
  16. from shutil import copy, move
  17. from os.path import exists, join
  18. from django.conf import settings
  19. from django.db import connection
  20. from django.db.models import signals
  21. from mumble import models
  22. from update_schema import update_schema
  23. from server_detect import find_existing_instances
  24. if settings.DATABASE_ENGINE == "sqlite3":
  25. # Move the DB to the db subdirectory if necessary.
  26. oldpath = join( settings.MUMBLE_DJANGO_ROOT, "mumble-django.db3" )
  27. if not exists( settings.DATABASE_NAME ) and exists( oldpath ):
  28. move( oldpath, settings.DATABASE_NAME )
  29. cursor = connection.cursor()
  30. tablename = models.Mumble._meta.db_table
  31. if tablename in connection.introspection.get_table_list(cursor):
  32. fields = connection.introspection.get_table_description(cursor, tablename)
  33. uptodate = "server_id" in [ entry[0] for entry in fields ]
  34. else:
  35. # Table doesn't yet exist, so syncdb will create it properly
  36. uptodate = True
  37. if not uptodate:
  38. if settings.DATABASE_ENGINE == "sqlite3":
  39. # backup the db before the conversion.
  40. copy( settings.DATABASE_NAME, settings.DATABASE_NAME+".bak" )
  41. signals.post_syncdb.connect( update_schema, sender=models )
  42. else:
  43. signals.post_syncdb.connect( find_existing_instances, sender=models )