From a49f06c6b5f61d978a2feb39d8da12b96e1e47a7 Mon Sep 17 00:00:00 2001 From: Erik Moeller Date: Wed, 12 Aug 2020 17:36:55 -0700 Subject: [PATCH] Add simple Weblate screenshot uploader tool Uploads all page layout test results via Weblate's API. --- Makefile | 4 +++ securedrop/bin/upload-screenshots | 58 +++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100755 securedrop/bin/upload-screenshots diff --git a/Makefile b/Makefile index 9f784cb875..22d95e7779 100644 --- a/Makefile +++ b/Makefile @@ -310,6 +310,10 @@ update-user-guides: ## Run the page layout tests to regenerate screenshots. @$(DEVSHELL) $(SDBIN)/update-user-guides @echo +.PHONY: upload-screenshots +upload-screenshots: ## Upload all English language screenshots to Weblate. + $(SDBIN)/upload-screenshots + @echo ########### # diff --git a/securedrop/bin/upload-screenshots b/securedrop/bin/upload-screenshots new file mode 100755 index 0000000000..2253dd8ed7 --- /dev/null +++ b/securedrop/bin/upload-screenshots @@ -0,0 +1,58 @@ +#!/bin/bash +# +# A maintenance script for uploading all screenshots generated by the page +# layout tests to Weblate, to provide context for translators. Only the +# English language screenshots are uploaded. +# +# Currently this script does not perform checks for existing screenshots; +# it just blindly uploads the entire set of screenshots, which then have +# to be manually associated with the correct strings. + +# Standard shell safety settings +set -e +set -u +set -o pipefail + +if [ -z "${WEBLATE_BASE_URL:-}" ]; then + WEBLATE_BASE_URL="https://weblate.securedrop.org/" +fi + +if [ -z "${WEBLATE_API_KEY:-}" ]; then + echo "WEBLATE_API_KEY environment variable is not set. This script requires" + echo "an API key to be configured to perform file uploads. You can obtain" + echo "one via this link: ${WEBLATE_BASE_URL}accounts/profile/#api" + exit 1 +fi + +BASEDIR=$(dirname "$0") +FILES="$BASEDIR/../tests/pageslayout/screenshots/en_US/*.png" + +for file in $FILES +do + if [ ! -f "$file" ]; then + echo "Page layout test results not found. Run this command from the SecureDrop" + echo "base directory to generate the English language screenshots. This will" + echo "take several minutes." + echo + echo "LOCALES=en_US make translation-test" + exit 1 + fi + BASENAME=$(basename "$file") + # Generate more readable titles for use within Weblate. + # Example conversion: "source-session_timeout.png" -> "source: session timeout" + TITLE=$(echo "${BASENAME}" | sed -e "s/\.png//" | sed -e "s/-/: /g" | sed -e "s/_/ /g") + + echo "Uploading '${BASENAME}' to Weblate." + echo "API result:" + curl -w "\nHTTP code: %{http_code}\n" \ + -H "Authorization: Token ${WEBLATE_API_KEY}" \ + -F "image=@${file}" \ + -F "name=${TITLE}" \ + -F "project_slug=securedrop" \ + -F "component_slug=securedrop" \ + "${WEBLATE_BASE_URL}api/screenshots/" + echo + echo +done + +echo "Upload complete."