# SPDX-License-Identifier: AGPL-3.0-or-later
# Copyright (C) 2021 Andrew Rechnitzer
# Copyright (C) 2021-2022 Colin B. Macdonald
from pathlib import Path
from plom.solutions import with_manager_messenger
solution_path = Path("solutionImages")
[docs]@with_manager_messenger
def putSolutionImage(question, version, imageName, *, msgr):
"""Push a solution image to a server.
Args:
question (int):
version (int):
imageName (str/pathlib.Path):
Keyword Args:
msgr (plom.Messenger/tuple): either a connected Messenger or a
tuple appropriate for credientials.
Returns:
`[True, msg]` or `[False, msg]` where `msg` is either an
error message (on failure) or a diagnostic message (on success).
"""
spec = msgr.get_spec()
# nb question,version are strings at this point
iq = int(question)
iv = int(version)
if iq < 1 or iq > spec["numberOfQuestions"]:
return [False, "Question number out of range"]
if iv < 1 or iv > spec["numberOfVersions"]:
return [False, "Version number out of range"]
if spec["question"][question]["select"] == "fix" and iv != 1:
return [False, f"Question{question} has fixed version = 1"]
msgr.putSolutionImage(question, version, imageName)
return [True, f"Solution for {question}.{version} uploaded"]