コード例 #1
0
def add_localization(api: ApiClient, locale, exercise_id, include_name):
    """
    Add (or update if exists) a localized text of an exercise. The text is read from the standard input.
    If includeName flag is set, the first line of the input is used as the name.
    """
    full_exercise = api.get_exercise(exercise_id)
    copy_props = ["version", "difficulty", "localizedTexts", "isPublic", "isLocked", "configurationType",
                  "solutionFilesLimit", "solutionFilesLimit", "solutionSizeLimit", "mergeJudgeLogs"]
    exercise = {}
    for prop in copy_props:
        exercise[prop] = full_exercise[prop]

    localizedText = next((lt for lt in exercise["localizedTexts"] if lt["locale"] == locale), None)
    if localizedText is None:
        localizedText = {
            "locale": locale,
            "name": "",
            "text": "",
            "link": "",
            "description": ""
        }
        exercise["localizedTexts"].append(localizedText)

    input_stream = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8')
    if include_name is True:
        localizedText["name"] = input_stream.readline().strip()

    localizedText["text"] = input_stream.read()
    api.update_exercise(exercise_id, exercise)
コード例 #2
0
def get(api: ApiClient, exercise_id, useJson):
    """
    Get exercise data and print it in JSON or Yaml.
    """
    exercise = api.get_exercise(exercise_id)
    if useJson:
        json.dump(exercise, sys.stdout, sort_keys=True, indent=4)
    else:
        yaml.dump(exercise, sys.stdout)