extra support

This commit is contained in:
Emmanuel Garette 2019-12-22 18:41:35 +01:00
parent 4de9bde691
commit 41af2512b5
3 changed files with 45 additions and 17 deletions

View File

@ -42,7 +42,8 @@ class Risotto(Controller):
release_cache: Dict) -> None:
as_names = []
dest_file = self.get_servermodel_cache(servermodel_id, 'funcs.py')
with open(dest_file, 'w') as funcs:
with open(dest_file, 'wb') as funcs:
funcs.write(b'from tiramisu import valid_network_netmask, valid_ip_netmask, valid_broadcast, valid_in_network, valid_not_equal as valid_differ, valid_not_equal, calc_value\n\n')
for applicationservice_id, applicationservice_infos in dependencies.items():
applicationservice_name, as_release_id = applicationservice_infos
path = join(self.source_root_path,
@ -54,9 +55,13 @@ class Risotto(Controller):
if isdir(path):
as_names.append(applicationservice_name)
for fil in listdir(path):
with open(join(path, fil), 'r') as fh:
funcs.write('# {}\n'.format(join(path, fil)))
funcs.write(fh.read() + '\n')
if not fil.endswith('.py'):
continue
fil_path = join(path, fil)
with open(fil_path, 'rb') as fh:
funcs.write(f'# {fil_path}\n'.encode())
funcs.write(fh.read())
funcs.write(b'\n')
as_names_str = '", "'.join(as_names)
log.info(_(f'gen funcs for "{servermodel_name}" with application services "{as_names_str}"'))
@ -68,9 +73,11 @@ class Risotto(Controller):
dependencies: Dict,
release_cache: Dict) -> None:
paths = []
as_names = []
extras = []
as_names = set()
for applicationservice_id, applicationservice_infos in dependencies.items():
applicationservice_name, as_release_id = applicationservice_infos
# load creole dictionaries
path = join(self.source_root_path,
release_cache[as_release_id]['source_name'],
release_cache[as_release_id]['release_name'],
@ -78,12 +85,29 @@ class Risotto(Controller):
applicationservice_name,
'dictionaries')
if isdir(path):
as_names.append(applicationservice_name)
as_names.add(applicationservice_name)
paths.append(path)
# load extra dictionaries
path = join(self.source_root_path,
release_cache[as_release_id]['source_name'],
release_cache[as_release_id]['release_name'],
'applicationservice',
applicationservice_name,
'extras')
if isdir(path):
for namespace in listdir(path):
extra_dir = join(path, namespace)
if not isdir(extra_dir):
continue
as_names.add(applicationservice_name)
extras.append((namespace, [extra_dir]))
eolobj = CreoleObjSpace(dtdfilename)
as_names_str = '", "'.join(as_names)
log.info(_(f'gen schema for "{servermodel_name}" with application services "{as_names_str}"'))
eolobj.create_or_populate_from_xml('creole', paths)
for extra in extras:
eolobj.create_or_populate_from_xml(extra[0], extra[1])
# FIXME extra
funcs_file = self.get_servermodel_cache(servermodel_id, 'funcs.py')
eolobj.space_visitor(funcs_file)

View File

@ -84,11 +84,12 @@ class Risotto(Controller):
# check if a session already exists
sessions = storage.get_sessions()
for session in sessions.values():
if sess['id'] == id:
if sess['username'] == risotto_context.username:
for sess_id, session in sessions.items():
if session['id'] == id:
if session['username'] == risotto_context.username:
# same user so returns it
return self.format_session(session['session_id'], session)
return self.format_session(sess_id,
session)
else:
raise Exception(_(f'{username} already edits this configuration'))
@ -157,11 +158,13 @@ class Risotto(Controller):
session_id,
type)
# if multi and not follower the value is in fact in value_multi
option = session['option'].option(name).option
# FIXME option = session['option'].option(name).option
option = session['config'].option(name).option
if option.ismulti() and not option.isfollower():
value = value_multi
namespace = session['namespace']
update = {'name': f'{namespace}.{name}',
#FIXME namespace = session['namespace']
#FIXME update = {'name': f'{namespace}.{name}',
update = {'name': name,
'action': action,
'value': value}
if index is not None:
@ -196,12 +199,13 @@ class Risotto(Controller):
mandatories = list(config.value.mandatory())
config.property.read_write()
if mandatories:
# FIXME mandatories = [mandatory.split('.', 1)[1] for mandatory in mandatories]
if len(mandatories) == 1:
mandatories = mandatories[0]
msg = _('the parameter "--{mandatories}" is mandatory')
msg = _(f'the parameter "--{mandatories}" is mandatory')
else:
mandatories = '", "--'.join(mandatories)
msg = _('parameters "{mandatories}" are mandatories')
msg = _(f'parameters "--{mandatories}" are mandatories')
raise Exception(msg)
return self.format_session(session_id,
session)
@ -219,7 +223,7 @@ class Risotto(Controller):
if name is not None:
info['content'] = {name: session['option'].option(name).value.get()}
else:
info['content'] = session['option'].value.dict()
info['content'] = session['option'].value.dict(fullpath=True)
return info
@register(['v1.session.server.stop', 'v1.session.servermodel.stop'], None)

View File

@ -97,7 +97,7 @@ class Storage(object):
session_id: int,
username: str) -> Dict:
if session_id not in self.sessions:
raise Exception(f'the session {session_id} not exists')
raise Exception(f'the session "{session_id}" not exists')
session = self.sessions[session_id]
if username != session['username']:
raise NotAllowedError()