#!/usr/bin/perl -w # require 5.0; use strict; # Configuration Variables # p4 command - requires a user with super access. my $p4 = "C:\\Progra~1\\Perforce\\p4 -p localhost:1666 -u -P "; # filename used for temporary storage of change descriptions. my $Scratchfile = "update"; # group name for "authorised updaters". my $upgroup = "CDupdate"; # This subroutine assumes that the input job # is an addendum. The caller must check this. sub process_job { my @job = @_; my $Job; # Required data from the job my $User; my $Date; my $Chnum; my @changedesc; my $validaddendum = 0; my $fieldcounter = 0; # need 4 more valid fields - count them ( # we know that the type field is # addendum as that's assured by the caller, # so that order in the form doesn't matter. foreach (@job) { # step through job description if (!$validaddendum) { # Gather data until we're sure # this is a valid addendum chomp ($_); if ($_) { my @fields = split; if (($fields[0]) && ($fields[0] eq "Job:")) { $Job = $fields[1]; $fieldcounter++; } if (($fields[0]) && ($fields[0] eq "User:")) { $User = $fields[1]; $fieldcounter++; } if (($fields[0]) && ($fields[0] eq "Date:")) { $Date = join (" ", $fields[1], $fields[2]); $fieldcounter++; } if (($fields[0]) && ($fields[0] eq "ChangeNumber:")){ if ($fields[1]) { $Chnum = $fields[1]; $fieldcounter++; } else { return -1; # change num missing - abandon. } } if ($fieldcounter == 4) { @changedesc = `$p4 change -o $Chnum`; open (UPDATE, ">$Scratchfile"); print UPDATE @changedesc; print UPDATE "\tAppended by $User on $Date:\n"; $fieldcounter++; # don't repeat this step. } if (($fields[0]) && ($fields[0] eq "Description:")){ $validaddendum = 1; } } } else { print UPDATE "\t"; print UPDATE $_; # append the new data } } close UPDATE; if ($validaddendum) { # verify permissions - if OK, do the update. # Updates are authorised if the author # of the job is either the original author # of the change or is in the Changeupdates group. foreach (@changedesc) { my @fields = split; if (($fields[0]) && ($fields[0] eq "User:")) { if ($User eq $fields[1]) { # job author is change author `$p4 change -f -i < $Scratchfile`; `$p4 job -d $Job`; return 0; } last; } } # job author is not change author - are they in the authorised group? my @augroup = `$p4 group -o $upgroup`; my $latch = 0; foreach (@augroup) { if ($latch) { if ($_ eq $User) { # job author is in updates group `$p4 change -f -i < $Scratchfile`; `$p4 job -d $Job`; return 0; } } else { if ($_ eq "Users:") { $latch = 1; } } } } return -1; # change has been rejected for some reason. } main { while (1) { # Get a complete list of Addendum jobs my @jobslist = `$p4 jobs -e Type=Addendum`; # Go through this list chomp (@jobslist); foreach (@jobslist) { my @fields = split(/ /); # get jobname my @job = `$p4 job -o $fields[0]`; # get job description process_job (@job); } sleep 10; } }