Skip to content

Commit

Permalink
Add simple Weblate screenshot uploader tool
Browse files Browse the repository at this point in the history
Uploads all page layout test results via Weblate's API.
  • Loading branch information
eloquence committed Aug 13, 2020
1 parent 172138e commit a49f06c
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

###########
#
Expand Down
58 changes: 58 additions & 0 deletions securedrop/bin/upload-screenshots
Original file line number Diff line number Diff line change
@@ -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."

0 comments on commit a49f06c

Please sign in to comment.