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.

60 lines
1.8 KiB

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