first commit

This commit is contained in:
2019-11-28 14:50:53 +01:00
commit 37499daccf
165 changed files with 4995 additions and 0 deletions

8
src/risotto/__init__.py Normal file
View File

@ -0,0 +1,8 @@
from .utils import undefined
from .dispatcher import register, dispatcher
from .http import get_app
# just to register every route
from . import services as _services
__ALL__ = ('undefined', 'register', 'dispatcher', 'get_app')

3
src/risotto/config.py Normal file
View File

@ -0,0 +1,3 @@
HTTP_PORT = 8080
MESSAGE_ROOT_PATH = 'messages'
DEBUG = True

3
src/risotto/context.py Normal file
View File

@ -0,0 +1,3 @@
class Context:
def __init__(self):
self.paths = []

View File

@ -0,0 +1,7 @@
from .dispatcher import dispatcher
class Controller:
async def call(self, uri, risotto_context, **kwargs):
version, uri = uri.split('.', 1)
return await dispatcher.call(version, uri, risotto_context, **kwargs)

178
src/risotto/dispatcher.py Normal file
View File

@ -0,0 +1,178 @@
from tiramisu import Config
from inspect import signature
from traceback import print_exc
from copy import copy
from .utils import undefined, _
from .error import RegistrationError, CallError, NotAllowedError
from .message import get_messages
from .logger import log
from .config import DEBUG
from .context import Context
def register(uri: str,
notification: str=undefined):
version, uri = uri.split('.', 1)
def decorator(function):
dispatcher.set_function(version, uri, function)
return decorator
class URI:
def __init__(self, ):
self.functions = {}
class Dispatcher:
def __init__(self):
self.modules = {}
self.uris = {}
self.function_names = {}
self.messages, self.option = get_messages()
config = Config(self.option)
def get_function_args(self, function):
# remove self
first_argument_index = 1
return [param.name for param in list(signature(function).parameters.values())[first_argument_index:]]
def _valid_rpc_params(self, version, uri, function, module_name):
""" parameters function must have strictly all arguments with the correct name
"""
def get_message_args():
# load config
config = Config(self.option)
config.property.read_write()
# set message to the uri name
config.option('message').value.set(uri)
# get message argument
subconfig = config.option(uri)
return set(config.option(uri).value.dict().keys())
# compare message arguments with function parameter
# it must not have more or less arguments
message_args = get_message_args()
function_args = self.get_function_args(function)
# risotto_context is a special argument, remove it
if function_args[0] == 'risotto_context':
function_args = function_args[1:]
function_args = set(function_args)
if message_args != function_args:
msg = []
missing_function_args = message_args - function_args
if missing_function_args:
msg.append(_(f'missing arguments: {missing_function_args}'))
extra_function_args = function_args - message_args
if extra_function_args:
msg.append(_(f'extra arguments: {extra_function_args}'))
function_name = function.__name__
msg = _(' and ').join(msg)
raise RegistrationError(_(f'error with {module_name}.{function_name} arguments: {msg}'))
def set_function(self, version, uri, function):
""" register a function to an URI
URI is a message
"""
# xxx module can only be register with v1.xxxx..... message
module_name = function.__module__.split('.')[-2]
uri_namespace = uri.split('.', 1)[0]
if uri_namespace != module_name:
raise RegistrationError(_(f'cannot registered to {uri} message in module {module_name}'))
# check if message exists
try:
if not Config(self.option).option(uri).option.type() == 'message':
raise RegistrationError(_(f'{uri} is not a valid message'))
except AttributeError:
raise RegistrationError(_(f'{uri} is not a valid message'))
# check if a function is already register for this uri
if version not in self.uris:
self.uris[version] = {}
self.function_names[version] = {}
if uri in self.uris[version]:
raise RegistrationError(_(f'uri {uri} already imported'))
# valid function's arguements
self._valid_rpc_params(version, uri, function, module_name)
# valid function is unique per module
if module_name not in self.function_names[version]:
self.function_names[version][module_name] = []
function_name = function.__name__
if function_name in self.function_names[version][module_name]:
raise RegistrationError(_(f'multiple registration of {module_name}.{function_name} function'))
self.function_names[version][module_name].append(function_name)
# True if first argument is the risotto_context
inject_risotto_context = self.get_function_args(function)[0] == 'risotto_context'
# register this function
self.uris[version][uri] = {'module': module_name,
'function': function,
'risotto_context': inject_risotto_context}
def set_module(self, module_name, module):
""" register a new module
"""
try:
self.modules[module_name] = module.Risotto()
except AttributeError as err:
raise RegistrationError(_(f'unable to register the module {module_name}, this module must have Risotto class'))
def validate(self):
""" check if all messages have a function
"""
# FIXME only v1 supported
missing_messages = set(self.messages.keys()) - set(self.uris['v1'].keys())
if missing_messages:
raise RegistrationError(_(f'missing uri {missing_messages}'))
async def call(self, version, uri, risotto_context, public_only=False, **kwargs):
""" execute the function associate with specified uri
arguments are validate before
"""
new_context = Context()
new_context.paths = copy(risotto_context.paths)
new_context.paths.append(version + '.' + uri)
new_context.username = risotto_context.username
if public_only and not self.messages[uri]:
raise NotAllowedError()
try:
config = Config(self.option)
config.property.read_write()
config.option('message').value.set(uri)
subconfig = config.option(uri)
for key, value in kwargs.items():
try:
subconfig.option(key).value.set(value)
except ValueError as err:
raise ValueError(str(err))
except AttributeError:
raise AttributeError(_(f'unknown parameter "{key}"'))
config.property.read_only()
mandatories = list(config.value.mandatory())
if mandatories:
mand = [mand.split('.')[-1] for mand in mandatories]
raise ValueError(_(f'missing parameters: {mand}'))
obj = self.uris[version][uri]
kw = config.option(uri).value.dict()
if obj['risotto_context']:
kw['risotto_context'] = new_context
returns = await obj['function'](self.modules[obj['module']], **kw)
except CallError as err:
raise err
except Exception as err:
if DEBUG:
print_exc()
log.error_msg(version, uri, new_context, kwargs, err)
raise CallError(str(err))
log.info_msg(version, uri, new_context, kwargs, returns)
return returns
dispatcher = Dispatcher()

10
src/risotto/error.py Normal file
View File

@ -0,0 +1,10 @@
class RegistrationError(Exception):
pass
class CallError(Exception):
pass
class NotAllowedError(Exception):
pass

41
src/risotto/http.py Normal file
View File

@ -0,0 +1,41 @@
from aiohttp.web import Application, Response, get, HTTPBadRequest, HTTPInternalServerError, HTTPNotFound
from .dispatcher import dispatcher
from .utils import _
from .context import Context
from .error import CallError, NotAllowedError
async def handle(request):
version, uri = request.match_info.get_info()['path'].split('/', 2)[-2:]
context = Context()
context.username = request.match_info.get('name', "Anonymous")
try:
text = await dispatcher.call(version, uri, context, id=2, public_only=True)
except NotAllowedError as err:
raise HTTPNotFound(reason=_(f'the message {version}.{uri} is private'))
except CallError as err:
raise HTTPBadRequest(reason=str(err))
except Exception as err:
raise HTTPInternalServerError(reason=str(err))
return Response(text=str(text))
def get_app():
app = Application()
routes = []
uris = list(dispatcher.uris.items())
uris.sort()
for version, uris in dispatcher.uris.items():
print()
print(_('======== Registered messages ========'))
for uri in uris:
web_uri = f'/{version}/{uri}'
if dispatcher.messages[uri]:
print(f' - {web_uri}')
else:
print(f' - {web_uri} (private)')
routes.append(get(web_uri, handle))
print()
app.add_routes(routes)
return app

23
src/risotto/logger.py Normal file
View File

@ -0,0 +1,23 @@
from .utils import _
class Logger:
def _get_message_paths(self, risotto_context):
paths = risotto_context.paths
if len(paths) == 1:
paths_msg = f'messages called: {paths[0]}'
else:
paths_msg = f'sub-messages called: '
paths_msg += ' > '.join(paths)
return paths_msg
def error_msg(self, version, message, risotto_context, arguments, error):
paths_msg = self._get_message_paths(risotto_context)
print(_(f'{risotto_context.username}: {error} ({paths_msg} with arguments "{arguments}")'))
def info_msg(self, version, message, risotto_context, arguments, returns):
paths_msg = self._get_message_paths(risotto_context)
print(_(f'{risotto_context.username}: {paths_msg} with arguments "{arguments}" returns {returns}'))
log = Logger()

View File

@ -0,0 +1 @@
from .message import get_messages

View File

@ -0,0 +1,610 @@
from collections import OrderedDict
from os.path import join, basename, dirname
from glob import glob
from tiramisu import StrOption, IntOption, BoolOption, ChoiceOption, OptionDescription, SymLinkOption, \
Config, Calculation, Params, ParamOption, ParamValue, calc_value, calc_value_property_help, \
groups
from yaml import load, SafeLoader
from os import listdir
from os.path import isfile
from ..config import MESSAGE_ROOT_PATH
from ..utils import _
groups.addgroup('message')
class MessageDefinition:
"""
A MessageDefinition is a representation of a message in the Zephir application messaging context
"""
__slots__ = ('version',
'uri',
'description',
'sampleuse',
'domain',
'parameters',
'public',
'errors',
'pattern',
'related',
'response')
def __init__(self, raw_def):
# default value for non mandatory key
self.version = u''
self.parameters = OrderedDict()
self.public = False
self.errors = []
self.related = []
self.response = None
self.sampleuse = None
# loads yaml information into object
for key, value in raw_def.items():
if isinstance(value, str):
value = value.strip()
if key == 'public':
if not isinstance(value, bool):
raise ValueError(_("{} must be a boolean, not {}").format(key, value))
elif key == 'pattern':
if value not in ['rpc', 'event', 'error']:
raise Exception(_('unknown pattern {}').format(value))
elif key == 'parameters':
if 'type' in value and isinstance(value['type'], str):
# should be a customtype
value = customtypes[value['type']].properties
else:
value = _parse_parameters(value)
elif key == 'response':
value = ResponseDefinition(value)
elif key == 'errors':
value = _parse_error_definition(value)
setattr(self, key, value)
# check mandatory keys
for key in self.__slots__:
try:
getattr(self, key)
except AttributeError:
raise Exception(_('mandatory key not set {} message').format(key))
# message with pattern = error must be public
if self.public is False and self.pattern == 'error':
raise Exception(_('Error message must be public : {}').format(self.uri))
class ParameterDefinition:
__slots__ = ('name',
'type',
'description',
'help',
'default',
'ref',
'shortarg')
def __init__(self, name, raw_def):
self.name = name
# default value for non mandatory key
self.help = None
self.ref = None
self.shortarg = None
# loads yaml information into object
for key, value in raw_def.items():
if isinstance(value, str):
value = value.strip()
if key == 'type':
if value.startswith('[]'):
tvalue = value[2:]
else:
tvalue = value
if tvalue in customtypes:
if value.startswith('[]'):
value = '[]{}'.format(customtypes[tvalue].type)
else:
value = customtypes[value].type
else:
self._valid_type(value)
#self._valid_type(value)
setattr(self, key, value)
# check mandatory keys
for key in self.__slots__:
try:
getattr(self, key)
except AttributeError:
if key != 'default':
raise Exception(_('mandatory key not set "{}" in parameter').format(key))
def _valid_type(self, typ):
if typ.startswith('[]'):
self._valid_type(typ[2:])
elif typ not in ['Boolean', 'String', 'Number', 'File', 'Dict', 'Any']:
raise Exception(_('unknown parameter type: {}').format(typ))
class ResponseDefinition:
"""
An ResponseDefinition is a representation of a response in the Zephir application messaging context
"""
__slots__ = ('description',
'type',
'ref',
'parameters',
'required')
def __init__(self, responses):
self.ref = None
self.parameters = None
self.required = []
for key, value in responses.items():
if key in ['parameters', 'required']:
raise Exception(_('parameters and required must be set with a custom type'))
elif key == 'type':
if value.startswith('[]'):
tvalue = value[2:]
else:
tvalue = value
if tvalue in customtypes:
self.parameters = customtypes[tvalue].properties
self.required = customtypes[tvalue].required
if value.startswith('[]'):
value = '[]{}'.format(customtypes[tvalue].type)
else:
value = customtypes[value].type
else:
self._valid_type(value)
setattr(self, key, value)
# check mandatory keys
for key in self.__slots__:
try:
getattr(self, key)
except AttributeError:
raise Exception(_('mandatory key not set {}').format(key))
def _valid_type(self, typ):
if typ.startswith('[]'):
self._valid_type(typ[2:])
elif typ not in ['Boolean', 'String', 'Number', 'File', 'Dict']:
raise Exception(_('unknown parameter type: {}').format(typ))
class ErrorDefinition:
"""
An ErrorDefinition is a representation of an error in the Zephir application messaging context
"""
__slots__ = ('uri',)
def __init__(self, raw_err):
extra_keys = set(raw_err) - set(self.__slots__)
if extra_keys:
raise Exception(_('extra keys for errors: {}').format(extra_keys))
self.uri = raw_err['uri']
def _parse_error_definition(raw_defs):
new_value = []
for raw_err in raw_defs:
new_value.append(ErrorDefinition(raw_err))
return new_value
def _parse_parameters(raw_defs):
parameters = OrderedDict()
for name, raw_def in raw_defs.items():
parameters[name] = ParameterDefinition(name, raw_def)
return parameters
def parse_definition(filename: str):
return MessageDefinition(load(filename, Loader=SafeLoader))
def is_message_defined(uri):
version, message = split_message_uri(uri)
path = get_message_file_path(version, message)
return isfile(path)
def get_message(uri):
load_customtypes()
try:
version, message = split_message_uri(uri)
path = get_message_file_path(version, message)
with open(path, "r") as message_file:
message_content = parse_definition(message_file.read())
message_content.version = version
return message_content
except Exception as err:
import traceback
traceback.print_exc()
raise Exception(_('cannot parse message {}: {}').format(uri, str(err)))
def split_message_uri(uri):
return uri.split('.', 1)
def get_message_file_path(version, message):
return join(MESSAGE_ROOT_PATH, version, 'messages', message + '.yml')
def list_messages():
messages = listdir(MESSAGE_ROOT_PATH)
messages.sort()
for version in messages:
for message in listdir(join(MESSAGE_ROOT_PATH, version, 'messages')):
if message.endswith('.yml'):
yield version + '.' + message.rsplit('.', 1)[0]
class CustomParam:
__slots__ = ('name',
'type',
'description',
'ref',
'default')
def __init__(self, name, raw_def, required):
self.name = name
self.ref = None
if name not in required:
self.default = None
# loads yaml information into object
for key, value in raw_def.items():
if isinstance(value, str):
value = value.strip()
if key == 'type':
value = self._convert_type(value, raw_def)
elif key == 'items':
continue
setattr(self, key, value)
# check mandatory keys
for key in self.__slots__:
try:
getattr(self, key)
except AttributeError:
# default value for non mandatory key
if key != 'default':
raise Exception(_('mandatory key not set "{}" in parameter').format(key))
def _convert_type(self, typ, raw_def):
types = {'boolean': 'Boolean',
'string': 'String',
'number': 'Number',
'object': 'Dict',
'array': 'Array',
'file': 'File'}
if typ not in list(types.keys()):
# validate after
return typ
if typ == 'array' and 'items' in raw_def:
if not isinstance(raw_def['items'], dict):
raise Exception(_('items must be a dict'))
if list(raw_def['items'].keys()) != ['type']:
raise Exception(_('items must be a dict with only a type'))
return '[]{}'.format(self._convert_type(raw_def['items']['type'], raw_def))
return types[typ]
def _parse_custom_params(raw_defs, required):
parameters = OrderedDict()
for name, raw_def in raw_defs.items():
parameters[name] = CustomParam(name, raw_def, required)
return parameters
class CustomType:
__slots__ = ('title',
'type',
'description',
'ref',
'properties',
'required')
def __init__(self, raw_def):
# default value for non mandatory key
self.ref = None
# loads yaml information into object
for key, value in raw_def.items():
if isinstance(value, str):
value = value.strip()
if key == 'type':
value = self._convert_type(value, raw_def)
elif key == 'properties':
value = _parse_custom_params(value, raw_def.get('required', {}))
setattr(self, key, value)
# check mandatory keys
for key in self.__slots__:
try:
getattr(self, key)
except AttributeError:
raise Exception(_('mandatory key not set "{}" in parameter').format(key))
def _convert_type(self, typ, raw_def):
types = {'boolean': 'Boolean',
'string': 'String',
'number': 'Number',
'object': 'Dict',
'array': 'Array'}
if typ not in list(types.keys()):
# validate after
return typ
if typ == 'array' and 'items' in raw_def:
if not isinstance(raw_def['items'], dict):
raise Exception(_('items must be a dict'))
if list(raw_def['items'].keys()) != ['type']:
raise Exception(_('items must be a dict with only a type'))
return '[]{}'.format(self._convert_type(raw_def['items']['type'], raw_def))
return types[typ]
def getname(self):
return self.title
customtypes = {}
def load_customtypes():
if not customtypes:
versions = listdir(MESSAGE_ROOT_PATH)
versions.sort()
for version in versions:
for message in listdir(join(MESSAGE_ROOT_PATH, version, 'types')):
if message.endswith('.yml'):
path = join(MESSAGE_ROOT_PATH, version, 'types', message)
message = message.rsplit('.', 1)[0]
with open(path, "r") as message_file:
try:
ret = CustomType(load(message_file, Loader=SafeLoader))
customtypes[ret.getname()] = ret
except Exception as err:
import traceback
traceback.print_exc()
raise Exception('{} for {}'.format(err, message))
for customtype in customtypes.values():
properties = {}
for key, value in customtype.properties.items():
type_ = value.type
if type_.startswith('[]'):
ttype_ = type_[2:]
else:
ttype_ = type_
if ttype_ in customtypes:
if type_.startswith('[]'):
raise Exception(_('cannot have []CustomType'))
properties[key] = customtypes[ttype_]
else:
properties[key] = value
customtype.properties = properties
def _get_description(description,
name):
# hack because some description are, in fact some help
if not '\n' in description and len(description) <= 150:
doc = description
else:
doc = name
if doc.endswith('.'):
doc= description[:-1]
return doc
def _get_option(name,
arg,
file_path,
select_option,
optiondescription):
"""generate option
"""
props = []
if not hasattr(arg, 'default'):
props.append('mandatory')
props.append(Calculation(calc_value,
Params(ParamValue('disabled'),
kwargs={'condition': ParamOption(select_option, todict=True),
'expected': ParamValue(optiondescription),
'reverse_condition': ParamValue(True)}),
calc_value_property_help))
description = arg.description.strip().rstrip()
kwargs = {'name': name,
'doc': _get_description(description, name),
'properties': frozenset(props),
#'multi': arg.multi,
}
if hasattr(arg, 'default'):
kwargs['default'] = arg.default
type_ = arg.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)
elif type_ == 'Boolean':
return BoolOption(**kwargs)
raise Exception('unsupported type {} in {}'.format(type_, file_path))
def _parse_args(message_def,
options,
file_path,
needs,
select_option,
optiondescription,
load_shortarg):
"""build option with args/kwargs
"""
new_options = OrderedDict()
for name, arg in message_def.parameters.items():
new_options[name] = arg
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, select_option, optiondescription)
options.append(current_opt)
if arg.shortarg and load_shortarg:
options.append(SymLinkOption(arg.shortarg, current_opt))
def _parse_responses(message_def,
file_path):
"""build option with returns
"""
responses = OrderedDict()
if message_def.response:
keys = {'': {'description': '',
'columns': {}}}
provides = {}
to_list = True
param_type = message_def.response.type
if param_type.startswith('[]'):
to_list = False
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}
ref = obj.ref
if ref:
provides[name] = ref
else:
keys['']['columns'][name] = {'description': descr,
'type': obj.type}
ref = obj.ref
if ref:
provides[name] = ref
responses['keys'] = keys
responses['to_list'] = to_list
responses['to_dict'] = False
responses['provides'] = provides
else:
name = 'response'
keys['']['columns'][name] = {'description': message_def.response.description,
'type': message_def.response.type}
ref = message_def.response.ref
if ref:
provides[name] = ref
responses['keys'] = keys
responses['to_list'] = to_list
responses['to_dict'] = True
responses['provides'] = provides
return responses
def _getoptions_from_yml(message_def,
version,
optiondescriptions,
file_path,
needs,
select_option,
load_shortarg):
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:
print('rpc without response?: {}'.format(file_path))
options = []
# options = [StrOption('version',
# 'version',
# version,
# properties=frozenset(['hidden']))]
_parse_args(message_def, options, file_path, needs, select_option, message_def.uri, load_shortarg)
name = message_def.uri
description = message_def.description.strip().rstrip()
optiondescriptions[name] = (description, options)
def _get_root_option(select_option, optiondescriptions):
"""get root option
"""
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
od = OptionDescription(name,
description,
_get_od(curr_ods[name]))
if None in list(curr_ods[name].keys()):
od.impl_set_group_type(groups.message)
options.append(od)
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)
def get_messages(load_shortarg=False, only_public=False):
"""generate description from yml files
"""
optiondescriptions = OrderedDict()
optiondescriptions_name = []
optiondescriptions_info = {}
responses = OrderedDict()
needs = OrderedDict()
messages = list(list_messages())
messages.sort()
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 only_public):
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 only_public):
continue
optiondescriptions_info[message_def.uri] = message_def.public
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,
select_option,
load_shortarg)
responses[message_def.uri] = _parse_responses(message_def,
message_name)
root = _get_root_option(select_option, optiondescriptions)
try:
config = Config(root)
except Exception as err:
raise Exception('error when generating root optiondescription: {}'.format(err))
config.property.read_write()
# config.property.add('demoting_error_warning')
# return needs, responses, config
return optiondescriptions_info, root

View File

@ -0,0 +1,18 @@
from os import listdir
from os.path import isdir, isfile, dirname, abspath, basename, join
from importlib import import_module
from ..dispatcher import dispatcher
def list_import():
abs_here = dirname(abspath(__file__))
here = basename(abs_here)
module = basename(dirname(abs_here))
for filename in listdir(abs_here):
absfilename = join(abs_here, filename)
if isdir(absfilename) and isfile(join(absfilename, '__init__.py')):
dispatcher.set_module(filename, import_module(f'.{here}.{filename}', module))
dispatcher.validate()
list_import()

View File

@ -0,0 +1 @@
from .config import Risotto

View File

@ -0,0 +1,25 @@
from ...controller import Controller
from ...dispatcher import register
class Risotto(Controller):
# @register('v1.config.created')
async def server_created(self, serverid, servername, servermodelid):
print('pouet')
@register('v1.config.session.server.start', None)
async def get_configuration(self, risotto_context, id):
stop = await self.call('v1.config.session.server.stop', risotto_context, sessionid=str(id))
return {'start': id}
@register('v1.config.session.server.stop', None)
async def get_configuration2(self, sessionid, save):
return {'stop': sessionid}
@register('v1.config.configuration.server.get', None)
async def get_configuration3(self, server_id, deploy):
return {'get': server_id}
@register('v1.config.configuration.server.deploy', None)
async def get_configuration4(self, server_id):
return {'deploy': server_id}

9
src/risotto/utils.py Normal file
View File

@ -0,0 +1,9 @@
class Undefined:
pass
def _(s):
return s
undefined = Undefined()