Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
EOLE
Zéphir
Services
API Bridge
Commits
047f2680
Commit
047f2680
authored
Feb 01, 2019
by
Matthieu Lamalle
Browse files
Update to tiramisu-json
parent
c9f5a5cd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Dockerfile
View file @
047f2680
...
...
@@ -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/pyth
on/tiramisu_
web
/usr/lib/python3/dist-packages/tiramisu_
web
# Tiramisu
json
COPY
--from=build /tmp/tiramisu-
js
on/tiramisu_
json/
/usr/lib/python3/dist-packages/tiramisu_
json
# Controller
RUN
mkdir
-p
/srv/bin
COPY
scripts/controller /srv/bin
...
...
scripts/controller
View file @
047f2680
...
...
@@ -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
,
get
_message
s
from
apibridge
import
get_messages
from
zephir.i18n
import
_
...
...
@@ -47,8 +48,21 @@ 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': 'Générer une commande',
# 'cmd': 'curl',
# 'type': 'submit'},
#{'title': 'Générer du code Python',
# 'cmd': 'python',
# 'type': 'submit'},
{
'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
)
src/python/apibridge/zephirmessage.py
View file @
047f2680
...
...
@@ -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
(
'..'
)
...
...
@@ -32,6 +30,8 @@ def _get_option(name,
kwargs
=
{
'name'
:
name
,
'doc'
:
_get_description
(
description
,
name
),
'properties'
:
frozenset
(
props
)}
#if arg.multiple:
# kwargs['multi'] = True
if
hasattr
(
arg
,
'default'
):
kwargs
[
'default'
]
=
arg
.
default
type_
=
arg
.
type
...
...
@@ -51,8 +51,16 @@ def _parse_args(message_def,
"""build option with args/kwargs
"""
new_options
=
OrderedDict
()
#for idx, arg in enumerate(message_def.args):
# name = 'tiramisu_' + str(idx)
# if not arg.required:
# raise Exception('arg without required ?? in {}'.format(file_path))
# new_options[name] = arg
# if arg.needs:
# needs.setdefault(message_def.uri, {}).setdefault(arg.needs, []).append(name)
for
name
,
arg
in
message_def
.
parameters
.
items
():
#if name.startswith('tiramisu_'):
# raise Exception('multi args with name {} in {}'.format(name, file_path))
new_options
[
name
]
=
arg
if
arg
.
ref
:
needs
.
setdefault
(
message_def
.
uri
,
{}).
setdefault
(
arg
.
ref
,
[]).
append
(
name
)
...
...
@@ -77,16 +85,69 @@ def _parse_responses(message_def,
param_type
=
param_type
[
2
:]
if
param_type
in
[
'Dict'
,
'File'
]:
pass
#break
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
))
#param_type = obj.type
descr
=
obj
.
description
.
strip
().
rstrip
()
#if message_def.parameters:
# for custom_name, custom_param in message_def.parameters.items():
# param_type2 = custom_param.type
# #if param_type2 in message_def.customtype:
# # keys[custom_name] = {'description': custom_descr,
# # 'columns': {}}
# # customtype2 = message_def.customtype[param_type2]
# # for custom_name2, custom_param2 in customtype2['parameters'].items():
# # keys[custom_name]['columns'][custom_name2] = {'description': custom_param2['description'].strip().rstrip(),
# # 'type': param_type2}
# # ref = custom_param2.get('ref')
# # if ref:
# # provides[custom_name2] = ref
# #else:
# keys['']['columns'][custom_name] = {'description': custom_param.description,
# 'type': param_type2}
# ref = custom_param.ref
# if ref:
# provides[custom_name] = ref
#else:
keys
[
''
][
'columns'
][
name
]
=
{
'description'
:
obj
.
description
,
'type'
:
obj
.
type
}
ref
=
obj
.
ref
if
ref
:
provides
[
name
]
=
ref
#if param_type in message_def.customtype:
# customtype = message_def.customtype[param_type]
# key = name
# if customtype['type'] == 'Dict':
# for custom_name, custom_param in customtype['parameters'].items():
# param_type2 = custom_param['type']
# #if param_type2.startswith('[]'):
# # break
# #if param_type2 in ['Dict', 'File']:
# # break
# custom_descr = custom_param['description'].strip().rstrip()
# if param_type2 in message_def.customtype:
# keys[custom_name] = {'description': custom_descr,
# 'columns': {}}
# customtype2 = message_def.customtype[param_type2]
# for custom_name2, custom_param2 in customtype2['parameters'].items():
# keys[custom_name]['columns'][custom_name2] = {'description': custom_param2['description'].strip().rstrip(),
# 'type': param_type2}
# ref = custom_param2.get('ref')
# if ref:
# provides[custom_name2] = ref
# else:
# keys['']['columns'][custom_name] = {'description': custom_descr,
# 'type': param_type}
# ref = custom_param.get('ref')
# if ref:
# provides[custom_name] = ref
# else:
# continue
# break
# break
else
:
keys
[
''
][
'columns'
][
name
]
=
{
'description'
:
descr
,
'type'
:
obj
.
type
}
...
...
@@ -133,35 +194,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 +221,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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment