Commit 1ee1ee41 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Langpacks: move index.html generation into separate scripts

parent d5420001
......@@ -7,7 +7,7 @@ Standards-Version: 3.9.1
Package: custom-site-mahara-langpacks
Architecture: all
Depends: ${misc:Depends}, apache2, php5-cli, perl, bash, debconf, git-core
Depends: ${misc:Depends}, apache2, php5-cli, perl, bash, debconf, git-core, libhtml-tiny-perl
Description: Mahara langpack repository scripts
Scripts to download mahara langpacks from gitorious, clean them up, and
make them available for HTTP download.
#!/usr/bin/perl -w
use HTML::Tiny;
use POSIX qw(strftime ceil);
my $docroot = $ARGV[0];
my $lastlang = '0';
my @tarballs = `find $docroot -name "*.tar.gz"`;
my @table = ();
foreach my $tarball (sort @tarballs) {
chomp $tarball;
if ($tarball =~ m{$docroot/([a-z_]+)-([0-9A-Za-z\._]+)\.tar\.gz}) {
my $lang = $1;
my $branch = $2;
my @fileinfo = stat $tarball;
my $l = '';
my $c = {};
if ( $lang ne $lastlang ) {
$l = $lang;
$c = { class => 'next' };
}
push @table,
[ \'tr', $c,
[ \'td',
{ style => 'font-weight: bold;' }, $l,
[ \'a', { href => "$lang-$branch.tar.gz" }, "$lang-$branch.tar.gz" ],
{ style => 'font-weight: normal; color: #888;' },
strftime("%Y-%m-%d %H:%M:%S", localtime $fileinfo[9]), ceil($fileinfo[7] / 1024 - 0.5) . 'k'
]
];
$lastlang = $lang;
}
}
open(my $fh, '>', "$docroot/index.html") or die $!;
my $h = HTML::Tiny->new( mode => 'html' );
print $fh $h->html(
[
$h->head(
[
$h->title( 'Mahara Language Packs' ),
$h->style( 'td,th {padding:0 .5em;} tr.next td {border-top: 1px dotted #ccc;}' ),
]
),
$h->body(
[
$h->div( { style => "float: right; margin-right: 1em;" }, [ \'a', { href => 'status.html' }, 'Status' ] ),
$h->h3( 'Mahara Language Packs' ),
$h->table(\@table),
]
)
]
);
#!/usr/bin/perl -w
use HTML::Tiny;
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 $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' ]
]
];
$lastlang = $lang;
}
}
open(my $fh, '>', "$docroot/status.html") or die $!;
my $h = HTML::Tiny->new( mode => 'html' );
print $fh $h->html(
[
$h->head(
[
$h->title( 'Mahara Language Packs' ),
$h->style( 'td,th {padding:0 .5em;} tr.next td {border-top: 1px dotted #ccc;}' ),
]
),
$h->body(
[
$h->div( { style => "float: right; margin-right: 1em;" }, [ \'a', { href => 'index.html' }, 'Download' ] ),
$h->h3( 'Mahara Language Packs' ),
$h->table(\@table),
]
)
]
);
......@@ -170,54 +170,10 @@ for file in `find ${TARBALLS} -name "*.diff"`; do
mv ${file} ${DOCROOT}/${base}-diff.txt
done
index="<html><head><title>Mahara Language Packs</title><style>td,th {padding:0 .5em;} tr.next td {border-top: 1px dotted #ccc;}</style></head>"
index+="<body><h3>Mahara Language Packs</h3>"
index+="<table>"
index+="<thead>"
index+="<tr><th><th colspan=\"2\">Last good version</th><th>Last commit</th><th>Changes</th><th>Status</th></tr>"
index+="</thead>"
for file in `find ${TARBALLS} -name "*.last" | sort`; do
base=${file##*/}
base=${base%.last}
lang=${base%%-*}
index+="<tr"
if [ "${lang}" != "${lastlang}" ]; then
index+=" class=\"next\""
fi
index+=">"
index+="<td style=\"font-weight:bold;\">"
if [ "${lang}" != "${lastlang}" ]; then
index+="${lang}"
fi
index+="</td>"
index+="<td style=\"font-weight:bold; border-left: 1px dotted #ccc;\">"
if [ -f ${DOCROOT}/${base}.tar.gz ]; then
index+="<a href=\"${WWWROOT}/${base}.tar.gz\">${base}.tar.gz</a>"
fi
date=`stat -c "%y" ${DOCROOT}/${base}.tar.gz 2>/dev/null`
date=${date%% *}
index+="</td><td>${date}</td>"
last=`cat ${file}`
index+="<td style=\"color: #888; border-left: 1px dotted #ccc;\">${last#* }</td>"
diffsize=`stat -c "%s" ${DOCROOT}/${base}-diff.txt 2>/dev/null`
index+="<td style=\"text-align:center;\">"
if [ "${diffsize}" != '0' ] ; then
index+="<a href=\"${WWWROOT}/${base}-diff.txt\">diff</a>"
fi
index+="</td>"
if [ -f ${DOCROOT}/${base}-errors.txt ]; then
index+="<td style=\"text-align:center;\"><a style=\"color:#a00;\" href=\"${WWWROOT}/${base}-errors.txt\">errors</a></td>"
else
index+="<td style=\"text-align:center;color:#080;\">ok</td>"
fi
index+="</tr>"
lastlang=${lang}
done
index+="</table></body></html>"
# Generate index.html
/usr/bin/perl ${SCRIPTS}/generate-index.pl ${DOCROOT}
echo -e "${index}" > ${DOCROOT}/index.html
# Generate status.html
/usr/bin/perl ${SCRIPTS}/generate-status.pl ${TARBALLS} ${DOCROOT}
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