Commit e0591a9e authored by Samuel GAIST's avatar Samuel GAIST

[common] Fix handling of remote available assets

parent 40c858f8
......@@ -1341,6 +1341,7 @@ def status(webapi, prefix, asset_type):
key,
remote[key]["creation_date"],
)
retval[key] = "r"
return 0, retval
......@@ -1406,6 +1407,10 @@ def push(
logger.error("cannot anonymously push objects, set your access token")
return 1
if webapi.user is None:
logger.error("Invalid user, stopping.")
return 1
retval, candidates = status(webapi, prefix, asset_type)
if retval:
return retval
......@@ -1443,16 +1448,17 @@ def push(
# flush all final candidates
for asset_name, legend_symbol in candidates.items():
if legend_symbol == "r": # don't push what is available unmodified remotely
continue
splits = asset_name.split("/")
if webapi.user is None and len(splits) >= 3: # excludes databases
# set-up user using the object's leading path
webapi.user = splits[0]
logger.debug(
"The command-line option for the user was not set, "
"so I'm overriding it with the object's leading path (`%s')",
webapi.user,
if splits[0] != webapi.user:
logger.error(
"Can't push asset {} not owned by user {}".format(
asset_name, webapi.user
)
)
return 1
logger.info(
"pushing %s/%s [%s]", TYPE_PLURAL[asset_type], asset_name, legend_symbol
......@@ -1485,11 +1491,7 @@ def push(
if dry_run:
continue # don't send the data
# if the user was set on the commandline, use it
if webapi.user is None:
url = "/api/v1/%s/" % (TYPE_PLURAL[asset_type],)
else:
url = "/api/v1/%s/%s/" % (TYPE_PLURAL[asset_type], webapi.user)
url = "/api/v1/%s/%s/" % (TYPE_PLURAL[asset_type], webapi.user)
# sends the data
if legend_symbol == "l": # POST (new object)
......@@ -1506,8 +1508,14 @@ def push(
else: # PUT (update)
url += "/".join(splits[1:]) + "/"
if legend_symbol == "d":
data = {"description": message["description"]}
else:
data = message
try:
webapi.put(url, data=message)
webapi.put(url, data=data)
except RuntimeError as e:
logger.error(e)
return 1
......
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