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.

188 lines
5.2 KiB

  1. # $Id: review.pl#11 2001/10/30 21:27:51 REDMOND\\chrisant $
  2. # Simplify program name, if it is a path
  3. $0 =~ s/.*\\//;
  4. require $ENV{'sdxroot'} . '\TOOLS\sendmsg.pl';
  5. #
  6. # fatal usage error
  7. #
  8. sub usage
  9. {
  10. my($err) = @_;
  11. die
  12. "\n" .
  13. "$0: $err\n" .
  14. "\n" .
  15. " review - Sends checkin mail to users in a Source Depot server.\n" .
  16. "\n" .
  17. " review [ -d ] counter sleep\n" .
  18. "\n" .
  19. " The 'counter' argument specifies the name of the review counter.\n" .
  20. "\n" .
  21. " The 'sleep' argument specifies how many minutes to sleep after\n" .
  22. " processing a set of changes.\n" .
  23. "\n" .
  24. " The -d flag runs the script in debug mode and generates\n" .
  25. " additional debugging output.\n";
  26. }
  27. #
  28. # parse arguments
  29. #
  30. $debug = 0;
  31. while (@ARGV && $ARGV[0] =~ /^-/)
  32. {
  33. $opt = shift;
  34. if ($opt eq '-d')
  35. {
  36. $debug = 1;
  37. }
  38. else
  39. {
  40. usage("invalid option $opt.");
  41. }
  42. }
  43. if (@ARGV == 2)
  44. {
  45. $counter = $ARGV[0];
  46. $sleepseconds = $ARGV[1];
  47. $sleepseconds = 1 if ($sleepseconds == 0);
  48. $sleepseconds = $sleepseconds * 60;
  49. }
  50. else
  51. {
  52. usage("invalid argument(s).");
  53. }
  54. print( "COUNTER: $counter\n" ) if ($debug);
  55. print( "SLEEP SECONDS: $sleepseconds\n" ) if ($debug);
  56. do
  57. {
  58. # Remember highest numbered change we see, so that we can
  59. # reset the 'review' counter once the actions is complete.
  60. local( $topChange ) = 0;
  61. #
  62. # REVIEW - list of changes to review. (scope your review)
  63. #
  64. print( "COMMAND: sd review -t $counter\n" ) if ($debug);
  65. open( REVIEW, "sd review -t $counter |" ) || next;
  66. # at this point, you can process each change since the
  67. # last time you ran, or you can batch them together.
  68. # we'll process each change
  69. while( <REVIEW> )
  70. {
  71. #
  72. # Format: "Change x user <email> (Full Name)"
  73. #
  74. local( $change, $user, $email, $fullName ) =
  75. /Change (\d*) (\S*) <(\S*)> (\(.*\))/;
  76. print( "CHANGE=$change; USER=$user; EMAIL=$email; FULLNAME=$fullName\n" ) if ($debug);
  77. print "doing action for $change...\n";
  78. ## perform your action here: mailer, build daemon, etc.
  79. ## and in this example-the action is to send out email,
  80. local( @reviewers ) = ();
  81. #
  82. # Retrieve the list of users interested in a change.
  83. #
  84. print( "COMMAND: sd reviews -c $change\n" ) if ($debug);
  85. open( REVIEWERS, "sd reviews -c $change|" ) || next;
  86. while( <REVIEWERS> )
  87. {
  88. print( $_ ) if ($debug);
  89. # user <email> (Full Name)
  90. local( $user2, $email2, $fullName2 ) =
  91. /(\S*) <.*\\(\S*)\@.*> (\(.*\))/;
  92. if ( length($email2) == 0 )
  93. {
  94. ( $user2, $email2, $fullName2 ) =
  95. /(\S*) <(\S*)> (\(.*\))/;
  96. }
  97. print( "USER=$user2; EMAIL=$email2; FULLNAME=$fullName2\n" ) if ($debug);
  98. # Don't need this with the perl mailer - just list the senders one at a time.
  99. # push( @reviewers, ";" ) if @reviewers;
  100. push( @reviewers, "$email2" );
  101. }
  102. close( REVIEWERS );
  103. if ( @reviewers )
  104. {
  105. #
  106. # If there's any intrest, do a "sd describe -s -c $change"
  107. # Figure out who checked in the change and package it into mail
  108. #
  109. $MailBody = "";
  110. open( SYNOPSIS, "sd describe -s $change |" );
  111. $line = 0;
  112. while( <SYNOPSIS> )
  113. {
  114. $line++;
  115. if ($line == 1)
  116. {
  117. ( $who ) = / by .*\\(\S*)\@/;
  118. if( length($who) == 0 ) { ( $who ) = / by (\S*)\@/; }
  119. if( length($who) == 0 ) { ( $who ) = / by (\S*) /; }
  120. }
  121. if ($line == 3)
  122. {
  123. # Got a description. Remove the leading tab and the trailing newline
  124. $ChangeDescription = $_;
  125. $ChangeDescription =~ s/^\t(.*)\n$/$1/;
  126. }
  127. $MailBody .= $_;
  128. }
  129. close( SYNOPSIS );
  130. #
  131. # Send mail to the reviewers
  132. #
  133. $MailTitle = "$who: #$change: $ChangeDescription";
  134. $MailSender = "NtSourceDepotReview";
  135. print( "COMMAND: sendmsg -e -m $MailSender, $MailTitle, $MailBody, @reviewers\n" ) if ($debug);
  136. $rc = sendmsg ('-v', '-m', $MailSender, $MailTitle, $MailBody, @reviewers);
  137. }
  138. $topChange = $change;
  139. print( "TOPCHANGE: $topChange\n" ) if ($debug);
  140. }
  141. #
  142. # Update review marker to reflect changes reviewed.
  143. #
  144. print( "COMMAND: sd review -c $topChange -t $counter\n" ) if ($debug);
  145. system( "sd review -c $topChange -t $counter" ) if( $topChange );
  146. print( "SLEEPING $sleepseconds SECONDS...\n" ) if ($debug);
  147. }
  148. while sleep( $sleepseconds ); # sleep then do it all over again.