-
Notifications
You must be signed in to change notification settings - Fork 689
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add simple Weblate screenshot uploader tool
Uploads all page layout test results via Weblate's API.
- Loading branch information
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." |