Commit a01d5ccc authored by Lionel Morin's avatar Lionel Morin

Merge branch 'feature/amelioration' into 'develop'

Feature/amelioration

See merge request !13
parents 4f45fc7b 9889e193
Pipeline #861 passed with stage
in 0 seconds
......@@ -10,7 +10,6 @@ RUN apt-get update -y && apt-get install -y \
gettext \
git \
make \
python3-ipy \
python3-lxml \
python3-setuptools
......@@ -58,25 +57,6 @@ RUN git clone "${PYTHON_ZEPHIR_REPO_URL}" "/tmp/python-zephir" \
&& cd /tmp/python-zephir \
&& git checkout "${PYTHON_ZEPHIR_REPO_REF}"
# Tiramisu
ARG TIRAMISU_REPO_URL=https://framagit.org/tiramisu/tiramisu.git
ARG TIRAMISU_REPO_REF=release/3.0rc4
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 \
&& cd /tmp/tiramisu \
&& git checkout "${TIRAMISU_REPO_REF}" \
&& make DESTDIR=${TIRAMISU_DEST_DIR} build-lang install-lang \
&& python3 setup.py install --root ${TIRAMISU_DEST_DIR}
# Tiramisu json
ARG TIRAMISU_JSON_REPO_URL=https://framagit.org/tiramisu/tiramisu-json.git
ARG TIRAMISU_JSON_REPO_REF=0e6fd8b29ccb27e902071d1e7b2ca857b00477d3
RUN git clone "${TIRAMISU_JSON_REPO_URL}" /tmp/tiramisu-json \
&& cd /tmp/tiramisu-json \
&& git checkout "${TIRAMISU_JSON_REPO_REF}"
####
#### Target layer
......@@ -122,6 +102,9 @@ RUN dpkg-reconfigure --frontend noninteractive tzdata
RUN pip3 install casbin
# Tiramisu
RUN pip3 install tiramisu==3.0rc10
# Sqitch
RUN sqitch config --user user.name 'Equipe EOLE'\
&& sqitch config --user user.email 'eole@ac-dijon.fr'
......@@ -154,18 +137,6 @@ COPY containerpilot.json5 /etc/containerpilot.json5
## Service specific
##
RUN apt-get update -y && apt-get install -y \
python3-ipy
# Tiramisu
COPY --from=build /tmp/build/tiramisu/usr/share/locale /usr/share/locale
COPY --from=build /tmp/build/tiramisu/usr/local/lib/python3.6/dist-packages/tiramisu/ /usr/local/lib/python3.6/dist-packages/tiramisu/
COPY --from=build /tmp/tiramisu/tiramisu/storage/cache /usr/local/lib/python3.6/dist-packages/tiramisu/storage/cache
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/sqlite3 /usr/local/lib/python3.6/dist-packages/tiramisu/storage/sqlite3
# Tiramisu json
COPY --from=build /tmp/tiramisu-json/tiramisu_json/ /usr/lib/python3/dist-packages/tiramisu_json
# Library
COPY src/python/apibridge /usr/lib/python3/dist-packages/apibridge
......
......@@ -2,9 +2,7 @@
# -*- 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
......@@ -34,7 +32,11 @@ class ApiBridgeCtrl(ZephirCommonController):
def __init__(self, *args, **kwargs):
self.policy = None
super().__init__(*args, **kwargs)
self.needs, self.responses, self.tiramisu = get_messages()
self.needs, self.responses, tiramisu = get_messages()
form = [{'title': 'Exécuter',
'cmd': 'ajax',
'type': 'submit'}]
self.tiramisu = tiramisu.option.dict(remotable='none', form=form)
async def http_to_rpc(self, request, uri, **kwargs):
ret = await self.call(uri, **kwargs)
......@@ -53,14 +55,9 @@ class ApiBridgeCtrl(ZephirCommonController):
@register('/v1', http_type='get')
async def http_api(self, request, _session_user):
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}
values = {'options': self.tiramisu,
'responses': self.responses,
'needs': self.needs}
return dumps(values)
if __name__ == "__main__":
......
......@@ -15,12 +15,16 @@ def _get_description(description,
doc = description
else:
doc = name
if doc.endswith('.'):
doc= description[:-1]
return doc
def _get_option(name,
arg,
file_path):
file_path,
select_option,
optiondescription):
"""generate option
"""
props = []
......@@ -29,11 +33,16 @@ def _get_option(name,
description = arg.description.strip().rstrip()
kwargs = {'name': name,
'doc': _get_description(description, name),
'properties': frozenset(props)}
'properties': frozenset(props),
'multi': arg.multi,
'requires': [{'option': select_option,
'expected': optiondescription,
'action': 'disabled',
'inverse': True}]}
if hasattr(arg, 'default'):
kwargs['default'] = arg.default
type_ = arg.type
if type_ == 'Dict' or 'String' in type_:
if type_ == 'Dict' or 'String' in type_ or 'Any' in type_:
return StrOption(**kwargs)
elif 'Number' in type_ or type_ == 'ID' or type_ == 'Integer':
return IntOption(**kwargs)
......@@ -45,7 +54,9 @@ def _get_option(name,
def _parse_args(message_def,
options,
file_path,
needs):
needs,
select_option,
optiondescription):
"""build option with args/kwargs
"""
new_options = OrderedDict()
......@@ -54,7 +65,7 @@ def _parse_args(message_def,
if arg.ref:
needs.setdefault(message_def.uri, {}).setdefault(arg.ref, []).append(name)
for name, arg in new_options.items():
current_opt = _get_option(name, arg, file_path)
current_opt = _get_option(name, arg, file_path, select_option, optiondescription)
options.append(current_opt)
if arg.shortarg:
options.append(SymLinkOption(arg.shortarg, current_opt))
......@@ -117,7 +128,8 @@ def _getoptions_from_yml(message_def,
version,
optiondescriptions,
file_path,
needs):
needs,
select_option):
if message_def.pattern == 'event' and message_def.response:
raise Exception('event with response?: {}'.format(file_path))
if message_def.pattern == 'rpc' and not message_def.response:
......@@ -126,35 +138,45 @@ def _getoptions_from_yml(message_def,
'version',
version,
properties=frozenset(['hidden']))]
_parse_args(message_def, options, file_path, needs)
_parse_args(message_def, options, file_path, needs, select_option, message_def.uri)
name = message_def.uri
description = message_def.description.strip().rstrip()
optiondescriptions[name] = (description, options)
def _get_root_option(optiondescriptions):
def _get_root_option(select_option, optiondescriptions):
"""get root option
"""
messages = []
for name in optiondescriptions.keys():
messages.append(name)
messages.sort()
options_obj = [ChoiceOption('message',
'Nom du message.',
tuple(messages),
properties=frozenset(['mandatory', 'positional']))]
for name, options_descr in optiondescriptions.items():
description, options = options_descr
requires = [{'option': options_obj[0],
'expected': name,
'action': 'disabled',
'inverse': True}]
properties = None
options_obj.append(OptionDescription(name.replace('.', '_'),
description,
options,
properties=properties,
requires=requires))
def _get_od(curr_ods):
options = []
for name in curr_ods.keys():
if name is None:
description, curr_options = curr_ods[name]
options.extend(curr_ods[name][1])
else:
if None in curr_ods[name].keys():
description = curr_ods[name][None][0]
if description.endswith('.'):
description = description[:-1]
else:
description = None
options.append(OptionDescription(name,
description,
_get_od(curr_ods[name])))
return options
options_obj = [select_option]
struct_od = {}
for od_name, options_descr in optiondescriptions.items():
# od_name is something like config.configuration.server.get
curr_od = struct_od
for subod in od_name.split('.'):
curr_od.setdefault(subod, {})
curr_od = curr_od[subod]
# curr_od is now {'config': {'configuration': {server: {}}}}
curr_od[None] = options_descr
# curr_od is now {'config': {'configuration': {server: {None: options_descr}}}}
options_obj.extend(_get_od(struct_od))
return OptionDescription('root', 'root', options_obj)
......@@ -162,27 +184,40 @@ def get_messages():
"""generate description from yml files
"""
optiondescriptions = OrderedDict()
optiondescriptions_name = []
responses = OrderedDict()
needs = OrderedDict()
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
optiondescriptions_name.append(message_def.uri)
optiondescriptions_name.sort()
select_option = ChoiceOption('message',
'Nom du message.',
tuple(optiondescriptions_name),
properties=frozenset(['mandatory', 'positional']))
for message_name in messages:
message_def = get_message(message_name)
if message_def.pattern not in ['rpc', 'event'] or \
(not message_def.public and not ALLOW_PRIVATE):
continue
version = message_name.split('.')[0]
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)
needs,
select_option)
responses[message_def.uri] = _parse_responses(message_def,
message_name)
root = _get_root_option(optiondescriptions)
root = _get_root_option(select_option, optiondescriptions)
try:
config = Config(root)
except Exception as err:
......
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