#!/usr/bin/perl # $Id: cvsstat.pl,v 1.5 2000/01/23 18:03:31 baba Exp $ # Copyright (C) 1999 Webmasters of www.linux.or.jp. All rights reserved. # ################################################################ $from="CVS Admin "; $mailto="maillist\@foo.co.jp"; $module="www"; $pserver=":pserver:user\@foo.co.jp:/$module"; $grep = "/bin/grep"; $cvs = "/usr/bin/cvs"; $nkf = "/usr/bin/nkf"; $sendmail = "/usr/sbin/sendmail"; ################################################################ sub parse_args { $today=`date`; chop($today); if ($ARGV[0] =~ /daily/) { $begindate=`date --date '1 day ago'`; $period = "1 日間"; } elsif ($ARGV[0] =~ /weekly/) { $begindate=`date --date '7 days ago'`; $period = "1 週間"; } elsif ($ARGV[0] =~ /monthly/) { $begindate=`date --date '1 month ago'`; $period = "1 ヶ月間"; } else { $ARGV[0] = "weekly"; $begindate=`date --date '7 days ago'`; $period = "1 週間"; } chop($begindate); } sub parse_history_and_diff { local($cmd)="$cvs -d $pserver history -a -c -D '$begindate'"; open(CMD, "$cmd | $grep ' $module' |") || die; @stdin = ; close(CMD); foreach (@stdin) { local($mark, $date, $time, $tz, $committer, $revision, $file, $repository, $hoge, $remote) = split(); if (! $n{$committer}) { push(@committers, $committer); } $n{$committer} ++; local($tmpfile) = "$repository/$file"; if (! $n{$tmpfile}) { push(@files, $tmpfile); } $n{$tmpfile} ++; } $ncommitter=$#committers+1; $nfile=$#files+1; $nline=$#stdin+1; foreach (sort @committers) { $committer_table .= sprintf " %8s: %4d\n", $_, $n{$_}; } foreach (sort @files) { if ($n{$_} >= 2) { $file_table .= sprintf " %8s: %4d\n", $_, $n{$_}; } } } sub mail_notification { open(MAIL, "| $nkf -j | $sendmail -odb -oem -t") || die; select(MAIL); print << "_EOM_"; To: $mailto From: $from Subject: $ARGV[0] cvs report for $today (このメールは、cron によって自動的に投稿されるものです。) これは $module リポジトリに対する CVS commit 状況の集計です。 $begindate から $today までの $period に、 計 $ncommitter 人の committer が、計 $nfile のファイルに対して、 のべ $nline 回の変更 (add/commit/merge など) を行ないました。 committer ごとの集計結果は以下の通りです (数字は commit 回数)。 $committer_table また、2 回以上変更の加えられたファイルの一覧です。 $file_table 作業ご苦労様でした。これからもどしどし commit して下さいませ。 _EOM_ ; close(MAIL); } sub main { &parse_args(); &parse_history_and_diff(); if ($nline > 0) { &mail_notification(); } } # go! &main(); exit 0; __END__ NAME cvsstat.pl - リポジトリの動作状況報告用 cron スクリプト SYNOPSIS cvsstat.pl [daily|weekly|monthly] OPTIONS daily, weekly, monthly のいずれかを引数に取れる。 引数なしの場合は weekly 相当。 DESCRIPTIONS 1 週間に 1 度、cron にて起動する。 cvs コマンドを実行するので、オンライン状態であること。 FILES CVS リポジトリ ($pserver), grep, cvs, sendmail, nkf BUGS PSERVER 経由の場合、cron を実行するユーザの ~/.cvspass が あることを確認。なかったら途中で止まってしまうはず。 [EOF]