summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Moreau Simard <dmsimard@redhat.com>2018-09-12 09:14:38 -0400
committerDavid Moreau Simard <dmsimard@redhat.com>2018-09-12 10:45:58 -0400
commite4d2b27a0fed243f360db7fbc87d8e86efa6911e (patch)
tree2e7db6ccd3869d79e919e92284473232135830cc
parentee86bb5cfe08e2d47079182b11afb66de67dd3cc (diff)
Move django import and initialization inside the offline client class
This allows to import the class without triggering the import and initialization of django and instead deferring it to when (and if) the class is instanciated. Change-Id: I79be90eb877f21b5254f116e51cc78b310c8674c
Notes
Notes (review): Code-Review+2: David Moreau Simard <dmsimard@redhat.com> Workflow+1: David Moreau Simard <dmsimard@redhat.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Wed, 12 Sep 2018 19:11:53 +0000 Reviewed-on: https://review.openstack.org/602028 Project: openstack/ara-clients Branch: refs/heads/master
-rw-r--r--ara/clients/offline.py31
1 files changed, 16 insertions, 15 deletions
diff --git a/ara/clients/offline.py b/ara/clients/offline.py
index f2876ed..c84528d 100644
--- a/ara/clients/offline.py
+++ b/ara/clients/offline.py
@@ -22,26 +22,27 @@ import json
22import logging 22import logging
23import os 23import os
24 24
25try:
26 from django import setup as django_setup
27 from django.core.management import execute_from_command_line
28 from django.test import Client
29 25
30 os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ara.server.settings') 26class AraOfflineClient(object):
27 def __init__(self):
28 self.log = logging.getLogger(__name__)
31 29
32 # Automatically create the database and run migrations (is there a better way?) 30 try:
33 execute_from_command_line(['django', 'migrate']) 31 from django import setup as django_setup
32 from django.core.management import execute_from_command_line
33 from django.test import Client
34 34
35 # Set up the things Django needs 35 os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ara.server.settings')
36 django_setup()
37except ImportError as e:
38 print('ERROR: The offline client requires ara-server to be installed')
39 raise e
40 36
37 # Automatically create the database and run migrations (is there a better way?)
38 execute_from_command_line(['django', 'migrate'])
39
40 # Set up the things Django needs
41 django_setup()
42 except ImportError as e:
43 self.log.error('The offline client requires ara-server to be installed')
44 raise e
41 45
42class AraOfflineClient(object):
43 def __init__(self):
44 self.log = logging.getLogger(__name__)
45 self.client = Client() 46 self.client = Client()
46 47
47 def _request(self, method, endpoint, **kwargs): 48 def _request(self, method, endpoint, **kwargs):