Commit 107adf3e authored by Sandro Knauß's avatar Sandro Knauß
Browse files

[weblate] save-suggestions: Add commandline arguments

* Set the repo to work with as argument
* add verbose flag, so we see logging in the console
* rename subprocessOutputToLogger->log_subprocess_output
parent eba0a7f6
#!/usr/bin/env python3
# This script generates a temporary copy of all translations including suggestions.
# TMPDIR - the directory where the temporary copy is located.
# We have created TMPDIR manually, by git cloning locally.
# We have created a local git clone before running this script.
# It takes the default branch to work on.
#
# Usage:
#
# /var/lib/weblate/scripts/save-suggestions.py repopath
import argparse
import logging
import logging.config
import os
import pathlib
import subprocess
import sys
......@@ -23,7 +25,6 @@ application = get_wsgi_application()
from weblate.trans import models
TMPDIR = "/var/lib/weblate/repositories/vcs/staging/"
logging.config.fileConfig('/var/lib/weblate/config/saveSuggestions.conf')
......@@ -32,7 +33,8 @@ logger = logging.getLogger('saveSuggestions')
logger.info("Start a new run.")
def subprocessOutputToLogger(cmd, **kwargs):
def log_subprocess_output(cmd, **kwargs):
"""Add subprocess output to logger."""
logger.info("Running command '%s':", " ".join(cmd))
popen = subprocess.Popen(cmd, universal_newlines=True,
stdout=subprocess.PIPE,
......@@ -62,11 +64,30 @@ def update_unit(translation, unit, target):
def commandline():
parser = argparse.ArgumentParser()
parser.add_argument(
"-v", "--verbose",
action='store_true',
help="verbose logging.")
parser.add_argument(
"repopath",
type=pathlib.Path,
help="path to the repository.")
args = parser.parse_args()
prog = parser.prog
if args.verbose:
for handler in logging.getLogger().handlers:
if isinstance(handler, logging.StreamHandler):
handler.level = logging.DEBUG
repopath = args.repopath
try:
subprocessOutputToLogger(["git", "clean", "-fd"], cwd=TMPDIR)
subprocessOutputToLogger(["git", "fetch"], cwd=TMPDIR)
subprocessOutputToLogger(["git", "reset", 'FETCH_HEAD', "--hard"],
cwd=TMPDIR)
log_subprocess_output(["git", "clean", "-fd"], cwd=str(repopath))
log_subprocess_output(["git", "fetch"], cwd=str(repopath))
log_subprocess_output(["git", "reset", 'FETCH_HEAD', "--hard"],
cwd=str(repopath))
except:
logger.exception("Got an exception")
raise
......@@ -95,13 +116,12 @@ def commandline():
# save with suggestions
if changed:
with open(TMPDIR+"/"+translation.filename, "wb") as f:
with (repopath/translation.filename).open("wb") as f:
translation.store.store.serialize(f)
except:
logger.exception("Got an exception for %s(%i)", subproject.name, i)
raise
logger.info("Successfully updated %s.", TMPDIR)
logger.info("Successfully updated %s.", repopath)
if __name__ == "__main__":
commandline()
......@@ -7,13 +7,14 @@ set -e
set -u
STAGING_WEB_DIR=/var/www/staging
STAGING_REPO_DIR=/var/lib/weblate/repositories/vcs/staging
SANITY_CHECK_LOGFILE_BASENAME=last-sanity-errors.txt
SANITY_CHECK_LOGFILE="${STAGING_WEB_DIR}/${SANITY_CHECK_LOGFILE_BASENAME}"
IKIWIKI_LOGFILE=/var/log/weblate/update-staging-website_ikiwiki.log
/var/lib/weblate/scripts/save-suggestions.py
/var/lib/weblate/scripts/save-suggestions.py "$STAGING_REPO_DIR"
cd /var/lib/weblate/repositories/vcs/staging
cd "STAGING_REPO_DIR"
# Note: cron ignores the exit code so on errors, we print a message to
# STDERR, which cron will then send over email
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment