Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

220 lines
5.6 KiB

  1. @rem = '-*- Perl -*-';
  2. @rem = '
  3. @if "%overbose%" == "" echo off
  4. setlocal
  5. for %%i in (oenvtest.bat) do @call %%~$PATH:i
  6. set ARGS= %*
  7. call perl%OPERLOPT% -w %~dpnx0 %ARGS:/?=-?%
  8. goto :eof
  9. ';
  10. #
  11. # REVIEWD - Source Depot review daemon
  12. #
  13. # See sub Usage for details.
  14. #
  15. # Author: smueller
  16. #
  17. #
  18. # External dependencies
  19. #
  20. BEGIN { if (exists $ENV{OTOOLS}) { # set library path for OTOOLS environment
  21. my $l="$ENV{OTOOLS}\\lib\\perl"; @INC=($l,"$l\\$ENV{PROCESSOR_ARCHITECTURE}")
  22. }}
  23. BEGIN { if (exists $ENV{'sdxroot'}) {
  24. require $ENV{'sdxroot'} . '\TOOLS\sendmsg.pl';
  25. }}
  26. require 5;
  27. use strict;
  28. use Getopt::Long;
  29. use Office::SD 0.78;
  30. use vars qw($fDebug @ports %counters $counter $sleep @describe);
  31. #
  32. # Utilities
  33. #
  34. #
  35. # Usage - Display detailed usage information and exit.
  36. #
  37. sub Usage {
  38. print <<EOT;
  39. reviewd - Send checkin mail to users in a Source Depot server
  40. reviewd [ -d ] [ -p port ... ] counter sleep
  41. The 'counter' argument specifies the name of the review counter to
  42. track.
  43. The 'sleep' argument specifies how many minutes to sleep between
  44. processing a set of changes and polling for the next set.
  45. The -p port flag specifies a depot server and port to poll. Specify
  46. multiple depots to poll by specifying multiple -p port flags.
  47. The -d flag runs the script in debug mode and generates
  48. additional debugging output.
  49. EOT
  50. exit 1;
  51. }
  52. #
  53. # Debug - Print debugging output if in debug mode.
  54. #
  55. sub Debug {
  56. print @_ if $fDebug;
  57. }
  58. #
  59. # Collect - Collect text and info output from SDDescribe
  60. #
  61. sub Collect {
  62. push @describe, @_;
  63. }
  64. #
  65. # ReviewChanges - Look for changes to process and do so
  66. #
  67. sub ReviewChanges {
  68. my($counter) = @_;
  69. foreach my $port (@ports) {
  70. # pick a depot
  71. ConfigSD(port => $port);
  72. # highest numbered change seen, for updating the counter each iteration
  73. my $nclMax = 0;
  74. # retrieve new changes
  75. #Debug("COMMAND: sd -p $port review -t $counter\n");
  76. my $rchanges = SDReview(\"-t $counter");
  77. next if ! defined $rchanges; # no new submitted changes
  78. foreach my $rc (@$rchanges) { # for each newly submitted change list
  79. Debug("CHANGE=$rc->{Change}; USER=$rc->{User}; EMAIL=$rc->{Email}; FULLNAME=$rc->{FullName}\n");
  80. warn "reviewd: processing port $port, change $rc->{Change}...\n";
  81. # retrieve users interested in change
  82. #Debug("COMMAND: sd -p $port reviews -c $rc->{Change}\n");
  83. my $rusers = SDReviews(\"-c $rc->{Change}");
  84. next if ! defined $rusers; # no interested users
  85. my @reviewers;
  86. foreach my $ru (@$rusers) { # for each user interested in this change
  87. Debug("USER=$ru->{User}; RAWEMAIL=$ru->{Email}; FULLNAME=$ru->{FullName}\n");
  88. my ($email) = $ru->{Email} =~ /^.*\\(\S*)\@.*$/;
  89. $email = $ru->{Email} if ! defined $email || $email eq '';
  90. Debug("USER=$ru->{User}; EMAIL=$email; FULLNAME=$ru->{FullName}\n");
  91. push @reviewers, $email;
  92. }
  93. # send submitter and describe output to any interested parties
  94. if (@reviewers) {
  95. # collect raw describe output using Collect callback
  96. my $rconfigSav = ConfigSD(echo => echoText | echoInfo, echofunc => \&Collect);
  97. @describe = ();
  98. my $rchange = SDDescribe(\'-s', $rc->{Change});
  99. ConfigSD($rconfigSav);
  100. # format header fields
  101. my $description1 = $rchange->{Description};
  102. $description1 =~ s/\n.*//; # get first line only
  103. my $subject = "$rchange->{User}: #$rc->{Change}: $description1";
  104. my $body = join '', @describe;
  105. my $sender = 'NtSourceDepotReview';
  106. # Send mail to the reviewers
  107. Debug("COMMAND: sendmsg -e -m $sender, $subject, $body, @reviewers\n");
  108. if (exists $ENV{'sdxroot'}) {
  109. my $ret = sendmsg('-v', '-m', $sender, $subject, $body, @reviewers);
  110. } else {
  111. print "From: $sender\nTo: @reviewers\nSubject: $subject\n\n$body\n";
  112. }
  113. }
  114. $nclMax = $rc->{Change};
  115. Debug("TOPCHANGE: $nclMax\n");
  116. }
  117. #
  118. # Update review marker to reflect changes reviewed.
  119. #
  120. #Debug("COMMAND: sd -p $port counter $counter $nclMax\n") if $nclMax;
  121. SDSetCounter($counter, $nclMax) if $nclMax;
  122. }
  123. }
  124. #
  125. # Daemon - Loop, work, wait
  126. #
  127. sub Daemon {
  128. my($counter, $sleep) = @_;
  129. Debug("COUNTER: $counter\n");
  130. Debug("SLEEP: $sleep\n");
  131. for (;;) {
  132. ReviewChanges($counter);
  133. Debug("SLEEPING $sleep SECONDS...\n");
  134. sleep($sleep);
  135. }
  136. }
  137. #
  138. # main
  139. #
  140. Usage if ! GetOptions('h|?', \&Usage, 'd', \$fDebug, 'p=s@', \@ports)
  141. || @ARGV != 2;
  142. # enable debug output if appropriate
  143. ConfigSD(verbose => 1) if $fDebug;
  144. # validate ports
  145. if (@ports == 0) {
  146. my $rset = SDSet();
  147. if (exists $rset->{SDPORT}) {
  148. @ports = ($rset->{SDPORT});
  149. warn "reviewd: no ports specified; defaulting to $ports[0]\n";
  150. }
  151. }
  152. foreach my $port (@ports) {
  153. ConfigSD(port => $port);
  154. if (! defined SDInfo()) {
  155. warn "reviewd: port $port appears bogus, skipping\n";
  156. $port = 'BOGUS:0000';
  157. }
  158. }
  159. @ports = grep $_ ne 'BOGUS:0000', @ports;
  160. if (@ports == 0) {
  161. die "reviewd: no valid ports specified\n";
  162. }
  163. # validate counter -- assume if first depot has it, all do
  164. ConfigSD(port => $ports[0]);
  165. $counter = $ARGV[0];
  166. %counters = SDCounters();
  167. die SDError() if SDError();
  168. die "No such counter '$counter'.\n" if ! exists $counters{uc $counter};
  169. $sleep = $ARGV[1];
  170. $sleep = 1 if $sleep == 0;
  171. $sleep *= 60; # convert to seconds
  172. Daemon($counter, $sleep);
  173. exit 0; # never get here