Commit 0e4d5b1a authored by Richard Mansfield's avatar Richard Mansfield

langpacks.sh: rewrite as perl and allow for repos to be defined in save file

parent c1c74fd3
......@@ -6,32 +6,34 @@ use POSIX qw(strftime ceil);
my $tarballs = $ARGV[0];
my $docroot = $ARGV[1];
my $lastlang = '0';
my @last = `find $tarballs -name "*.last"`;
my @table = ();
foreach my $last (sort @last) {
chomp $last;
if ($last =~ m{$tarballs/([a-z_]+)-([0-9A-Za-z\._]+)\.last}) {
my $lang = $1;
my $branch = $2;
my $commitinfo = `cat $last`;
my $l = '';
my $c = {};
if ( $lang ne $lastlang ) {
$l = $lang;
$c = { class => 'next' };
my $last;
my $savefile = "$tarballs/mahara-langpacks.last";
if ( -f $savefile ) {
eval(`cat $savefile`);
}
foreach my $lang (sort keys %{$last}) {
my $l = $lang;
my $c = { class => 'next' };
foreach my $branch (sort keys %{$last->{$lang}->{branches}}) {
my $status = [ \'span', { style => "color: #080" }, 'ok' ];
if ( $last->{$lang}->{branches}->{$branch}->{status} == -1 ) {
open $errorfh, '>', "$docroot/$lang-$branch-errors.txt";
print $errorfh $last->{$lang}->{branches}->{$branch}->{errors};
$status = [ \'a', { href => "$lang-$branch-errors.txt", style => "color: #a00;" }, 'errors' ];
}
my $errors = -f "$docroot/$lang-$branch-errors.txt";
push @table,
[ \'tr', $c,
[ \'td',
{ style => 'font-weight: bold;' }, $l, $branch,
{ style => 'font-weight: normal; color: #888;' }, [ \'tt', $commitinfo ],
$errors ? [ \'a', { href => "$lang-$branch-errors.txt", style => "color: #a00;" }, 'errors' ] : [ \'span', { style => "color: #080" }, 'ok' ]
{ style => 'font-weight: normal; color: #888;' }, [ \'tt', $last->{$lang}->{branches}->{$branch}->{commit} ],
$status
]
];
$lastlang = $lang;
$l = '';
$c = {};
}
}
......
#!/usr/bin/perl -w
# Copyright (C) 2010 Catalyst IT Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
use Data::Dumper;
use FindBin;
use File::Path qw(make_path remove_tree);
foreach my $c qw(DATA DOCROOT) {
exists $ENV{$c} or die ("\$ENV{$c} undefined");
}
my $DATA = $ENV{DATA};
my $DOCROOT = $ENV{DOCROOT};
my $CLEANCMD = "/usr/bin/php $FindBin::Bin/langpack.php";
my $SYNTAXCMD = "/usr/bin/php -l";
my $UTF8CMD = "/usr/bin/perl $FindBin::Bin/check-utf8.pl";
my $POCMD = "/usr/bin/perl $FindBin::Bin/po-php.pl";
my $GITDIR = "${DATA}/git";
my $DIRTY = "${DATA}/old";
my $CLEAN = "${DATA}/new";
my $TARBALLS = "${DATA}/tarballs";
make_path $GITDIR;
make_path $DIRTY;
make_path $CLEAN;
make_path $TARBALLS;
print STDERR "Checking langpacks for updates: " . `date \"+%Y-%m-%d %H:%M:%S\"`;
my @langs = qw(ar ca cs da de en_us es eu fi fr he it ja ko nl no_nb sl zh_tw);
my $last;
my $savefile = "$TARBALLS/mahara-langpacks.last";
if ( -f $savefile ) {
eval(`cat $savefile`);
}
else {
$last = {};
}
foreach my $lang (@langs) {
if ( ! defined $last->{$lang} ) {
$last->{$lang} = { repo => "git://gitorious.org/mahara-lang/$lang.git" };
}
my $remote = $last->{$lang}->{repo};
my $gitlangdir = "$GITDIR/$lang";
my $dirtylangdir = "$DIRTY/$lang";
my $cleanlangdir = "$CLEAN/$lang";
if ( ! -d $gitlangdir ) {
system "git clone --quiet $remote $gitlangdir";
}
make_path $dirtylangdir;
make_path $cleanlangdir;
chdir $gitlangdir;
system "git fetch --quiet";
my $remotebranchcmd = 'git branch -r | grep -v "HEAD" | grep "origin\/\(master\|1.2_STABLE\|1.3_STABLE\|1.4_STABLE\)$"';
my $remotebranches = `$remotebranchcmd`;
$remotebranches =~ s/\s+/ /;
foreach my $remotebranch (split(" ", $remotebranches)) {
my $remotecommitcmd = 'git log --pretty=format:"%H %ai %an" ' . $remotebranch . ' | head -1';
my $remotecommit = `$remotecommitcmd`;
chomp $remotecommit;
my $localbranch = $remotebranch;
$localbranch =~ s/^origin\///;
if ( ! defined $last->{$lang}->{branches}->{$localbranch} ) {
$last->{$lang}->{branches}->{$localbranch} = {};
}
my $filenamebase = "$lang-$localbranch";
my $tarball = "$TARBALLS/$filenamebase.tar.gz";
my $diff = "$TARBALLS/$filenamebase.diff";
-f $tarball && unlink $tarball;
-f $diff && unlink $diff;
my $lastruncommit = '';
if ( defined $last->{$lang}->{branches}->{$localbranch}->{commit} ) {
$lastruncommit = $last->{$lang}->{branches}->{$localbranch}->{commit};
}
if ( "$remotecommit" ne "$lastruncommit" ) {
print STDERR "Updating $lang $localbranch\n";
my $branchcmd = 'git branch | grep "' . $localbranch . '$"';
my $branchexists = `$branchcmd`;
if ( length $branchexists ) {
system "git checkout --quiet $localbranch";
system "git reset --hard -q $remotebranch";
} else {
system "git checkout --quiet -b $localbranch $remotebranch";
}
$last->{$lang}->{branches}->{$localbranch}->{status} = 0;
$last->{$lang}->{branches}->{$localbranch}->{errors} = '';
my $cleanbranchdir = "$cleanlangdir/$localbranch";
-d "$cleanbranchdir/lang" && remove_tree $cleanbranchdir;
! -d $cleanbranchdir && make_path $cleanbranchdir;
my $pofile = "$gitlangdir/mahara/$lang.po";
if ( -f $pofile ) {
print STDERR "$lang $localbranch: using .po file\n";
# Check utf8ness of .po file?
my $output = `$UTF8CMD $pofile`;
if ( length $output ) {
$last->{$lang}->{branches}->{$localbranch}->{errors} = "$pofile\n$output";
$last->{$lang}->{branches}->{$localbranch}->{status} = -1;
}
# Create langpack from .po file
my $pocmd = "$POCMD $pofile $cleanbranchdir \"$lang.utf8\"";
$output = `$pocmd`;
if ( length $output ) {
$last->{$lang}->{branches}->{$localbranch}->{errors} .= "Failed to create langpack from .po file $pofile\n";
$last->{$lang}->{branches}->{$localbranch}->{errors} .= "$output";
$last->{$lang}->{branches}->{$localbranch}->{status} = -1;
}
} else {
print STDERR "$lang $localbranch: sanitising\n";
# sanitise langpack
my $dirtybranchdir = "$dirtylangdir/$localbranch";
! -d $dirtybranchdir && make_path $dirtybranchdir;
system("cp -r $gitlangdir/" . '[a-z]* ' . $dirtybranchdir);
# Clean out stray php from the langpacks
system "$CLEANCMD $dirtybranchdir $cleanbranchdir";
chdir $DATA;
system "diff -Bwr $dirtybranchdir $cleanbranchdir > $diff";
# Check syntax of php files
chdir $cleanbranchdir;
my $phpfiles = `find . -name \"\*.php\"`;
foreach my $phpfile (split("\n", $phpfiles)) {
$phpfile =~ s/^\s*(\S.*\S)\s*$/$1/;
if ( $phpfile =~ m/php$/ ) {
my $output = `$SYNTAXCMD $phpfile >/dev/null`;
if ( length $output ) {
$last->{$lang}->{branches}->{$localbranch}->{errors} = "$phpfile\n$output";
$last->{$lang}->{branches}->{$localbranch}->{status} = -1;
}
}
}
my $allfiles = `find .`;
# Check utf8ness of all files
foreach my $file (split("\n", $allfiles)) {
$file =~ s/^\s*(\S.*\S)\s*$/$1/;
$output = `$UTF8CMD $file`;
if ( length $output ) {
$last->{$lang}->{branches}->{$localbranch}->{errors} .= "$file\n$output";
$last->{$lang}->{branches}->{$localbranch}->{status} = -1;
}
}
}
if ( $last->{$lang}->{branches}->{$localbranch}->{status} == 0 ) {
my $strip = $cleanbranchdir;
$strip =~ s{$/}{};
system "tar --transform \"s,$strip,$lang.utf8,\" -zcf $tarball $cleanbranchdir";
}
chdir $gitlangdir;
my $localcommit = `git log --pretty=format:\"%H %ai %an\" $localbranch | head -1`;
chomp $localcommit;
$last->{$lang}->{branches}->{$localbranch}->{commit} = $localcommit;
}
}
}
# Move new tarballs & log files to web directory
foreach my $file (split /\n/, `find $TARBALLS -name \"\*.tar.gz\"`) {
system "mv $file $DOCROOT";
}
foreach my $file (split /\n/, `find $TARBALLS -name \"\*.diff\"`) {
my $base = $file;
$base =~ s{^.*/([^/\s]+)\.diff\s*$}{$1};
system "mv $file $DOCROOT/$base-diff.txt";
}
# Generate index.html
system "/usr/bin/perl $FindBin::Bin/generate-index.pl $DOCROOT";
# Save latest commits
open $savefh, '>', $savefile;
print $savefh Data::Dumper->Dump([$last], ['last']);
# Generate status.html
system "/usr/bin/perl $FindBin::Bin/generate-status.pl $TARBALLS $DOCROOT";
print STDERR "Done.\n";
......@@ -23,11 +23,6 @@ DIRTY=${DATA}/old
CLEAN=${DATA}/new
TARBALLS=${DATA}/tarballs
CLEANCMD="/usr/bin/php ${SCRIPTS}/langpack.php"
SYNTAXCMD="/usr/bin/php -l"
UTF8CMD="/usr/bin/perl ${SCRIPTS}/check-utf8.pl"
POCMD="/usr/bin/perl ${SCRIPTS}/po-php.pl"
if [ ! -w ${DATA} ]; then
echo "${DATA} not writable"
exit 1
......@@ -37,173 +32,10 @@ if [ ! -w ${DOCROOT} ]; then
exit 1
fi
echo "Checking langpacks for updates: `date \"+%Y-%m-%d %H:%M:%S\"`"
[ ! -d ${GITDIR} ] && mkdir ${GITDIR}
[ ! -d ${DIRTY} ] && mkdir ${DIRTY}
[ ! -d ${CLEAN} ] && mkdir ${CLEAN}
[ ! -d ${TARBALLS} ] && mkdir ${TARBALLS}
langs="ar ca cs da de en_us es eu fi fr he it ja ko nl no_nb sl zh_tw"
for lang in ${langs} ; do
remote=${PROJDIR}/${lang}.git
gitlangdir=${GITDIR}/${lang}
dirtylangdir=${DIRTY}/${lang}
cleanlangdir=${CLEAN}/${lang}
if [ ! -d ${gitlangdir} ]; then
git clone --quiet ${remote} ${gitlangdir}
fi
[ ! -d ${dirtylangdir} ] && mkdir ${dirtylangdir}
[ ! -d ${cleanlangdir} ] && mkdir ${cleanlangdir}
cd ${gitlangdir}
git fetch --quiet
for remotebranch in `git branch -r | grep -v "HEAD" | grep "origin\/\(master\|1.2_STABLE\|1.3_STABLE\|1.4_STABLE\)$"`; do
remotecommit=`git log --pretty=format:"%H %ai %an" ${remotebranch} | head -1`
localbranch=${remotebranch##origin/}
filenamebase=${lang}-${localbranch}
log=${TARBALLS}/${filenamebase}.log
tarball=${TARBALLS}/${filenamebase}.tar.gz
diff=${TARBALLS}/${filenamebase}.diff
[ -f ${log} ] && rm ${log}
[ -f ${tarball} ] && rm ${tarball}
[ -f ${diff} ] && rm ${diff}
last=${TARBALLS}/${filenamebase}.last
lastruncommit=z
if [ -f ${last} ]; then
lastruncommit=`cat ${last}`
fi
if [ "$remotecommit" != "$lastruncommit" ] ; then
echo "Updating $lang $localbranch"
branchexists=`git branch | grep "${localbranch}$"`
if [ -z "${branchexists}" ]; then
git checkout --quiet -b ${localbranch} ${remotebranch}
else
git checkout --quiet ${localbranch}
git reset --hard -q ${remotebranch}
fi
errors=0
cleanbranchdir=${cleanlangdir}/${localbranch}
[ -d ${cleanbranchdir}/lang ] && rm -fr ${cleanbranchdir}
[ ! -d ${cleanbranchdir} ] && mkdir ${cleanbranchdir}
pofile="${gitlangdir}/mahara/${lang}.po"
if [ -f $pofile ] ; then
echo "$lang $localbranch: using .po file"
# Check utf8ness of .po file?
output=`${UTF8CMD} ${pofile}`
if [ $? -ne 0 ]; then
echo ${pofile} >> ${log}
echo -e "${output}" >> ${log}
errors=1
fi
# Create langpack from .po file
output=`${POCMD} $pofile $cleanbranchdir "${lang}.utf8"`
if [ $? -ne 0 ]; then
echo "Failed to create langpack from .po file ${pofile}" >> ${log}
echo ${pofile} >> ${log}
echo -e "${output}" >> ${log}
errors=1
fi
else
echo "$lang $localbranch: sanitising"
# sanitise langpack
dirtybranchdir=${dirtylangdir}/${localbranch}
[ ! -d ${dirtybranchdir} ] && mkdir ${dirtybranchdir}
cp -r ${gitlangdir}/[^\\.]* ${dirtybranchdir}
# Clean out stray php from the langpacks
${CLEANCMD} ${dirtybranchdir} ${cleanbranchdir}
cd ${DATA}
diff -Bwr ${dirtybranchdir} ${cleanbranchdir} > ${diff}
# Check syntax of php files
cd ${cleanbranchdir}
for file in `find . -name "*.php"`; do
output=`${SYNTAXCMD} $file`
if [ $? -ne 0 ]; then
echo ${file} >> ${log}
echo -e "${output}" >> ${log}
errors=1
fi
done
# Check utf8ness of all files
for file in `find .`; do
output=`${UTF8CMD} ${file}`
if [ $? -ne 0 ]; then
echo ${file} >> ${log}
echo -e "${output}" >> ${log}
errors=1
fi
done
fi
if [ $errors = 0 ]; then
strip=`echo ${cleanbranchdir} | sed 's,^/,,'`
tar --transform "s,${strip},${lang}.utf8," -zcf ${tarball} ${cleanbranchdir}
fi
cd ${gitlangdir}
localcommit=`git log --pretty=format:"%H %ai %an" ${localbranch} | head -1`
echo "${localcommit}" > ${last}
fi
done
done
# Move new tarballs & log files to web directory
for file in `find ${TARBALLS} -name "*.tar.gz"`; do
mv ${file} ${DOCROOT}
# Remove the old log file
base=${file##*/}
base=${base%.tar.gz}
[ -f ${DOCROOT}/${base}-errors.txt ] && rm ${DOCROOT}/${base}-errors.txt
done
for file in `find ${TARBALLS} -name "*.log"`; do
base=${file##*/}
base=${base%.log}
mv ${file} ${DOCROOT}/${base}-errors.txt
done
for file in `find ${TARBALLS} -name "*.diff"`; do
base=${file##*/}
base=${base%.diff}
mv ${file} ${DOCROOT}/${base}-diff.txt
done
# Generate index.html
/usr/bin/perl ${SCRIPTS}/generate-index.pl ${DOCROOT}
# Generate status.html
/usr/bin/perl ${SCRIPTS}/generate-status.pl ${TARBALLS} ${DOCROOT}
env DATA=$DATA DOCROOT=$DOCROOT /usr/bin/perl ${SCRIPTS}/langpacks.pl
echo "Done."
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