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.

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