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.

256 lines
7.1 KiB

  1. #---------------------------------------------------------------------
  2. package RelQuality;
  3. #
  4. # Copyright (c) Microsoft Corporation. All rights reserved.
  5. #
  6. # Version: 1.00 (11/15/2001) : SuemiaoR
  7. #
  8. # Purpose: Update/retrive NT release qulity information.
  9. #---------------------------------------------------------------------
  10. use strict;
  11. use vars qw($VERSION);
  12. $VERSION = '1.00';
  13. use File::Basename;
  14. use Logmsg;
  15. use comlib;
  16. ##### Define order of raise qualities
  17. my %qualityOrder = ( pre => 1, bvt => 2, tst => 3, sav => 4,
  18. idw => 5, ids => 6, idc => 7 );
  19. #---------------------------------------------------------------------
  20. sub IsValid
  21. {
  22. my ( $pQuality ) = @_;
  23. return 1 if ( exists $qualityOrder{lc $pQuality } );
  24. return 0;
  25. }
  26. #---------------------------------------------------------------------
  27. sub AllQlyFiles
  28. {
  29. my ( $pPath, $pFiles ) = @_;
  30. @{$pFiles} = grep { $_ if ( ! -d $_ ) } &comlib::globex( "$pPath\\*.qly" );
  31. return 1;
  32. }
  33. #---------------------------------------------------------------------
  34. sub AllQualities
  35. {
  36. my ( $pPath, $pBuildName ) = @_;
  37. my ( @allFiles, @allQualities );
  38. ##### Get existing QLY files
  39. &AllQlyFiles( $pPath, \@allFiles );
  40. for my $theFile ( @allFiles )
  41. {
  42. basename( $theFile ) =~ /^([^\.]+)\.qly$/;
  43. my ( $fileQuality ) = $1;
  44. my @qlyInfo = &comlib::ReadFile( $theFile );
  45. push( @allQualities, $fileQuality) if ( $qlyInfo[0] =~ /$pBuildName/i );
  46. }
  47. return @allQualities;
  48. }
  49. #---------------------------------------------------------------------
  50. sub Exist
  51. {
  52. my ( $pPath, $pBuildName, $pQuality ) = @_;
  53. my @allQualities = &AllQualities( $pPath, $pBuildName );
  54. for my $theQly ( @allQualities )
  55. {
  56. return 1 if( lc $theQly eq $pQuality );
  57. }
  58. return 0;
  59. }
  60. #---------------------------------------------------------------------
  61. sub Which
  62. {
  63. my ( $pPath, $pBuildName, $pRetQly) = @_;
  64. my @allQualities = &AllQualities( $pPath, $pBuildName );
  65. $$pRetQly = $allQualities[0] if( @allQualities == 1 );
  66. return 1;
  67. }
  68. #---------------------------------------------------------------------
  69. sub Add
  70. {
  71. my ( $pPath, $pBuildName, $pQuality ) = @_;
  72. if( &Exist( $pPath, $pBuildName, $pQuality ) )
  73. {
  74. wrnmsg( "Found [$pQuality.qly], skip adding the file." );
  75. return 1;
  76. }
  77. ##### Create new QLY file
  78. if( ! (open QLYFILE, "> $pPath\\$pQuality.qly" ) )
  79. {
  80. errmsg( "Could not open [$pPath\\$pQuality.qly] for write ($!)." );
  81. return 0;
  82. }
  83. dbgmsg( "Adding [$pPath\\$pQuality.qly]..." );
  84. print QLYFILE "$pBuildName\n";
  85. close QLYFILE;
  86. return 1;
  87. }
  88. #---------------------------------------------------------------------
  89. sub Delete
  90. {
  91. my ( $pPath, $pQuality ) = @_;
  92. my $file = "$pPath\\$pQuality.qly";
  93. if( system( "dir /b $file >nul 2>nul" ) )
  94. {
  95. wrnmsg( "[$file] is not existing, skip deleting the file." );
  96. return 1;
  97. }
  98. if( system( "del $file >nul 2>nil" ) )
  99. {
  100. errmsg( "Could not delete $file ($!)." );
  101. return 0;
  102. }
  103. return 1;
  104. }
  105. #---------------------------------------------------------------------
  106. sub Update
  107. {
  108. my ( $pPath, $pBuildName, $pReqQly ) = @_;
  109. if ( !&IsValid( $pReqQly ) )
  110. {
  111. errmsg( "Invalid [$pReqQly ] quality, exit." );
  112. return 0;
  113. }
  114. my @allQualities = &AllQualities($pPath, $pBuildName );
  115. ##### Remove any QLY files that don't match current status
  116. ##### -- there should never be more than one, but we
  117. ##### should handle that case correctly
  118. my $tobeAdd = 1;
  119. for my $theQly ( @allQualities )
  120. {
  121. if ( !exists $qualityOrder{lc $theQly } )
  122. {
  123. wrnmsg( "Invalid quality file [$theQly.qly] found, deleting...");
  124. return 0 if( !&Delete( $pPath, $theQly ));
  125. next;
  126. }
  127. #####Same quality with request
  128. if( lc $theQly eq lc $pReqQly )
  129. {
  130. dbgmsg( "Same quality [$pReqQly] found, skip adding..." );
  131. $tobeAdd = 0;
  132. next;
  133. }
  134. #####Different quality with request
  135. if ( !&AllowQualityTransition( $theQly, $pReqQly ) )
  136. {
  137. errmsg( "Not allowed to go from [$theQly] to [$pReqQly] quality!" );
  138. return 0;
  139. }
  140. #####Remove the previous QLY file
  141. return 0 if( !&Delete( $pPath, $theQly ));
  142. }
  143. #####Add the requested QLY file
  144. return 0 if( $tobeAdd && !&Add( $pPath, $pBuildName, $pReqQly ) );
  145. return 1;
  146. }
  147. #---------------------------------------------------------------------
  148. sub AllowQualityTransition
  149. {
  150. my ( $pLastQly, $pReqQly ) = @_;
  151. ##### Allow transition to sav from any previous quality
  152. return 1 if ( lc $pReqQly eq 'sav' );
  153. ###### Allow transition from pre/bvt to any quality
  154. return 1 if( lc $pLastQly eq "pre" ||lc $pLastQly eq "bvt" );
  155. ##### Don't allow transition from anything else to pre/bvt
  156. return 0 if ( lc $pReqQly eq "pre" || lc $pReqQly eq "bvt" );
  157. ###### Otherwise allow transitions based on order specified in %qualityOrder
  158. return 1 if ( $qualityOrder{lc $pReqQly} >= $qualityOrder{lc $pLastQly} );
  159. return 0;
  160. }
  161. #---------------------------------------------------------------------
  162. =head1 NAME
  163. RelQuality - Access/Update release quality Information.
  164. =head1 SYNOPSIS
  165. use RelQuality;
  166. AllQlyFiles( $path, @return_files)
  167. where $path is the location of the quality files.
  168. where @return_files is the return array contains all the quality file names in the given $path.
  169. AllQualities( $path, $buildname )
  170. where $path is the location of the quality files.
  171. where $buildname is the searach criteria that used to match the content in quality file.
  172. return all the qualities exist in $path and match $buildname.
  173. Exist( $path, $buildname, $quality )
  174. where $path is the location of the quality files.
  175. where $buildname is the searach criteria that used to match the content in quality file.
  176. where $quality is the inquiry candidate.
  177. return true if $quality is existing for $buildname in $path. Otherwise, return false.
  178. Which( $path, $buildname, $return_quality )
  179. where $path is the location of the quality files.
  180. where $buildname is the searach criteria that used to match the content in quality file.
  181. where $return_quality is the return quality value for $buildname in $path.
  182. Add( $path, $buildname, $quality )
  183. where $path is the location of the quality files.
  184. where $buildname is used to be saved in quality file.
  185. where $quality is part of the file name to be created.
  186. Delete( $path, $quality )
  187. where $path is the location of the quality files.
  188. where $quality is part of the file name to be deleted.
  189. Upadte( $path, $buildname, $quality )
  190. where $path is the location of the quality files.
  191. where $buildname is the searach criteria that used to match the content in quality file.
  192. where $quality used to update qulity file name by given $buildname in $path.
  193. AllowQualityTransition( $q1, $q2 )
  194. where $q1 is the quality to be replaced.
  195. where $q2 is the quality to replace.
  196. return true if the replace order is allowed. Otherwise, return false.
  197. =head1 DESCRIPTION
  198. used to access or update release quality information.
  199. =head1 AUTHOR
  200. Suemiao Rossignol <[email protected]>
  201. =head1 COPYRIGHT
  202. Copyright (c) Microsoft Corporation. All rights reserved.
  203. =cut
  204. 1;