diff --git a/tools/langstats b/tools/langstats new file mode 100755 index 0000000000000000000000000000000000000000..3621f5a6381d18026e475cc948fedce72d3db356 --- /dev/null +++ b/tools/langstats @@ -0,0 +1,112 @@ +#!/usr/bin/perl -w +# langstats - count of lists by language setting +# taggart 2012-10-26 + +use Getopt::Std; +$Getopt::Std::STANDARD_HELP_VERSION='true'; + +use vars qw($opt_c $opt_w $opt_s $opt_d $small $smalllim $medium $mediumlim $large $largelim $debug $date); +# want to have warning and critical levels eventually + +getopts('wh'); + +sub HELP_MESSAGE { + print "Usage: langstats\n"; + print " -w : use redcloth/greencloth wiki output\n"; + print " -h : use html output\n"; +} + +# enable debug to use local test data +#$debug='true'; + +# the number of top counts to display +$count = 15; +$i=0; + +$date=`date`; +chomp($date); + +if ( $debug ) { + $listdir='./expl'; +} else { + $listdir='/home/sympa/expl'; +} + +# get list of open lists +$sql='mysql -N --batch --database=sympa --execute "select name_list from list_table where status_list = \'open\'"'; + +open(LISTS, "$sql|") or die "cannot get list names from database\n"; + +while (<LISTS>) { + chomp; + + $config = "$listdir/$_/config"; + + # if a list's config file doesn't exist, skip it + if ( ! -f $config ) { + next + } + + open(CONFIG,"grep ^lang $config|") || die "ERROR: cannot open $config\n"; + $line =<CONFIG>; + if ($line) { + $line =~ s/^lang (.*)$/$1/; + #print $line; + $lang{$line}++; + } else { + $lang{'(none)'}++; + } + close CONFIG; + +} + +# set format, print header +if ( $opt_h ) { + $~='Html'; + print "<style>table.single{border: 1px solid;border-collapse: collapse;}\n.single td, .single th{border-width: 1px 1px 1px 1px;border-style: solid;}\n</style>\n"; + print "<h3>Top $count Languages by list count</h3>\n\n"; + print "(generated ".$date.")<br>\n"; + print "<table class=\"single\">\n"; + print "<tr><th>Language</th><th align=right>List Count</th></tr>\n"; +} elsif ( $opt_w ) { + $~='Wiki'; + print "h3. Top $count Languages by list count\n\n"; + print "(generated ".$date.")\n\n"; + print "|_.Language|_.List Count|\n"; +} else { + $~='Plain'; + print "Top $count Languages by list count\n"; + print "(generated ".$date.")\n\n"; + print "Language List Count\n"; + print "======================\n"; +} + +# now display the results +foreach $key ( sort { $lang{$b} <=> $lang{$a} } keys %lang ) { + last if ( $i > $count ); + $i++; + write; +} + +# footer +if ( $opt_h ) { + print "</table>\n"; +} + +exit 0; + + +format Wiki = +|@<<<<<<<<<|>.@>>>>>>>>>| +$key, $lang{$key} +. + +format Plain = +@<<< @>>>>>>> +$key, $lang{$key} +. + +format Html = +<tr><td>@*</td><td align=right>@*</td></tr> + $key, $lang{$key} +.