Commit 1bfa7996 authored by André Anjos's avatar André Anjos 💬

Merge branch '67_add_version_of_asset_to_data_sent' into 'master'

Add version of asset to data sent on push

Closes #67

See merge request !90
parents 31cb1621 5acca02d
Pipeline #38921 passed with stages
in 8 minutes and 4 seconds
......@@ -48,6 +48,8 @@ import six
import termcolor
import simplejson
from enum import Enum, unique
from beat.core import dataformat
from beat.core import database
from beat.core import library
......@@ -124,6 +126,19 @@ TYPE_PLURAL = {
}
@unique
class ModificationStatus(Enum):
"""This enum describes the state of possible changes between a local asset
and it's remote counter part"""
NO_CHANGES = ""
REMOTE_ONLY_AVAILABLE = "r"
LOCAL_ONLY_AVAILABLE = "l"
DOC_CHANGED = "d"
CONTENT_CHANGED = "+"
BOTH_CHANGED = "*"
def recursive_rmdir_if_empty(path, stop_at):
"""Recursively removes empty directories until a certain top directory"""
......@@ -1257,14 +1272,16 @@ def status(webapi, prefix, asset_type):
if contents:
if doc:
symbol = "*" # both contents and doc changed
symbol = (
ModificationStatus.BOTH_CHANGED
) # both contents and doc changed
else:
symbol = "+" # only contents changed
symbol = ModificationStatus.CONTENT_CHANGED # only contents changed
else:
if doc:
symbol = "d" # only docs changed
symbol = ModificationStatus.DOC_CHANGED # only docs changed
else:
symbol = "" # no changes
symbol = ModificationStatus.NO_CHANGES # no changes
if symbol:
logger.info(
......@@ -1282,7 +1299,7 @@ def status(webapi, prefix, asset_type):
# whatever is not listed remotely
for key in set(local) - set(remote.keys()):
logger.info("[l] %s/%s", TYPE_PLURAL[asset_type], key)
retval[key] = "l"
retval[key] = ModificationStatus.LOCAL_ONLY_AVAILABLE
# whatever is not listed locally
for key in set(remote.keys()) - set(local):
......@@ -1292,7 +1309,7 @@ def status(webapi, prefix, asset_type):
key,
remote[key]["creation_date"],
)
retval[key] = "r"
retval[key] = ModificationStatus.REMOTE_ONLY_AVAILABLE
return 0, retval
......@@ -1398,8 +1415,9 @@ def push(
return 0
# flush all final candidates
for asset_name, legend_symbol in candidates.items():
if legend_symbol == "r": # don't push what is available unmodified remotely
for asset_name, modification_status in candidates.items():
if modification_status == ModificationStatus.REMOTE_ONLY_AVAILABLE:
# don't push what is available unmodified remotely
continue
splits = asset_name.split("/")
......@@ -1412,7 +1430,10 @@ def push(
return 1
logger.info(
"pushing %s/%s [%s]", TYPE_PLURAL[asset_type], asset_name, legend_symbol
"pushing %s/%s [%s]",
TYPE_PLURAL[asset_type],
asset_name,
modification_status,
)
storage = TYPE_STORAGE[asset_type](prefix, asset_name)
data = storage.load() # returns a named tuple
......@@ -1445,10 +1466,18 @@ def push(
url = "/api/v1/%s/%s/" % (TYPE_PLURAL[asset_type], webapi.user)
# sends the data
if legend_symbol == "l": # POST (new object)
if (
modification_status == ModificationStatus.LOCAL_ONLY_AVAILABLE
): # POST (new object)
message["name"] = storage.name
version = getattr(storage, "version")
if version is not None:
message["version"] = version
if asset_type == "experiment":
message["toolchain"] = "/".join(splits[1:-1])
try:
webapi.post(url, data=message)
except RuntimeError as e:
......@@ -1460,7 +1489,7 @@ def push(
else: # PUT (update)
url += "/".join(splits[1:]) + "/"
if legend_symbol == "d":
if modification_status == ModificationStatus.DOC_CHANGED:
data = {"description": message["description"]}
else:
data = message
......
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