Commit c578694a authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[utils][commands][install] Install protocoltemplates

parent 25d3882e
......@@ -71,6 +71,7 @@ import beat.core.dataformat
import beat.core.experiment
import beat.core.library
import beat.core.plotter
import beat.core.protocoltemplate
import beat.core.toolchain
logger = logging.getLogger(__name__)
......@@ -275,6 +276,79 @@ def upload_dataformat(prefix, name, data):
return True
def upload_protocoltemplate(prefix, name, data, new_only=False):
"""Uploads the protocol template to the platform
prefix (str): The prefix where the object template is sitting
name (str): The canonical name of the object
data (dict): A dictionary with template substitutions
bool: Indicates if the operation was successful
storage = beat.core.protocoltemplate.Storage(prefix, name)
if not storage.exists():
return False # should be ignored
declaration = detemplatize(storage.json.load(), data)
obj = simplejson.loads(declaration, object_pairs_hook=collections.OrderedDict)
description = storage.doc.load() if storage.doc.exists() else ""
if "root_folder" in data:
obj["root_folder"] = data["root_folder"]
declaration = simplejson.dumps(obj, indent=4)
from ....common.models import Shareable
from ....protocoltemplates.models import ProtocolTemplate
protocol_template = ProtocolTemplate.objects.filter(, version=int(storage.version)
if not protocol_template:
(protocol_template, errors) = ProtocolTemplate.objects.create_protocoltemplate(,
short_description=obj.get("description", ""),
if protocol_template is None:
logger.warn("Did not add template protocol `%s', because: %s", name, errors)
return False
else:"Added template protocol `%s'", protocol_template)
elif new_only:
return True
else: # only updates files
protocol_template = protocol_template[0]
protocol_template.short_description = obj.get("description", "")
protocol_template.declaration = declaration
protocol_template.description = description"Updated protocol template `%s'", protocol_template)
if not data["private"]:
protocol_template.sharing = Shareable.PUBLIC"Set protocol template `%s' as public", protocol_template)
return True
def load_database_folders(filename):
"""Simply loads the json file describing the database root folders
......@@ -874,6 +948,7 @@ def upload_dispatcher(prefix, project, type, name, data):
valid_types = {
"dataformats": upload_dataformat,
"protocoltemplates": upload_protocoltemplate,
"databases": upload_database,
"libraries": upload_library,
"algorithms": upload_algorithm,
......@@ -973,6 +1048,15 @@ def install_contributions(source_prefix, project, template_data, db_root_file=No
# Template protocols
from ....protocoltemplates.models import ProtocolTemplate
for object_ in list_objects(source_prefix, project, "protocoltemplates", "*.json"):
source_prefix, project, "protocoltemplates", object_, template_data
# Reads database root file, if provided
db_root = {}
if db_root_file:
Supports Markdown
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