Commit 196b0929 authored by Lionel Morin's avatar Lionel Morin

Merge branch 'tiramisu-json' into 'develop'

Update to tiramisu-json

See merge request !2
parents c9f5a5cd 666ea596
......@@ -60,7 +60,7 @@ RUN git clone "${PYTHON_ZEPHIR_REPO_URL}" "/tmp/python-zephir" \
# Tiramisu
ARG TIRAMISU_REPO_URL=https://framagit.org/tiramisu/tiramisu.git
ARG TIRAMISU_REPO_REF=fee8997f1371d2ae18b700950c8aa3cc2e4e6a8c
ARG TIRAMISU_REPO_REF=26fa9231
ARG TIRAMISU_DEST_DIR=/tmp/build/tiramisu
# XXX: specific stable tag in the feature/3.0 tiramisu development branch
RUN git clone "${TIRAMISU_REPO_URL}" /tmp/tiramisu \
......@@ -70,14 +70,12 @@ RUN git clone "${TIRAMISU_REPO_URL}" /tmp/tiramisu \
&& python3 setup.py install --root ${TIRAMISU_DEST_DIR}
# Tiramisu Web
ARG TIRAMISU_WEB_REPO_URL=https://forge.cadoles.com/egarette/tiramisu-web.git
ARG TIRAMISU_WEB_REPO_REF=9ce55c7d3262c0013f9c3a6e509bd15518c39724
ARG TIRAMISU_WEB_DEST_DIR=/tmp/build/tiramisu-web
RUN git clone "${TIRAMISU_WEB_REPO_URL}" /tmp/tiramisu-web \
&& cd /tmp/tiramisu-web \
&& git checkout "${TIRAMISU_WEB_REPO_REF}" \
&& python3 setup.py install --root ${TIRAMISU_WEB_DEST_DIR}
# Tiramisu json
ARG TIRAMISU_JSON_REPO_URL=https://framagit.org/tiramisu/tiramisu-json.git
ARG TIRAMISU_JSON_REPO_REF=72031109
RUN git clone "${TIRAMISU_JSON_REPO_URL}" /tmp/tiramisu-json \
&& cd /tmp/tiramisu-json \
&& git checkout "${TIRAMISU_JSON_REPO_REF}"
####
......@@ -161,8 +159,8 @@ COPY --from=build /tmp/tiramisu/tiramisu/storage/cache /usr/local/lib/python3.6/
COPY --from=build /tmp/tiramisu/tiramisu/storage/dictionary /usr/local/lib/python3.6/dist-packages/tiramisu/storage/dictionary
COPY --from=build /tmp/tiramisu/tiramisu/storage/sqlalchemy /usr/local/lib/python3.6/dist-packages/tiramisu/storage/sqlalchemy
COPY --from=build /tmp/tiramisu/tiramisu/storage/sqlite3 /usr/local/lib/python3.6/dist-packages/tiramisu/storage/sqlite3
# Tiramisu Web
COPY --from=build /tmp/tiramisu-web/src/python/tiramisu_web /usr/lib/python3/dist-packages/tiramisu_web
# Tiramisu json
COPY --from=build /tmp/tiramisu-json/tiramisu_json/ /usr/lib/python3/dist-packages/tiramisu_json
# Controller
RUN mkdir -p /srv/bin
COPY scripts/controller /srv/bin
......
......@@ -2,12 +2,13 @@
# -*- coding: utf-8 -*-
from json import loads, dumps
from tiramisu_json import TiramisuJson
from aiohttp.web import HTTPForbidden, StreamResponse, HTTPInternalServerError, Response
from autobahn.wamp.exception import ApplicationError
from zephir.controller import ZephirCommonController, run
from zephir.http import register
from zephir.message import list_messages, get_message, is_message_defined
from zephir.message import list_messages, get_message
from apibridge import get_messages
from zephir.i18n import _
......@@ -29,6 +30,10 @@ class ApiBridgeCtrl(ZephirCommonController):
raise Exception('unknown message pattern {}'.format(uri))
register(uri, http_type='post', parameters_type='json', add_uri_in_response=True, allow_kwargs=True)(func)
return super().__new__(cls)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.needs, self.responses, self.tiramisu = get_messages()
async def http_to_rpc(self, request, uri, **kwargs):
ret = await self.call(uri, **kwargs)
......@@ -47,8 +52,15 @@ class ApiBridgeCtrl(ZephirCommonController):
@register('/v1', http_type='get')
async def http_api(self, request, _session_user):
return dumps(get_messages("v1"))
tiramisu = TiramisuJson(self.tiramisu, remotable='none')
form = [
{'title': 'Exécuter',
'cmd': 'ajax',
'type': 'submit'}]
values = {'options': tiramisu.get_jsonform(form),
'responses': self.responses,
'needs': self.needs}
return dumps(values)
if __name__ == "__main__":
run(ApiBridgeCtrl)
......@@ -4,8 +4,6 @@ from os.path import join, basename, dirname
from glob import glob
from tiramisu import StrOption, IntOption, BoolOption, ChoiceOption, OptionDescription, Config
from tiramisu_web import TiramisuWeb
ALLOW_PRIVATE = False
ROOTPATH = join('..')
......@@ -51,7 +49,6 @@ def _parse_args(message_def,
"""build option with args/kwargs
"""
new_options = OrderedDict()
for name, arg in message_def.parameters.items():
new_options[name] = arg
if arg.ref:
......@@ -77,10 +74,12 @@ def _parse_responses(message_def,
param_type = param_type[2:]
if param_type in ['Dict', 'File']:
pass
if message_def.response.parameters is not None:
for name, obj in message_def.response.parameters.items():
if name in responses:
raise Exception('multi response with name {} in {}'.format(name, file_path))
descr = obj.description.strip().rstrip()
keys['']['columns'][name] = {'description': obj.description,
'type': obj.type}
......@@ -133,35 +132,18 @@ def _getoptions_from_yml(message_def,
def _get_root_option(optiondescriptions):
"""get root option
"""
domains = OrderedDict()
messages = []
for name in optiondescriptions.keys():
domains.setdefault(name.split('.')[0], []).append(name)
domains_list = list(domains.keys())
domains_list.sort()
domain_option = ChoiceOption('domain',
'Sélectionner le domaine',
tuple(domains_list),
properties=frozenset(['mandatory']))
options_obj = [domain_option]
messages = OrderedDict()
for domain in domains_list:
requires = [{'option': domain_option,
'expected': domain,
'action': 'disabled',
'inverse': True}]
option = ChoiceOption('message_' + domain,
'Sélectionner le message du domaine {}'.format(domain),
tuple(domains[domain]),
requires=requires,
properties=frozenset(['mandatory']))
options_obj.append(option)
messages[domain] = option
messages.append(name)
messages.sort()
options_obj = [ChoiceOption('message',
'Sélectionner le message.',
tuple(messages),
properties=frozenset(['mandatory']))]
for name, options_descr in optiondescriptions.items():
description, options = options_descr
message = messages[name.split('.')[0]]
if len(options) != 1:
requires = [{'option': message,
requires = [{'option': options_obj[0],
'expected': name,
'action': 'disabled',
'inverse': True}]
......@@ -177,53 +159,36 @@ def _get_root_option(optiondescriptions):
return OptionDescription('root', 'root', options_obj)
def get_messages(version="v1", list_msg=None):
def get_messages():
"""generate description from yml files
version : version of the API to return
list_msg : alternate list of MessageDefinitions for testing purpose
"""
optiondescriptions = OrderedDict()
responses = OrderedDict()
needs = OrderedDict()
messages = []
if list_msg is None:
list_msg = list(list_messages())
list_msg.sort()
for message_name in list_msg:
if message_name.startswith('{}.'.format(version)):
messages.append((message_name, get_message(message_name)))
else:
for msg in list_msg:
messages.append(('{}.{}'.format(version, msg.uri), msg))
for message_name, message_def in messages:
if message_name.startswith('{}.'.format(version)):
if message_def.pattern not in ['rpc', 'event'] or \
(not message_def.public and not ALLOW_PRIVATE):
continue
if message_def.uri in responses:
raise Exception('uri {} allready loader'.format(message_def.uri))
_getoptions_from_yml(message_def,
version,
optiondescriptions,
message_name,
needs)
responses[message_def.uri] = _parse_responses(message_def,
message_name)
messages = list(list_messages())
messages.sort()
for message_name in messages:
message_def = get_message(message_name)
version = message_name.split('.')[0]
if message_def.pattern not in ['rpc', 'event'] or \
(not message_def.public and not ALLOW_PRIVATE):
continue
if message_def.uri in responses:
raise Exception('uri {} allready loader'.format(message_def.uri))
_getoptions_from_yml(message_def,
version,
optiondescriptions,
message_name,
needs)
responses[message_def.uri] = _parse_responses(message_def,
message_name)
root = _get_root_option(optiondescriptions)
try:
api = Config(root)
config = Config(root)
except Exception as err:
raise Exception('error when generating root optiondescription: {}'.format(err))
tiramisu = TiramisuWeb(api, remotable='none')
form = [
{'title': 'Exécuter',
'cmd': 'ajax',
'type': 'submit'}]
values = {'options': tiramisu.get_jsonform(form),
'responses': responses,
'needs': needs}
return values
config.property.read_write()
config.property.add('demoting_error_warning')
return needs, responses, config
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment