diff options
author | Michael Elkins <melkins@tislabs.com> | 2013-03-26 18:57:17 +0000 |
---|---|---|
committer | Michael Elkins <melkins@tislabs.com> | 2013-03-26 18:57:17 +0000 |
commit | 3e321743f6eb19628cbb14ca4a739f25b65a6575 (patch) | |
tree | f91be1fc96a3fddcb12a92c1c5550070a418fb89 | |
parent | 8e10cef711926f522f6bce7efef275c4fac62a27 (diff) |
add new rpki.gui.script_util.setup() that does the ORM setup for standalone scripts so that we don't need to set $DJANGO_SETTINGS_MODULE or $PYTHONPATH. this is similar to what irdbd does.
svn path=/trunk/; revision=5225
-rw-r--r-- | rpkid/rpki/gui/script_util.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/rpkid/rpki/gui/script_util.py b/rpkid/rpki/gui/script_util.py new file mode 100644 index 00000000..f71073ac --- /dev/null +++ b/rpkid/rpki/gui/script_util.py @@ -0,0 +1,32 @@ +""" +This module contains utility functions for use in standalone scripts. +""" + +from django.conf import settings + +from rpki.config import parser + +__version__ = '$Id$' + + +def setup(): + """ + Configure Django enough to use the ORM. + """ + cfg = parser(section='web_portal') + settings.configure( + DATABASES={ + 'default': { + 'ENGINE': 'django.db.backends.mysql', + 'NAME': cfg.get('sql-database'), + 'USER': cfg.get('sql-username'), + 'PASSWORD': cfg.get('sql-password'), + } + }, + INSTALLED_APPS=( + 'rpki.gui.app', + 'rpki.gui.cacheview', + 'rpki.gui.routeview', + 'rpki.irdb' + ) + ) |