kopia lustrzana https://github.com/OpenDroneMap/WebODM
Removed swagger
rodzic
9581f563b7
commit
d12513647c
|
@ -64,7 +64,6 @@ Then:
|
|||
|
||||
```
|
||||
pip install -r requirements.txt
|
||||
pip install --upgrade git+git://github.com/Yelp/swagger_spec_validator
|
||||
npm install -g webpack
|
||||
npm install
|
||||
webpack
|
||||
|
|
|
@ -1,43 +1,26 @@
|
|||
"""
|
||||
A wrapper around Bravado to communicate with a node-OpenDroneMap node.
|
||||
An interface to
|
||||
"""
|
||||
from bravado.client import SwaggerClient
|
||||
from bravado.exception import HTTPError
|
||||
from requests import ConnectionError
|
||||
import requests
|
||||
|
||||
class ApiClient:
|
||||
def check_client(func):
|
||||
def check(self, *args, **kwargs):
|
||||
"""
|
||||
Makes sure that the client has been instantiated.
|
||||
Sometimes this will fail (rest endpoint might be offline),
|
||||
so we need to handle it gracefully...
|
||||
"""
|
||||
if not hasattr(self, 'client'):
|
||||
try:
|
||||
self.client = SwaggerClient.from_url('http://{}:{}/swagger.json'.format(self.host, self.port))
|
||||
except (ConnectionError, HTTPError) as err:
|
||||
return None
|
||||
|
||||
return func(self, *args, **kwargs)
|
||||
return check
|
||||
|
||||
def __init__(self, host, port):
|
||||
self.host = host
|
||||
self.port = port
|
||||
|
||||
@check_client
|
||||
def url(self, url):
|
||||
return "http://{}:{}{}".format(self.host, self.port, url)
|
||||
|
||||
def info(self):
|
||||
return self.client.server.get_info().result()
|
||||
return requests.get(self.url('/info')).json()
|
||||
|
||||
@check_client
|
||||
def options(self):
|
||||
return self.client.server.get_options().result()
|
||||
return requests.get(self.url('/options')).json()
|
||||
|
||||
@check_client
|
||||
def new_task(self):
|
||||
print(dir(self.client.task.post_task_new))
|
||||
return self.client.task.post_task_new(images=[])
|
||||
pass
|
||||
#print(dir(self.client.task.post_task_new))
|
||||
#return self.client.task.post_task_new(images=dict(images="../Gruntfile.js")).result()
|
||||
|
||||
a = ApiClient("localhost", 3000)
|
||||
a.new_task()
|
||||
#a = ApiClient("localhostaa", 3000)
|
||||
#print(a.info())
|
|
@ -7,6 +7,7 @@ from django.dispatch import receiver
|
|||
from .api_client import ApiClient
|
||||
import json
|
||||
from django.db.models import signals
|
||||
from requests.exceptions import ConnectionError
|
||||
|
||||
class ProcessingNode(models.Model):
|
||||
hostname = models.CharField(max_length=255, help_text="Hostname where the node is located (can be an internal hostname as well)")
|
||||
|
@ -27,19 +28,18 @@ class ProcessingNode(models.Model):
|
|||
:returns: True if information could be updated, False otherwise
|
||||
"""
|
||||
api_client = self.api_client()
|
||||
info = api_client.info()
|
||||
if info != None:
|
||||
try:
|
||||
info = api_client.info()
|
||||
self.api_version = info['version']
|
||||
self.queue_count = info['taskQueueCount']
|
||||
|
||||
options = api_client.options()
|
||||
if options != None:
|
||||
self.available_options = options
|
||||
self.last_refreshed = timezone.now()
|
||||
|
||||
self.save()
|
||||
return True
|
||||
return False
|
||||
self.available_options = options
|
||||
self.last_refreshed = timezone.now()
|
||||
self.save()
|
||||
return True
|
||||
except ConnectionError:
|
||||
return False
|
||||
|
||||
def api_client(self):
|
||||
return ApiClient(self.hostname, self.port)
|
||||
|
|
|
@ -4,6 +4,7 @@ import subprocess, time
|
|||
from os import path
|
||||
from .models import ProcessingNode
|
||||
from .api_client import ApiClient
|
||||
from requests.exceptions import ConnectionError
|
||||
|
||||
current_dir = path.dirname(path.realpath(__file__))
|
||||
|
||||
|
@ -31,8 +32,8 @@ class TestClientApi(TestCase):
|
|||
|
||||
def test_offline_api(self):
|
||||
api = ApiClient("offline-host", 3000)
|
||||
self.assertTrue(api.info() == None)
|
||||
self.assertTrue(api.options() == None)
|
||||
self.assertRaises(ConnectionError, api.info)
|
||||
self.assertRaises(ConnectionError, api.options)
|
||||
|
||||
def test_info(self):
|
||||
info = self.api_client.info()
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
anyjson==0.3.3
|
||||
APScheduler==3.2.0
|
||||
attrs==16.2.0
|
||||
bravado==8.3.0
|
||||
bravado-core==4.5.0
|
||||
cffi==1.8.3
|
||||
crochet==1.5.0
|
||||
cryptography==1.5
|
||||
Django==1.10
|
||||
django-common-helpers==0.8.0
|
||||
django-filter==0.15.3
|
||||
|
@ -13,31 +7,16 @@ django-guardian==1.4.6
|
|||
django-webpack-loader==0.3.3
|
||||
djangorestframework==3.5.1
|
||||
drf-nested-routers==0.11.1
|
||||
enum34==1.1.6
|
||||
fido==3.2.0
|
||||
funcsigs==1.0.2
|
||||
functools32==3.2.3.post2
|
||||
futures==3.0.5
|
||||
idna==2.1
|
||||
ipaddress==1.0.17
|
||||
jsonschema==2.5.1
|
||||
Markdown==2.6.7
|
||||
pillow==3.3.1
|
||||
pip-autoremove==0.9.0
|
||||
psycopg2==2.6.2
|
||||
pyasn1==0.1.9
|
||||
pyasn1-modules==0.0.8
|
||||
pycparser==2.14
|
||||
pyOpenSSL==16.1.0
|
||||
python-dateutil==2.5.3
|
||||
pytz==2016.6.1
|
||||
PyYAML==3.12
|
||||
requests==2.11.1
|
||||
service-identity==16.0.0
|
||||
simplejson==3.8.2
|
||||
rfc3987==1.3.7
|
||||
six==1.10.0
|
||||
swagger-spec-validator==2.0.2
|
||||
Twisted==16.4.1
|
||||
strict-rfc3339==0.7
|
||||
tzlocal==1.3
|
||||
yelp-bytes==0.3.0
|
||||
yelp-encodings==0.1.3
|
||||
zope.interface==4.3.2
|
||||
webcolors==1.5
|
||||
|
|
Ładowanie…
Reference in New Issue