[Debian-l10n-commits] [SCM] Debian i18n - l10n development - dl10n robots branch, master, updated. 6c9b7fb4ba0d7fe5ad071eda63c540b0a9148b9d

Simon Paillard spaillard at debian.org
Sun Jun 17 09:52:31 UTC 2012


The following commit has been merged in the master branch:
commit 6c9b7fb4ba0d7fe5ad071eda63c540b0a9148b9d
Author: Simon Paillard <spaillard at debian.org>
Date:   Sun Jun 17 09:51:16 2012 +0000

    dl10n-nmu: add parameters and catch open errors

diff --git a/cron/nmu-update b/cron/nmu-update
index c403fe9..45cbc3c 100755
--- a/cron/nmu-update
+++ b/cron/nmu-update
@@ -2,22 +2,29 @@
 
 set -e
 
-DL10NDIR=/srv/dl10n-stuff/svn/dl10n
-LOGDIR=/srv/dl10n-stuff/log
-LOGPREFIX=$LOGDIR/dl10n-nmu.cron.$(date "+%Y%m%d-%H%M")
-OUTDIR=/srv/i18n.debian.net/www/debian-l10n-coordination/l10n-nmu/
+I18NROOT=/srv/i18n.debian.org/
+DL10NDIR=$I18NROOT/dl10n/git
+LOGDIR=$I18NROOT/log/l10n-nmu
+LOGPREFIX=$LOGDIR/dl10n-nmu.$(date "+%Y%m%d-%H%M")
+OUTDIR=$I18NROOT/htdocs/l10n-nmu
+STAT_DATABASE=$I18NROOT/htdocs/material/data/unstable.gz
+TMPDIR=$I18NROOT/tmp
+POPCON_FILE=$TMPDIR/by_inst
 
 cd $DL10NDIR
 
 umask 0002
 
-rm -f data/by_inst
-wget -P data -o /dev/null http://popcon.debian.org/source/by_inst || {
+wget -O $POPCON_FILE -o /dev/null http://popcon.debian.org/source/by_inst || {
 	echo "Failed to download http://popcon.debian.org/source/by_inst"
 	exit 1
 }
 
-PERLLIB=lib ./dl10n-nmu > $LOGPREFIX.log 2> $LOGPREFIX.err
+PERLLIB=lib ./dl10n-nmu		\
+	--db "$STAT_DATABASE"	\
+	--gendir "$OUTDIR"	\
+	--popcon "$POPCON_FILE"	\
+		> $LOGPREFIX.log 2> $LOGPREFIX.err
 
 cat $LOGPREFIX.err
 chgrp debian-i18n-users $LOGPREFIX.log $LOGPREFIX.err
diff --git a/dl10n-nmu b/dl10n-nmu
index f33e79f..1055779 100755
--- a/dl10n-nmu
+++ b/dl10n-nmu
@@ -12,14 +12,59 @@
 
 use strict;
 
+use Getopt::Long; #to parse the args
 use Debian::L10n::Db;
 use SOAP::Lite;
 use POSIX qw(strftime);
 my $generation_date = strftime('%a, %d %b %Y %H:%M:%S %z', gmtime);
 
-# TODO: add an option
+my $progname= $0; $progname= $& if $progname =~ m,[^/]+$,;
+
 my $DB_FILE="/srv/i18n.debian.net/www/debian-l10n-material/data/unstable.gz";
 my $POPCON="./data/by_inst";
+my $GENDIR ;
+
+sub syntax_msg {
+    my $msg = shift;
+    if (defined $msg) {
+        print "$progname: $msg\n";
+    }
+    print 
+"Syntax: $0 [options]
+General options:
+    -h, --help                display short help text
+    -V, --version             display version and exit
+
+Database to use:
+    --db=DB_FILE              use DB_FILE as database file
+                                (instead of $DB_FILE)
+    --popcon=POPCON           location of by_inst popcon file
+    --gendir                  Generate the files in this directory
+";
+    if (defined $msg) {
+        exit 1;
+    } else {
+        exit 0;
+    }
+}
+
+# Hash used to process commandline options
+my %opthash = (
+# ------------------ general options
+        "help|h"        => \&syntax_msg,
+# ------------------ configuration options
+        "db=s"          => \$DB_FILE,
+        "popcon=s"      => \$POPCON,
+        "gendir=s"      => \$GENDIR,
+        );
+
+# init commandline parser
+Getopt::Long::config('bundling', 'no_getopt_compat', 'no_auto_abbrev');
+
+# process commandline options
+GetOptions(%opthash)
+    or syntax_msg("error parsing options");
+
 
 print "Read the database...";
 my $data = Debian::L10n::Db->new();
@@ -44,7 +89,7 @@ print "done.\n";
 
 my $pop = {};
 
-open (POPCON, $POPCON);
+open (POPCON, $POPCON) or die "Can't open popconf by_inst file from $POPCON";
 while (my $line = <POPCON>) {
   if ($line =~ /^(\d+)\s+(\S+)\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+$/) {
     $pop->{$2} = (2 - $1 / 10000);
@@ -146,7 +191,7 @@ foreach my $pkg (keys %$packages) {
 #TODO: refactor printing code
 #printing stuffs
 ###BY PACKAGE
-open (FILE, ">html/nmu_bypackage.html");
+open (FILE, ">$GENDIR/html/nmu_bypackage.html") or die;
 print FILE "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
 print FILE "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"fr\">\n";
 print FILE "<head>\n";
@@ -160,7 +205,7 @@ print FILE "<img src=\"score.png\" alt=\"Score calculation formula\" />";
 print FILE "  <table summary=\"rank of packages\">\n";
 print FILE "    <tr><td>Package</td><td>Score</td><td>L10n bugs</td><td>Maintainer</td><td>Comment</td></tr>\n";
 
-open (DATABASE, ">data/status.nmu");
+open (DATABASE, ">$GENDIR/data/status.nmu") or die;
 foreach my $pkg (sort { $packages->{$b}->{score} <=> $packages->{$a}->{score} } keys %$packages) {
   next if ($packages->{$pkg}->{score} == 0);
   print DATABASE "Package: $pkg\n";
@@ -209,7 +254,7 @@ print FILE "</html>\n";
 close (FILE);
 
 ###BY MAINTAINER
-open (FILE, ">html/nmu_maintainer.html");
+open (FILE, ">$GENDIR/html/nmu_maintainer.html") or die;
 print FILE "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
 print FILE "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"fr\">\n";
 print FILE "<head>\n";

-- 
Debian i18n - l10n development - dl10n robots



More information about the Debian-l10n-commits mailing list