Source code of Windows XP (NT5)
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.

216 lines
5.5 KiB

  1. @echo off
  2. REM ------------------------------------------------------------------
  3. REM
  4. REM delbuild.cmd
  5. REM Delete the builds in the release servers.
  6. REM
  7. REM Copyright (c) Microsoft Corporation. All rights reserved.
  8. REM Version: < 1.0 > 05/13/2002 Suemiao Rossignol
  9. REM ------------------------------------------------------------------
  10. perl -x "%~f0" %*
  11. @set RETURNVALUE=%errorlevel%
  12. goto :endperl
  13. #!perl
  14. use strict;
  15. use lib "$ENV{RAZZLETOOLPATH}\\PostBuildScripts";
  16. use lib $ENV{RAZZLETOOLPATH};
  17. use Logmsg;
  18. use ParseArgs;
  19. use File::Basename;
  20. use comlib;
  21. use GetIniSetting;
  22. use RelQuality;
  23. $ENV{script_name} = basename( $0 );
  24. sub Usage {
  25. print<<USAGE;
  26. Lower the shares and delete the builds in the release servers.
  27. Usage:
  28. $ENV{script_name} [-l:<language>] [-k:<Number of builds to keep>] [-p]
  29. -l Language. Default is "usa".
  30. -k Number of builds to keep.
  31. Default is 2.
  32. -p Powerless.
  33. -? Display Usage.
  34. USAGE
  35. exit(1)
  36. }
  37. my ( $numBuildToKeep, $powerLess, $buildNum );
  38. my ( $relPath, @delBlds, $dfsRoot );
  39. my ( $isRelServer );
  40. if( !&GetParams()) { exit(1); }
  41. timemsg( "Start $ENV{script_name}" );
  42. if( !&InitVars() ) { exit(1); }
  43. if( !&DeleteBuilds ){ exit(1); }
  44. timemsg( "Complete $ENV{script_name}" );
  45. exit(0);
  46. #-----------------------------------------------------------------------------
  47. sub GetParams
  48. {
  49. parseargs('?' => \&Usage, '\l:' => \$ENV{lang}, '\k:' => \$numBuildToKeep,
  50. 'd' => \$Logmsg::DEBUG,'p' =>\$powerLess, '\n:' => \$buildNum);
  51. $ENV{lang} = "usa" if( !$ENV{lang} );
  52. &comlib::ResetLogErrFile( "delbuild" );
  53. return 1;
  54. }
  55. #-----------------------------------------------------------------------------
  56. sub InitVars
  57. {
  58. $relPath = "\\release";
  59. ### Get DFS Root name
  60. if( !($dfsRoot = &GetIniSetting::GetSetting( "DFSRootName" ) ) )
  61. {
  62. errmsg( "[DFSRootName] undefined in [xpsp1.ini]." );
  63. return 0;
  64. }
  65. # Set number of builds to keep
  66. if( !$numBuildToKeep )
  67. {
  68. $numBuildToKeep = &GetIniSetting::GetSetting( "ReleaseServerBuildsToKeep::$ENV{computername}" );
  69. }
  70. $numBuildToKeep = 3 if( !$numBuildToKeep );
  71. # Check if this is release server
  72. my @iniRequest = ( "ReleaseServers::$ENV{lang}::$ENV{_buildArch}$ENV{_buildType}" );
  73. my( $iniRelServers ) = &GetIniSetting::GetSetting( @iniRequest );
  74. my @releaseServers = split( /\s+/, $iniRelServers );
  75. for ( @releaseServers )
  76. {
  77. if( lc $ENV{computername} eq lc $_ ){ $isRelServer =1; last;}
  78. }
  79. # Get existing builds
  80. my @allBlds;
  81. if( $buildNum)
  82. {
  83. push( @allBlds, $buildNum );
  84. }
  85. else
  86. {
  87. chomp( @allBlds = ( `dir $relPath /ad /b /on`) );
  88. }
  89. for (my $i=0; $i<@allBlds; $i++ )
  90. {
  91. if( $allBlds[$i] !~ /\d+/ )
  92. {
  93. splice( @allBlds, $i, 1);
  94. --$i;
  95. next;
  96. }
  97. if( system("dir $relPath\\$allBlds[$i]\\$ENV{lang} >nul 2>nul") )
  98. {
  99. splice( @allBlds, $i, 1);
  100. --$i;
  101. }
  102. }
  103. @allBlds = sort {lc($a) cmp lc($b) } @allBlds;
  104. my $i;
  105. for( my $i=0; $i<@allBlds; $i++ )
  106. {
  107. last if( @allBlds <= $numBuildToKeep );
  108. next if( $isRelServer && IsKeepQuality( $allBlds[$i] ) );
  109. push ( @delBlds, $allBlds[$i] );
  110. splice( @allBlds, $i, 1);
  111. --$i;
  112. }
  113. logmsg( "Language ................[$ENV{lang}]" );
  114. logmsg( "Input Build Number ......[$buildNum]" );
  115. logmsg( "Number of Builds To Keep [$numBuildToKeep]" )if( !$buildNum );
  116. logmsg( "Builds to be kept .......[@allBlds]" ) if( !$buildNum );
  117. logmsg( "Builds to be Deleted ....[@delBlds]" );
  118. logmsg( "DFS Root ................[$dfsRoot]" );
  119. logmsg( "Temp Log file ...........[$ENV{LOGFILE}]" );
  120. logmsg( "Temp Error file .........[$ENV{ERRFILE}]" );
  121. return 1;
  122. }
  123. #-----------------------------------------------------------------------------
  124. sub IsKeepQuality
  125. {
  126. my ( $pBldNo ) =@_;
  127. my $qlyDir = "$dfsRoot\\xpsp1\\$pBldNo\\$ENV{lang}";
  128. return 0 if( system( "dir $qlyDir\\$pBldNo\.*\.BLD >nul 2>nul") );
  129. my @tmp = `dir /b $qlyDir\\$pBldNo\.*\.BLD`;
  130. chomp @tmp;
  131. for my $file ( @tmp )
  132. {
  133. my $qly = (`cat $qlyDir\\$file`);
  134. chomp( $qly );
  135. return 1 if( $qly =~ /sav/i || $qly =~ /idw/i || $qly =~ /idx/i );
  136. }
  137. return 0;
  138. }
  139. #-----------------------------------------------------------------------------
  140. sub DeleteBuilds
  141. {
  142. my $dash = '-' x 60;
  143. logmsg ( $dash );
  144. if( $buildNum && !@delBlds )
  145. {
  146. wrnmsg( "The build quality cannot be deleted." );
  147. wrnmsg( "Lower the build first, then try again." );
  148. return 1;
  149. }
  150. if( $isRelServer && !$powerLess )
  151. {
  152. open DELFILE, ">>timetask.cmd" || print "open fail\n";
  153. print DELFILE "$ENV{_ntdrive}\n";
  154. }
  155. for my $bld ( @delBlds )
  156. {
  157. logmsg ( $dash );
  158. my $cmdLine = "raiseall.cmd -l:$ENV{lang} -n:$bld -lower";
  159. dbgmsg( $cmdLine );
  160. next if( $isRelServer && !&comlib::ExecuteSystemX( $cmdLine, $powerLess ) );
  161. $cmdLine = "rd /s /q $relPath\\$bld\\$ENV{lang}";
  162. if( $isRelServer && !$powerLess )
  163. {
  164. print DELFILE "$cmdLine\n";
  165. print DELFILE "rd $relPath\\$bld\n";
  166. next;
  167. }
  168. next if( !&comlib::ExecuteSystemX( $cmdLine, $powerLess ) );
  169. my @tmp= `dir /b $relPath\\$bld`;
  170. chomp @tmp;
  171. &comlib::ExecuteSystemX( "rd $relPath\\$bld", $powerLess ) if( !@tmp );
  172. }
  173. close DELFILE if( $isRelServer && !$powerLess );
  174. return 1;
  175. }
  176. #-----------------------------------------------------------------------------
  177. 1;
  178. __END__
  179. :endperl
  180. @echo off
  181. if not defined seterror (
  182. set seterror=
  183. for %%a in ( seterror.exe ) do set seterror=%%~$PATH:a
  184. )
  185. @%seterror% %RETURNVALUE%