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.

130 lines
2.7 KiB

  1. #----------------------------------------------------------------//
  2. # Script: changelab.pl
  3. #
  4. # (c) 2001 Microsoft Corporation. All rights reserved.
  5. #
  6. # Purpose: This script maps the client views of all
  7. # depots to the view specified as an argument.
  8. # usage: perl.exe changelab.pl <lab_name>
  9. #
  10. # Maintenance: Update @labarray to reflect the list of valid labs
  11. #
  12. # Version: <1.00> 03/22/2001 : VishnuP
  13. #----------------------------------------------------------------//
  14. $VERSION = '1.00';
  15. if ($#ARGV != 0) {
  16. die "usage: perl.exe changelab.pl <lab_name>\n";
  17. }
  18. $changeto = lc($ARGV[$#ARGV]);
  19. if (validateLab() == 0)
  20. {
  21. die "$changeto is not a valid <lab_name>\n";
  22. }
  23. $sdxroot = $ENV{'SDXROOT'} || die "SDXROOT not defined\n";
  24. chdir($sdxroot);
  25. @SdMapping = `sd client -o`;
  26. foreach $line (@SdMapping) {
  27. if ($line =~ m/depot\/([^\/]+)\//) {
  28. $line =~ s/$1/$changeto/;
  29. }
  30. $SdNewMapping .= $line;
  31. }
  32. $tmpdir = $ENV{'tmp'} || die "tmp not defined\n";
  33. $dirOnly = "root";
  34. MapIt();
  35. $SdNewMapping = "";
  36. @dirs = `dir /ad /b $sdxroot`;
  37. chomp(@dirs);
  38. foreach $dir (@dirs) {
  39. $dirOnly = $dir;
  40. $dir = "$sdxroot\\$dir";
  41. if (-e "$dir\\sd.ini"){
  42. chdir($dir);
  43. @SdMapping = `sd client -o`;
  44. foreach $line (@SdMapping) {
  45. if ($line =~ m/depot\/([^\/]+)\//) {
  46. $line =~ s/$1/$changeto/;
  47. }
  48. $SdNewMapping .= $line;
  49. }
  50. MapIt();
  51. $SdNewMapping = "";
  52. }
  53. }
  54. chdir($sdxroot);
  55. # edit( in-memory) sd.map to reflect the changes
  56. $sdMapFile = "sd.map";
  57. `attrib -r -h sd.map`;
  58. if ( !open(INIFILE, "+< $sdMapFile"))
  59. {
  60. die "cannot open file $sdMapFile $!\n";
  61. }
  62. $sdMapStream = "";
  63. while (<INIFILE>) {
  64. if (/BRANCH([\s+\=]+)([\w+]+)/) {
  65. s/$2/$changeto/eg;
  66. }
  67. $sdMapStream .= $_;
  68. }
  69. seek(INIFILE, 0, 0) or die "cannot seek to start of $sdMapFile\n";
  70. print INIFILE $sdMapStream or die "cannot print to $sdMapFile\n";;
  71. truncate(INIFILE, tell(INIFILE)) or die "cannot truncate $sdMapFile\n";
  72. close (INIFILE);
  73. `attrib +r +h sd.map`;
  74. sub validateLab{
  75. @labarray = ("lab01_n", "lab02_n", "lab03_n", "lab03_dev", "lab04_n", "lab05_n",
  76. "lab06_n", "lab07_n", "lab08_n", "lab09_n", "lab10_n",
  77. "lab11_n", "lab12_n", "lab13_n", "lab14_n", "lab15_n",
  78. "main");
  79. foreach $lab (@labarray){
  80. if ($changeto eq $lab){
  81. return 1;
  82. }
  83. }
  84. return 0;
  85. }
  86. sub MapIt{
  87. $random = int (1000 * rand(7));
  88. $clientSpecFile = "$tmpdir\\$random";
  89. if ( !open(MAPFILE, ">$clientSpecFile"))
  90. {
  91. die "cannot create file $clientSpecFile\n";
  92. }
  93. print MAPFILE $SdNewMapping;
  94. close(MAPFILE);
  95. print "Changing $dirOnly depot...\n";
  96. print `sd client -i < $clientSpecFile`;
  97. unlink($clientSpecFile);
  98. }