From 9f8d1b3a220102e97efb1af487b74818160b73eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Fr=C3=B6hlich?= Date: Sun, 21 Oct 2018 23:36:58 +0200 Subject: [PATCH] Added tool scripts --- tools/do_backup | 26 ++++++++ tools/export_translation | 134 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 160 insertions(+) create mode 100644 tools/do_backup create mode 100644 tools/export_translation diff --git a/tools/do_backup b/tools/do_backup new file mode 100644 index 0000000..758c8dd --- /dev/null +++ b/tools/do_backup @@ -0,0 +1,26 @@ +#!/bin/sh +DUMPDIR=/home/ted/dumps +rm $DUMPDIR/dump.9.gz +mv $DUMPDIR/dump.8.gz $DUMPDIR/dump.9.gz +mv $DUMPDIR/dump.7.gz $DUMPDIR/dump.8.gz +mv $DUMPDIR/dump.6.gz $DUMPDIR/dump.7.gz +mv $DUMPDIR/dump.5.gz $DUMPDIR/dump.6.gz +mv $DUMPDIR/dump.4.gz $DUMPDIR/dump.5.gz +mv $DUMPDIR/dump.3.gz $DUMPDIR/dump.4.gz +mv $DUMPDIR/dump.2.gz $DUMPDIR/dump.3.gz +mv $DUMPDIR/dump.1.gz $DUMPDIR/dump.2.gz +mv $DUMPDIR/dump.last.gz $DUMPDIR/dump.1.gz +# No encryption necessary on testserver... +#sqldump --user=cats_user --password= cats_db | gpg -r 0x7AFB8D26 -r 0xED30077A --batch --encrypt > $DUMPDIR/dump.last.gpg +mysqldump --user=cats_user --password= cats_db | gzip > $DUMPDIR/dump.last.gz +#cp $DUMPDIR/dump.last.gz /var/www/cats1.it-sls.de/training/public/dump.gz + +# Fetch backup of the production database +rm $DUMPDIR/dump.in.pgp 2>/dev/null +wget -o $DUMPDIR/dump.pgp.log -O $DUMPDIR/dump.in.pgp http://cats.cacert.org/backup.pgp + +if test -s $DUMPDIR/dump.in.pgp ; then + rm $DUMPDIR/dump.pgp + mv $DUMPDIR/dump.in.pgp $DUMPDIR/dump.pgp +fi + diff --git a/tools/export_translation b/tools/export_translation new file mode 100644 index 0000000..ee49102 --- /dev/null +++ b/tools/export_translation @@ -0,0 +1,134 @@ +#!/usr/bin/perl +# This is an experimental tool script to create a nice HTML page from the CATS database to help translating +# a test into another language and to review the result. +# Adjust the test id of the language you want to translate into (look for $sth_q->execute), probably modify +# the header of the page, then start the script with the database password as parameter. + +use strict; +use DBI; + + +sub PrintHeader { +print <<'ENDHEADER'; + + + + + + + + + + + +
+

Translation Sheet for CATS Test CZ

+

Please verify that the translation conserves the intention of the english text. It does not + have to be a word-by-word translation. Links may be adjusted to point to translated content, + if available.

+

The grayed out questions are currently disabled, so they won't be shown and translating them + is purely optional. Don't worry about true/false answers, those are translated automatically + by CATS.

+

Forward information about typos and bad language to the translator. Normally such issues + should not block publication of the translation, unless the mistakes are quite serious.

+

Note: The lines of english and translated answers do not necessarily match, since + the link between the answers was only recently implemented...

+
+ENDHEADER +} + +sub PrintFooter { +print <<'ENDFOOTER'; + + +ENDFOOTER +} + +my $dsn="DBI:mysql:database=cats_db"; +my $dbh = DBI->connect($dsn, "cats_user", $ARGV[0]); + +PrintHeader(); + +my $sth_aen = $dbh->prepare( + "SELECT a_en.a_id IDEN, a_en.answer TEXTEN ". + " FROM answers a_en". + " WHERE a_en.q_id=?". + " ORDER BY a_en.a_id" +); +my $sth_alg = $dbh->prepare( + "SELECT a_lg.a_id IDLG, a_lg.answer TEXTLG, a_lg.ref_a_id REF ". + " FROM answers a_lg". + " WHERE a_lg.q_id=?". + " ORDER BY a_lg.ref_a_id" +); + +my $sth_q = $dbh->prepare( + "SELECT q_en.q_id IDEN, q_lg.q_id IDLG, q_en.question Q_EN, q_lg.question Q_LG, ". + " qd_en.description DESCEN, qd_lg.description DESCLG, ". + " q_en.active ACTIVEEN, q_lg.active ACTIVELG ". + " FROM questions q_lg left outer join questions q_en on (q_en.q_id=q_lg.ref_q_id) ". + " LEFT OUTER JOIN question_description qd_en ON (qd_en.q_id=q_en.q_id) ". + " LEFT OUTER JOIN question_description qd_lg ON (qd_lg.q_id=q_lg.q_id) ". + " WHERE q_lg.t_id=? ". + " ORDER BY q_en.q_id"); +$sth_q->execute(9); # for language cz +#$sth_q->execute(5); # for language fr +while(my $ref = $sth_q->fetchrow_hashref()) { + print '
'."\n"; + print "
{ACTIVEEN} != 1 || $ref->{ACTIVELG} != 1); + print "\">
$ref->{Q_EN}
$ref->{Q_LG}
\n"; + print "
{ACTIVEEN} != 1 || $ref->{ACTIVELG} != 1); + print "\">
$ref->{DESCEN}
$ref->{DESCLG}
\n"; + $sth_aen->execute($ref->{IDEN}); + $sth_alg->execute($ref->{IDLG}); + while(my $ref2 = $sth_aen->fetchrow_hashref()) { + my $ref3 = $sth_alg->fetchrow_hashref(); + print "
{ACTIVEEN} != 1 || $ref->{ACTIVELG} != 1); + print "\">"; + print "
$ref2->{IDEN}
$ref2->{TEXTEN}
"; + print "
$ref3->{IDLG}($ref3->{REF})
$ref3->{TEXTLG}
"; + print "
\n"; + } + print "
\n"; +} + +PrintFooter();