Merge "Do not attempt to load the offline client if ara-server isn't installed"

This commit is contained in:
Zuul 2019-01-21 15:37:21 +00:00 committed by Gerrit Code Review
commit c28ab133d7
1 changed files with 15 additions and 14 deletions

View File

@ -20,19 +20,23 @@
import logging
import os
import sys
import threading
from django.core.handlers.wsgi import WSGIHandler
from django.core.servers.basehttp import ThreadedWSGIServer, WSGIRequestHandler
from .http import AraHttpClient
from ara.clients.http import AraHttpClient
class AraOfflineClient(AraHttpClient):
def __init__(self):
self.log = logging.getLogger(__name__)
try:
# Validate that ara-server is installed
if "ara.server" not in sys.modules:
raise ImportError("AraOfflineClient requires ara-server to be installed.")
from django import setup as django_setup
from django.core.management import execute_from_command_line
@ -46,9 +50,6 @@ class AraOfflineClient(AraHttpClient):
self._start_server()
super().__init__(endpoint="http://localhost:%d" % self.server_thread.port)
except ImportError:
self.log.error("The offline client requires ara-server to be installed")
raise
def _start_server(self):
self.server_thread = ServerThread("localhost")