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.

78 lines
2.1 KiB

  1. # -*- coding: utf-8 -*-
  2. """
  3. * Copyright © 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. import os
  16. from os.path import join
  17. from django.db import connection, transaction
  18. from django.db.models import signals
  19. from django.conf import settings
  20. from mumble import models
  21. from mumble.management.server_detect import find_existing_instances
  22. def update_schema( **kwargs ):
  23. if "verbosity" in kwargs:
  24. v = kwargs['verbosity'];
  25. else:
  26. v = 1;
  27. if v:
  28. print "Migrating Database schema for Mumble-Django 2.0 now."
  29. scriptdir = join(
  30. settings.MUMBLE_DJANGO_ROOT, "pyweb", "mumble", "conversionsql", {
  31. 'postgresql_psycopg2': 'pgsql',
  32. 'postgresql': 'pgsql',
  33. 'mysql': 'mysql',
  34. 'sqlite3': 'sqlite',
  35. }[settings.DATABASE_ENGINE]
  36. )
  37. if v > 1:
  38. print "Reading migration scripts for %s from '%s'" % ( settings.DATABASE_ENGINE, scriptdir )
  39. scripts = [ filename for filename in os.listdir( scriptdir ) if filename.endswith( ".sql" ) ]
  40. scripts.sort()
  41. for filename in scripts:
  42. cursor = connection.cursor()
  43. scriptpath = os.path.join( scriptdir, filename )
  44. scriptfile = open( scriptpath, "r" )
  45. try:
  46. if v > 1:
  47. print "Running migration script '%s'..." % scriptpath
  48. stmt = scriptfile.read()
  49. cursor.execute( stmt )
  50. except IOError, err:
  51. print "Error reading file '%s':" % filename
  52. print err
  53. except cursor.db.connection.Error, err:
  54. print "Error executing file '%s':" % filename
  55. print err
  56. finally:
  57. scriptfile.close()
  58. cursor.close()
  59. if v:
  60. print "Database migration finished successfully."
  61. find_existing_instances( **kwargs )