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.

65 lines
1.8 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. scriptpath = join(
  24. settings.MUMBLE_DJANGO_ROOT, "pyweb", "mumble", "conversionsql", {
  25. 'postgresql_psycopg2': 'pgsql',
  26. 'postgresql': 'pgsql',
  27. 'mysql': 'mysql',
  28. 'sqlite3': 'sqlite',
  29. }[settings.DATABASE_ENGINE]
  30. )
  31. scripts = [ filename for filename in os.listdir( scriptpath ) if filename.endswith( ".sql" ) ]
  32. scripts.sort()
  33. for filename in scripts:
  34. cursor = connection.cursor()
  35. scriptfile = open( os.path.join( scriptpath, filename ), "r" )
  36. try:
  37. stmt = scriptfile.read()
  38. cursor.execute( stmt )
  39. if "postgresql" in settings.DATABASE_ENGINE:
  40. transaction.commit()
  41. except IOError, err:
  42. print "Error reading file '%s':" % filename
  43. print err
  44. except cursor.db.connection.Error, err:
  45. print "Error executing file '%s':" % filename
  46. print err
  47. if "postgresql" in settings.DATABASE_ENGINE:
  48. transaction.rollback()
  49. finally:
  50. scriptfile.close()
  51. cursor.close()
  52. find_existing_instances( **kwargs )