1 | #!/usr/bin/perl |
---|
2 | # A script to invoke madx/madxp on a specific target, and to store the modified outputs into |
---|
3 | # the madx-examples CVS repository, to alleviate the task of the people in charge of overwriting |
---|
4 | # test cases whenever a new release brought unsignificant changes... |
---|
5 | |
---|
6 | use File::Path; # to remove directory trees |
---|
7 | |
---|
8 | |
---|
9 | $target = $ARGV[0]; |
---|
10 | $root = "/afs/cern.ch/user/n/nougaret/scratch0/mad-automation"; |
---|
11 | |
---|
12 | @targets = `xsltproc --stringparam what list_targets $root/ProcessScenario.xsl $root/TestScenario.xml`; |
---|
13 | |
---|
14 | $localDirectory = `pwd`; chop $localDirectory; |
---|
15 | |
---|
16 | print "make sure you update the madx/madxp executables in /user/nougaret/MAD-X/madX before running this program.\n"; |
---|
17 | |
---|
18 | my $found = 0; |
---|
19 | foreach $targ (@targets){ |
---|
20 | |
---|
21 | chop $targ; # remove new line char |
---|
22 | if ($target eq $targ){ |
---|
23 | $found = 1; |
---|
24 | print "about to retreive information about target '$target'\n"; |
---|
25 | |
---|
26 | # do the CVS extraction locally |
---|
27 | my $localCvsExtractDir = "./localCvsExtractDir_$target"; |
---|
28 | mkdir $localCvsExtractDir; |
---|
29 | chdir "$localCvsExtractDir"; |
---|
30 | # do the CVS extraction |
---|
31 | my $cvsRootDir = ':gserver:isscvs.cern.ch:/local/reps/madx-examples'; |
---|
32 | `cvs -d $cvsRootDir checkout madX-examples/REF/$target`; |
---|
33 | my $targetDir = "$localDirectory/$localCvsExtractDir/madX-examples/REF/$target"; |
---|
34 | chdir $targetDir; |
---|
35 | $now=`pwd`; print "now in $now\n"; |
---|
36 | |
---|
37 | my @tests = `xsltproc --stringparam target $target --stringparam what list_tests $root/ProcessScenario.xsl $root/TestScenario.xml`; |
---|
38 | foreach $test (@tests){ |
---|
39 | chop $test; |
---|
40 | print "$test\n"; |
---|
41 | if ($test =~ /\.\/madx(p?)[\s\t]*<[\s\t]*([\w\d\.\_\-]+)[\s\t]*>[\s\t]*([\w\d\.\_\-]+)[\s\t]*(,[\s\t]*subdirectory=([\w\d\-\_\.]+))?/){ |
---|
42 | # chop $test; |
---|
43 | if ($1 eq 'p'){ |
---|
44 | $program = 'madxp'; |
---|
45 | } else { |
---|
46 | $program = 'madx'; |
---|
47 | } |
---|
48 | $input = $2; |
---|
49 | $output = $3; |
---|
50 | if (defined($4)){ |
---|
51 | $subdir = $5; |
---|
52 | } else { |
---|
53 | $subdir = ""; # everything takes place in the same, base directory |
---|
54 | } |
---|
55 | print "program is '$program' input is '$input', output is '$output', dir is '$subdir'\n"; |
---|
56 | |
---|
57 | if ($subdir ne ""){ |
---|
58 | chdir $subdir; # going into the sub-directory of the test |
---|
59 | } |
---|
60 | |
---|
61 | # path for madx/madxp should link to the latest production version |
---|
62 | my $where = `pwd`; print "invoked from $where\n"; |
---|
63 | my $programRoot = "/user/nougaret/MAD-X/madX"; |
---|
64 | my $command = "$programRoot/$program < $input > $output"; |
---|
65 | `rm $output`; # remove the output file (as the forced output redirection, does not seem to work from perl) |
---|
66 | my $outcome = `$command`; # execute the command |
---|
67 | print "outcome of \"$command\": $outcome\n"; |
---|
68 | print "note: MAD commands will be picked up in $programRoot\n"; |
---|
69 | |
---|
70 | # now look at the list of files that need CVS commit |
---|
71 | @locallyModified = `cvs status | grep Locally`; |
---|
72 | foreach $mod (@locallyModified){ |
---|
73 | chop $mod; |
---|
74 | if ($mod =~ /^File:[\s\t]*([\w\d\-\_\.]+)[\s\t]*Status: Locally Modified[\s\t]*$/){ |
---|
75 | my $file = $1; |
---|
76 | # need to commit this file |
---|
77 | print "now invoke 'cvs commit -m \"automated commit\"' $file\n"; |
---|
78 | `cvs commit -m \"automated commit - overwrote all outputs by MadTestOverwrite.pl\" $file`; |
---|
79 | } |
---|
80 | } |
---|
81 | |
---|
82 | |
---|
83 | if ($subdir ne ""){ |
---|
84 | chdir $targetDir; # going-back one level up |
---|
85 | } |
---|
86 | |
---|
87 | |
---|
88 | } else { |
---|
89 | print "no match of the MAD command line!\n"; |
---|
90 | exit 1; |
---|
91 | } # failed to match MAD command line |
---|
92 | } # for each test |
---|
93 | # clean-up the location of the extract (rmtree...) |
---|
94 | chdir $localDirectory; # back to where we were initially... |
---|
95 | print "now removing $localDirectory/$localCvsExtractDir CVS extract directory\n"; |
---|
96 | rmtree("$localDirectory/$localCvsExtractDir"); # remove the directory in which we did the CVS extract |
---|
97 | } # target found (only once) |
---|
98 | |
---|
99 | } |
---|
100 | |
---|
101 | if ($found eq 0) { |
---|
102 | print "non-existing target '$target'\n"; |
---|
103 | exit 1; |
---|
104 | } |
---|
105 | |
---|
106 | |
---|
107 | # retrieve the MAD command with input / output arguments |
---|
108 | |
---|
109 | #`xsltproc --stringparam what retreiveXXX ProcessScenario.xsl TestScenario.xml`; |
---|
110 | |
---|