Commit 96b7395b authored by Samuel GAIST's avatar Samuel GAIST

[protocoltemplates] Add implementation for pull protocol templates

This is a step towards adding online support to the
command but is currently there to allow handling
of V2 version of the Database object.
parent 8fdd379c
......@@ -38,7 +38,10 @@ import logging
import click
from beat.core import protocoltemplate
from . import commands
from . import common
from .click_helper import AliasedGroup
from .click_helper import AssetCommand
from .click_helper import AssetInfo
......@@ -62,3 +65,74 @@ def protocoltemplates(ctx):
CMD_LIST = ["list", "path", "edit", "check", "create", "version", ("rm", "rm_local")]
commands.initialise_asset_commands(protocoltemplates, CMD_LIST, ProtocolTemplateCommand)
def pull_impl(webapi, prefix, names, force, indentation, cache):
"""Copies protocol template from the server
Parameters:
webapi (object): An instance of our WebAPI class, prepared to access the
BEAT server of interest
prefix (str): A string representing the root of the path in which the user
objects are stored
names (:py:class:`list`): A list of strings, each representing the unique
relative path of the objects to retrieve or a list of usernames from
which to retrieve objects. If the list is empty, then we pull all
available objects of a given type. If no user is set, then pull all
public objects of a given type.
force (bool): If set to ``True``, then overwrites local changes with the
remotely retrieved copies.
indentation (int): The indentation level, useful if this function is called
recursively while downloading different object types. This is normally
set to ``0`` (zero).
Returns:
int: Indicating the exit status of the command, to be reported back to the
calling process. This value should be zero if everything works OK,
otherwise, different than zero (POSIX compliance).
"""
from .dataformats import pull_impl as dataformats_pull
protocoltemplates = set(names)
if not protocoltemplates:
return 0
status, downloaded = common.pull(
webapi,
prefix,
"protocoltemplate",
protocoltemplates,
["declaration", "description"],
force,
indentation,
)
if status != 0:
return status
if indentation == 0:
indentation = 4
# see what else one needs to pull
dataformats = set()
for name in protocoltemplates:
try:
obj = protocoltemplate.ProtocolTemplate(prefix, name)
dataformats |= obj.dataformats.keys()
except Exception as e:
logger.error("loading `%s': %s...", name, str(e))
cache[name] = None
df_status = dataformats_pull(
webapi, prefix, dataformats, force, indentation + 2, cache
)
return status + df_status
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