From 255faafd7f98b80e39d742483fd284a7a962062a Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Mon, 21 Nov 2016 18:54:13 +0100 Subject: Reporting/Storage: Remove wildcard import --- src/lib/Bcfg2/Reporting/Storage/DjangoORM.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/lib/Bcfg2/Reporting') diff --git a/src/lib/Bcfg2/Reporting/Storage/DjangoORM.py b/src/lib/Bcfg2/Reporting/Storage/DjangoORM.py index ac0cde783..27040feb6 100644 --- a/src/lib/Bcfg2/Reporting/Storage/DjangoORM.py +++ b/src/lib/Bcfg2/Reporting/Storage/DjangoORM.py @@ -20,7 +20,10 @@ from django.core.cache import cache #Used by GetCurrentEntry import difflib from Bcfg2.Compat import b64decode -from Bcfg2.Reporting.models import * +from Bcfg2.Reporting.models import \ + Interaction, PackageEntry, FilePerms, PathEntry, LinkEntry, \ + Group, Client, Bundle, TYPE_EXTRA, TYPE_BAD, TYPE_MODIFIED, \ + FailureEntry, Performance, BaseEntry from Bcfg2.Reporting.Compat import transaction -- cgit v1.2.3-1-g7c22 From f500167d2aae88d9b2a68fb792a9cad797a9338b Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Mon, 21 Nov 2016 19:13:07 +0100 Subject: Reporting/Storage: Load django models after option parsing django get setup during option parsing and we cannot acces "django.db.models" before. So we need to delay the import of the models until the option parsing is ready. --- src/lib/Bcfg2/Reporting/Storage/DjangoORM.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/lib/Bcfg2/Reporting') diff --git a/src/lib/Bcfg2/Reporting/Storage/DjangoORM.py b/src/lib/Bcfg2/Reporting/Storage/DjangoORM.py index 27040feb6..cdfab7704 100644 --- a/src/lib/Bcfg2/Reporting/Storage/DjangoORM.py +++ b/src/lib/Bcfg2/Reporting/Storage/DjangoORM.py @@ -20,13 +20,23 @@ from django.core.cache import cache #Used by GetCurrentEntry import difflib from Bcfg2.Compat import b64decode -from Bcfg2.Reporting.models import \ - Interaction, PackageEntry, FilePerms, PathEntry, LinkEntry, \ - Group, Client, Bundle, TYPE_EXTRA, TYPE_BAD, TYPE_MODIFIED, \ - FailureEntry, Performance, BaseEntry from Bcfg2.Reporting.Compat import transaction +def load_django_models(): + """ Load models for Django after option parsing has completed """ + # pylint: disable=W0602 + global Interaction, PackageEntry, FilePerms, PathEntry, LinkEntry, \ + Group, Client, Bundle, TYPE_EXTRA, TYPE_BAD, TYPE_MODIFIED, \ + FailureEntry, Performance, BaseEntry + # pylint: enable=W0602 + + from Bcfg2.Reporting.models import \ + Interaction, PackageEntry, FilePerms, PathEntry, LinkEntry, \ + Group, Client, Bundle, TYPE_EXTRA, TYPE_BAD, TYPE_MODIFIED, \ + FailureEntry, Performance, BaseEntry + + def get_all_field_names(model): if django.VERSION[0] == 1 and django.VERSION[1] >= 8: return [field.name @@ -45,6 +55,7 @@ class DjangoORM(StorageBase): type=Bcfg2.Options.Types.size, help='Reporting file size limit', default=1024 * 1024)] + options_parsed_hook = staticmethod(load_django_models) def _import_default(self, entry, state, entrytype=None, defaults=None, mapping=None, boolean=None, xforms=None): -- cgit v1.2.3-1-g7c22 From acd3a53c732eea1cb2dc046438626c729278f67c Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Mon, 21 Nov 2016 19:15:15 +0100 Subject: Reporting/Storage: Removed unused import --- src/lib/Bcfg2/Reporting/Storage/DjangoORM.py | 1 - 1 file changed, 1 deletion(-) (limited to 'src/lib/Bcfg2/Reporting') diff --git a/src/lib/Bcfg2/Reporting/Storage/DjangoORM.py b/src/lib/Bcfg2/Reporting/Storage/DjangoORM.py index cdfab7704..f763a3273 100644 --- a/src/lib/Bcfg2/Reporting/Storage/DjangoORM.py +++ b/src/lib/Bcfg2/Reporting/Storage/DjangoORM.py @@ -12,7 +12,6 @@ from Bcfg2.Compat import md5 from Bcfg2.Reporting.Storage.base import StorageBase, StorageError from Bcfg2.Server.Plugin.exceptions import PluginExecutionError import django -from django.core import management from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned from django.db.models import FieldDoesNotExist from django.core.cache import cache -- cgit v1.2.3-1-g7c22 From 73fb40f2ac080ccbb4d9f0f0acc2c7f5009321f6 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Mon, 21 Nov 2016 19:15:36 +0100 Subject: Reporting/Storage: Reordering of the imports --- src/lib/Bcfg2/Reporting/Storage/DjangoORM.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src/lib/Bcfg2/Reporting') diff --git a/src/lib/Bcfg2/Reporting/Storage/DjangoORM.py b/src/lib/Bcfg2/Reporting/Storage/DjangoORM.py index f763a3273..347e5cc81 100644 --- a/src/lib/Bcfg2/Reporting/Storage/DjangoORM.py +++ b/src/lib/Bcfg2/Reporting/Storage/DjangoORM.py @@ -2,24 +2,23 @@ The base for the original DjangoORM (DBStats) """ -from lxml import etree -from datetime import datetime +import difflib import traceback +from datetime import datetime from time import strptime -import Bcfg2.Options -import Bcfg2.DBSettings -from Bcfg2.Compat import md5 -from Bcfg2.Reporting.Storage.base import StorageBase, StorageError -from Bcfg2.Server.Plugin.exceptions import PluginExecutionError +from lxml import etree + import django from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned from django.db.models import FieldDoesNotExist from django.core.cache import cache -#Used by GetCurrentEntry -import difflib -from Bcfg2.Compat import b64decode +import Bcfg2.Options +import Bcfg2.DBSettings +from Bcfg2.Compat import b64decode, md5 from Bcfg2.Reporting.Compat import transaction +from Bcfg2.Reporting.Storage.base import StorageBase, StorageError +from Bcfg2.Server.Plugin.exceptions import PluginExecutionError def load_django_models(): -- cgit v1.2.3-1-g7c22 From fa0d86aba32c40d829f9f94411403221a48283e8 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Mon, 28 Nov 2016 21:12:22 +0100 Subject: DBSettings: Call django.setup() right after configuring the settings If required the DBSettings config hook will call django.setup right after configuring django with the required settings. So we can drop the calls to django.setup from all other places. --- src/lib/Bcfg2/Reporting/Reports.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/lib/Bcfg2/Reporting') diff --git a/src/lib/Bcfg2/Reporting/Reports.py b/src/lib/Bcfg2/Reporting/Reports.py index 7ba0265ae..e60b2e82e 100755 --- a/src/lib/Bcfg2/Reporting/Reports.py +++ b/src/lib/Bcfg2/Reporting/Reports.py @@ -327,8 +327,6 @@ class CLI(Bcfg2.Options.CommandRegistry): components=[self]) parser.add_options(self.subcommand_options) parser.parse() - if django.VERSION[0] == 1 and django.VERSION[1] >= 7: - django.setup() # pylint: disable=E1101 def run(self): """ Run bcfg2-reports """ -- cgit v1.2.3-1-g7c22