pjs/webtools/tinderbox/buildwho.pl

135 строки
3.3 KiB
Perl
Исходник Обычный вид История

1998-06-17 01:43:24 +04:00
#!/usr/bonsaitools/bin/perl --
# -*- Mode: perl; indent-tabs-mode: nil -*-
#
1999-11-02 02:33:56 +03:00
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
1998-06-17 01:43:24 +04:00
#
1999-11-02 02:33:56 +03:00
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
1998-06-17 01:43:24 +04:00
#
# The Original Code is the Tinderbox build tool.
#
# The Initial Developer of the Original Code is Netscape Communications
1999-11-02 02:33:56 +03:00
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
1998-06-17 01:43:24 +04:00
use FileHandle;
use File::Copy 'move';
use Fcntl qw(:DEFAULT :flock);
1998-06-17 01:43:24 +04:00
use lib "../bonsai";
require 'tbglobals.pl';
1998-06-17 01:43:24 +04:00
$F_DEBUG=1;
# Process args:
# $days: How many days of data to process.
# $tree: Which tree to use.
my ($days, $tree) = process_args();
1998-06-17 01:43:24 +04:00
# Only allow one process at a time to re-write "who.dat".
#
my $lock = lock_datafile($tree);
1998-06-17 01:43:24 +04:00
# Grab globals for this tree:
# $cvs_module: The checkout module
2001-03-26 03:53:37 +04:00
# $cvs_branch: The current branch
# $cvs_root: The path to the cvs root
# $bonsai_tree: The data directory for this tree in ../bonsai
#
1998-06-17 01:43:24 +04:00
require "$tree/treedata.pl";
# Setup global variables for bonsai query
#
if ($cvs_root eq '') {
1998-06-17 01:43:24 +04:00
$CVS_ROOT = '/m/src';
} else {
1998-06-17 01:43:24 +04:00
$CVS_ROOT = $cvs_root;
}
$CVS_REPOS_SUFIX = $CVS_ROOT;
$CVS_REPOS_SUFIX =~ s/\//_/g;
$CHECKIN_DATA_FILE = "/d/webdocs/projects/bonsai/data/checkinlog${CVS_REPOS_SUFIX}";
$CHECKIN_INDEX_FILE = "/d/webdocs/projects/bonsai/data/index${CVS_REPOS_SUFIX}";
require 'cvsquery.pl';
print "cvsroot='$CVS_ROOT'\n" if $F_DEBUG;
1998-06-17 01:43:24 +04:00
build_who($tree);
1998-06-17 01:43:24 +04:00
unlock_datafile($lock);
1998-06-17 01:43:24 +04:00
# End of main
##################################################################
sub process_args {
my ($days, $tree);
if ($ARGV[0] eq '-days') {
($days, $tree) = @ARGV[1,2];
} else {
($days, $tree) = (2, $ARGV[0]);
}
return $days, $tree;
}
1998-06-17 01:43:24 +04:00
sub lock_datafile {
my ($tree) = @_;
1998-06-17 01:43:24 +04:00
my $lock_fh = new FileHandle ">>$tree/buildwho.sem"
2001-03-26 03:53:37 +04:00
or die "Couldn't open semaphore file!";
1998-06-17 01:43:24 +04:00
# Get an exclusive lock with a non-blocking request
unless (flock($lock_fh, LOCK_EX|LOCK_NB)) {
die "buildwho.pl: Lock unavailable: $!";
1998-06-17 01:43:24 +04:00
}
return $lock_fh;
}
sub unlock_datafile {
my ($lock_fh) = @_;
flock $lock_fh, LOCK_UN; # Free the lock
close $lock_fh;
}
sub build_who {
my ($tree) = @_;
$query_date_min = time - (60 * 60 * 24 * $days);
print "Minimum date: $query_date_min\n" if $F_DEBUG;
1998-06-17 01:43:24 +04:00
2001-03-26 03:53:37 +04:00
$query_module=$cvs_module;
$query_branch=$cvs_branch;
my $who_file = "$tree/who.dat";
my $temp_who_file = "$who_file.$$";
open(WHOLOG, ">$temp_who_file");
chdir "../bonsai";
$::TreeID = $bonsai_tree;
2001-03-26 03:53:37 +04:00
my $result = &query_checkins(%mod_map);
1998-06-17 01:43:24 +04:00
2001-03-26 03:53:37 +04:00
$last_who='';
$last_date=0;
for $ci (@$result) {
if ($ci->[$CI_DATE] != $last_date or $ci->[$CI_WHO] ne $last_who) {
print WHOLOG "$ci->[$CI_DATE]|$ci->[$CI_WHO]\n";
1998-06-17 01:43:24 +04:00
}
2001-03-26 03:53:37 +04:00
$last_who=$ci->[$CI_WHO];
$last_date=$ci->[$CI_DATE];
1998-06-17 01:43:24 +04:00
}
close (WHOLOG);
chdir "../tinderbox";
move($temp_who_file, $who_file);
1998-06-17 01:43:24 +04:00
}