aboutsummaryrefslogtreecommitdiff
path: root/rpki/gui/script_util.py
diff options
context:
space:
mode:
Diffstat (limited to 'rpki/gui/script_util.py')
-rw-r--r--rpki/gui/script_util.py59
1 files changed, 35 insertions, 24 deletions
diff --git a/rpki/gui/script_util.py b/rpki/gui/script_util.py
index fb15403d..8919139c 100644
--- a/rpki/gui/script_util.py
+++ b/rpki/gui/script_util.py
@@ -16,13 +16,6 @@
This module contains utility functions for use in standalone scripts.
"""
-import django
-
-from django.conf import settings
-
-from rpki import config
-from rpki import autoconf
-
__version__ = '$Id$'
@@ -30,20 +23,38 @@ def setup():
"""
Configure Django enough to use the ORM.
"""
- cfg = config.parser(section='web_portal')
- # INSTALLED_APPS doesn't seem necessary so long as you are only accessing
- # existing tables.
- settings.configure(
- DATABASES={
- 'default': {
- 'ENGINE': 'django.db.backends.mysql',
- 'NAME': cfg.get('sql-database'),
- 'USER': cfg.get('sql-username'),
- 'PASSWORD': cfg.get('sql-password'),
- }
- },
- MIDDLEWARE_CLASSES = (),
- )
- if django.VERSION >= (1, 7):
- from django.apps import apps
- apps.populate(settings.INSTALLED_APPS)
+
+ # In theory we no longer need to call settings.configure, which
+ # probably means this whole module can go away soon, but leave
+ # breadcrumbs for now.
+
+ if True:
+ os.environ.update(DJANGO_SETTINGS_MODULE = "rpki.django_settings")
+
+ else:
+ import django
+ from rpki import config
+ from rpki import autoconf
+ from django.conf import settings
+
+ cfg = config.parser(section='web_portal')
+ # INSTALLED_APPS doesn't seem necessary so long as you are only accessing
+ # existing tables.
+ settings.configure(
+ DATABASES={
+ 'default': {
+ 'ENGINE': 'django.db.backends.mysql',
+ 'NAME': cfg.get('sql-database'),
+ 'USER': cfg.get('sql-username'),
+ 'PASSWORD': cfg.get('sql-password'),
+ },
+ },
+ MIDDLEWARE_CLASSES = (),
+ )
+ # Can't populate apps if we don't know what they are. If this
+ # explodes with an AppRegistryNotReady exception, the above comment
+ # about not needing to set INSTALLED_APPS is no longer true and
+ # you'll need to fix that here.
+ if False and django.VERSION >= (1, 7):
+ from django.apps import apps
+ apps.populate(settings.INSTALLED_APPS)