-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcustomize_version.pl
executable file
·155 lines (143 loc) · 4.87 KB
/
customize_version.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env perl
use XML::Simple;
use Data::Dumper;
use Getopt::Std;
use File::Slurp;
use XML::Writer;
use IO::File;
# get the file name
$status=getopts("i:o:s:g:4:a:t:r:m:h");
$filename_in = $opt_i;
$filename_out = $opt_o;
$halld_home = $opt_s;
$halld_recon_home = $opt_r;
$halld_sim_home = $opt_m;
$hdds_home = $opt_g;
$hdgeant4_home = $opt_4;
$gluex_root_analysis_home = $opt_a;
$amptools_home = $opt_t;
if ($opt_h) {
print_usage();
exit;
}
if (!$filename_in || !$filename_out ) {
print "\nError: required command-line option missing\n\n";
print_usage();
exit 1;
}
if (!($halld_home || $halld_recon_home || $halld_sim_home || $hdds_home || $hdgeant4_home || $gluex_root_analysis_home || $amptools_home)) {
print "\nError: no custom home directories specified, no action taken\n\n";
print_usage();
exit 2;
}
if ($halld_home && $halld_recon || $halld_home && $halld_sim) {
print "\nError: halld_home used with either halld_recon or halld_sim or both, no action taken\n\n";
print_usage();
exit 3;
}
# slurp in the xml file
$ref = XMLin($filename_in, KeyAttr=>[]);
# dump it to the screen for debugging only
#print Dumper($ref);
my $output = IO::File->new(">$filename_out");
my $writer = XML::Writer->new(OUTPUT => $output, NEWLINES => 1);
$writer->startTag("gversion", "version" => "1.0");
$a = $ref->{'package'}; # an array reference;
#print "a = $a\n";
@b = @{$a}; # an array
#print "b = @b\n";
foreach $href (@b) {
$c = $href; # a hash reference
#print "c = $c\n";
%d = %{$c}; # a hash
#print "d{name} = $d{name}\n";
#print "d{version} = $d{version}\n";
$name = $d{name};
$version = $d{version};
$dirtag = $d{dirtag};
$url = $d{url};
$branch = $d{branch};
$home = $d{home};
$hash = $d{hash};
$debug_level = $d{debug_level};
#print "package = $name, version = $version\n";
if ($name eq "sim-recon" && $halld_home) {
if (uc($halld_home) ne "NONE") {
$writer->emptyTag("package", "name" => "$name", "home" => "$halld_home");
}
} elsif ($name eq "halld_recon" && $halld_recon_home) {
if (uc($halld_recon_home) ne "NONE") {
$writer->emptyTag("package", "name" => "$name", "home" => "$halld_recon_home");
}
} elsif ($name eq "halld_sim" && $halld_sim_home) {
if (uc($halld_sim_home) ne "NONE") {
$writer->emptyTag("package", "name" => "$name", "home" => "$halld_sim_home");
}
} elsif ($name eq "hdds" && $hdds_home) {
if (uc($hdds_home) ne "NONE") {
$writer->emptyTag("package", "name" => "$name", "home" => "$hdds_home");
}
} elsif ($name eq "hdgeant4" && $hdgeant4_home) {
if (uc($hdgeant4_home) ne "NONE") {
$writer->emptyTag("package", "name" => "$name", "home" => "$hdgeant4_home");
}
} elsif ($name eq "gluex_root_analysis" && $gluex_root_analysis_home) {
if (uc($gluex_root_analysis_home) ne "NONE") {
$writer->emptyTag("package", "name" => "$name", "home" => "$gluex_root_analysis_home");
}
} elsif ($name eq "amptools" && $amptools_home) {
if (uc($amptools_home) ne "NONE") {
$writer->emptyTag("package", "name" => "$name", "home" => "$amptools_home");
}
} else {
$write_element_command = "\$writer->emptyTag(\"package\", \"name\" => \"$name\"";
if ($version) {
$write_element_command .= ", \"version\" => \"$version\"";
}
if ($dirtag) {
$write_element_command .= ", \"dirtag\" => \"$dirtag\"";
}
if ($url) {
$write_element_command .= ", \"url\" => \"$url\"";
}
if ($branch) {
$write_element_command .= ", \"branch\" => \"$branch\"";
}
if ($home) {
$write_element_command .= ", \"home\" => \"$home\"";
}
if ($debug_level ne '') {
$write_element_command .= ", \"debug_level\" => \"$debug_level\"";
}
$write_element_command .= ");";
#print "write_element_command = $write_element_command\n";
eval $write_element_command;
}
}
$writer->endTag("gversion");
$writer->end();
$output->close();
print "\nInfo: contents of $filename_out:\n";
print "----------------------------------------\n";
system("cat $filename_out");
print "----------------------------------------\n";
exit;
sub print_usage {
my $usage = <<'EOM';
custom_sim_recon.pl: creates a version xml file with custom sim-recon home directory.
Options:
-i <input XML file name> (required)
-o <output XML file name> (required)
-s <custom sim-recon home directory> (optional, s for sim-recon)
-r <custom halld_recon home directory> (optional, r for recon)
-m <custom halld_sim home directory> (optional, m for Monte Carlo)
-g <custom HDDS home directory> (optional, g for geometry)
-4 <custom HDGeant4 home directory> (optional, 4 for 4)
-a <custom gluex_root_analysis home directory> (optional, a for analysis)
-t <custom amptools home directory> (optional, t for tools)
-h print this usage message
Note: if custom home directory name = "none", corresponding package element
will be omitted in output XML file.
EOM
print $usage;
}