From 111193ef96adb711b1b1b4859291c77197eb8ea8 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Tue, 31 Jul 2012 09:12:01 -0400 Subject: unified Metadata/DBMetadata plugins made django optional --- src/lib/Bcfg2/Server/Plugin.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/lib/Bcfg2/Server/Plugin.py') diff --git a/src/lib/Bcfg2/Server/Plugin.py b/src/lib/Bcfg2/Server/Plugin.py index 696dacc06..2a68ea3b7 100644 --- a/src/lib/Bcfg2/Server/Plugin.py +++ b/src/lib/Bcfg2/Server/Plugin.py @@ -11,9 +11,14 @@ import sys import threading import Bcfg2.Server from Bcfg2.Bcfg2Py3k import ConfigParser - import Bcfg2.Options +try: + import django + has_django = True +except ImportError: + has_django = False + # py3k compatibility if sys.hexversion >= 0x03000000: from functools import reduce @@ -106,6 +111,20 @@ class DatabaseBacked(object): def __init__(self): pass + @property + def _use_db(self): + use_db = self.core.setup.cfp.getboolean(self.name.lower(), + "use_database", + default=False) + if use_db and has_django: + return True + elif not use_db: + return False + else: + self.logger.error("use_database is true but django not found") + return False + + class PluginDatabaseModel(object): class Meta: -- cgit v1.2.3-1-g7c22