602
|
1 |
#!perl
|
|
2 |
# Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
# All rights reserved.
|
|
4 |
# This component and the accompanying materials are made available
|
|
5 |
# under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
# which accompanies this distribution, and is available
|
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
#
|
|
9 |
# Initial Contributors:
|
|
10 |
# Nokia Corporation - initial contribution.
|
|
11 |
#
|
|
12 |
# Contributors:
|
|
13 |
#
|
|
14 |
# Description:
|
|
15 |
#
|
|
16 |
#
|
|
17 |
|
|
18 |
use strict;
|
|
19 |
use FindBin;
|
|
20 |
use lib "$FindBin::Bin";
|
|
21 |
use Getopt::Long;
|
|
22 |
use File::Path;
|
|
23 |
use IniData;
|
|
24 |
use RelTransfer::Export;
|
|
25 |
use RelData;
|
|
26 |
use CommandController;
|
|
27 |
|
|
28 |
|
|
29 |
#
|
|
30 |
# Globals.
|
|
31 |
#
|
|
32 |
|
|
33 |
my $verbose = 0;
|
|
34 |
my $dummy = 0;
|
|
35 |
my $force = 0;
|
|
36 |
my $ftpResume = 0;
|
|
37 |
my $iniData;
|
|
38 |
my $commandController;
|
|
39 |
my $excludeSource = 0;
|
|
40 |
my %releases; # Data structure changed to a double hash (from a single hash).
|
|
41 |
# Top level keys are (case lowered) component names with has reference values.
|
|
42 |
# Second level hash keys are versions, with a dummy value.
|
|
43 |
# This arrangement makes it possible for a single component to have more than one
|
|
44 |
# version, and to easily delete versions that have already been imported.
|
|
45 |
my %failedExports;
|
|
46 |
my %goodExports;
|
|
47 |
my %alreadyExported;
|
|
48 |
|
|
49 |
#
|
|
50 |
# Main.
|
|
51 |
#
|
|
52 |
|
|
53 |
ProcessCommandLine();
|
|
54 |
ExportRelease();
|
|
55 |
PrintReport();
|
|
56 |
|
|
57 |
#
|
|
58 |
# Subs.
|
|
59 |
#
|
|
60 |
|
|
61 |
sub ProcessCommandLine {
|
|
62 |
Getopt::Long::Configure ("bundling");
|
|
63 |
my $help;
|
|
64 |
GetOptions("h" => \$help, "v+" => \$verbose, "f" => \$force, "r" => \$ftpResume, "d" => \$dummy, "e" => \$excludeSource);
|
|
65 |
|
|
66 |
if ($help) {
|
|
67 |
Usage(0);
|
|
68 |
}
|
|
69 |
|
|
70 |
if (scalar(@ARGV) == 1) {
|
|
71 |
if (-f $ARGV[0]) {
|
|
72 |
open IN, $ARGV[0] or die "Error: Couldn't open $ARGV[0] for reading: $!\n";
|
|
73 |
while (my $line = <IN>) {
|
|
74 |
chomp $line;
|
|
75 |
$line =~ s/^\s*$//;
|
|
76 |
$line =~ s/#.*//;
|
|
77 |
if ($line eq '') {
|
|
78 |
next; #Nothing left
|
|
79 |
}
|
|
80 |
my ($comp, $ver) = split(" ", $line);
|
|
81 |
if (defined $comp and defined $ver) {
|
|
82 |
$releases{lc($comp)}->{$ver} = 1;
|
|
83 |
}
|
|
84 |
else {
|
|
85 |
print "Error: Invalid file format in $ARGV[0]\n";
|
|
86 |
Usage(1);
|
|
87 |
}
|
|
88 |
}
|
|
89 |
close IN;
|
|
90 |
}
|
|
91 |
else {
|
|
92 |
print "Error: $ARGV[0] is not a file\n";
|
|
93 |
Usage(1);
|
|
94 |
}
|
|
95 |
}
|
|
96 |
elsif (scalar(@ARGV) == 2) {
|
|
97 |
$releases{lc($ARGV[0])}->{$ARGV[1]} = 1;
|
|
98 |
}
|
|
99 |
else {
|
|
100 |
print "Error: Invalid arguments\n";
|
|
101 |
Usage(1);
|
|
102 |
}
|
|
103 |
$iniData = IniData->New(undef,1);
|
|
104 |
$commandController = CommandController->New($iniData, 'ExportRel');
|
|
105 |
#if ftp resume option is used override value in reltools.ini
|
|
106 |
if ($ftpResume) {
|
|
107 |
$iniData->FtpServerSupportsResume(1);
|
|
108 |
}
|
|
109 |
}
|
|
110 |
|
|
111 |
sub Usage {
|
|
112 |
my $exitCode = shift;
|
|
113 |
|
|
114 |
Utils::PrintDeathMessage($exitCode, "\nUsage: exportrel [options] (<component> <version>) | (<component_ver_list_file>)
|
|
115 |
|
|
116 |
options:
|
|
117 |
|
|
118 |
-h help
|
|
119 |
-f force export overwriting if necessary
|
|
120 |
-r use FTP reconnect and resume transfer mode
|
|
121 |
-d dummy run (don't do anything) - assumes -v
|
|
122 |
-e exclude source
|
|
123 |
-v verbose output (-vv very verbose)\n");
|
|
124 |
}
|
|
125 |
|
|
126 |
sub ExportRelease {
|
|
127 |
my $exporter = RelTransfer::Export->New(ini_data => $iniData,
|
|
128 |
force => $force,
|
|
129 |
dummy => $dummy,
|
|
130 |
excludeSource => $excludeSource,
|
|
131 |
verbose => $verbose);
|
|
132 |
#do the export checking for errors
|
|
133 |
foreach my $comp (sort keys %releases) {
|
|
134 |
foreach my $ver (keys %{$releases{$comp}}) {
|
|
135 |
my $exported;
|
|
136 |
eval {
|
|
137 |
GetCorrectVersionNumber($comp, \$ver);
|
|
138 |
$exported = $exporter->TransferRelease($comp, $ver);
|
|
139 |
};
|
|
140 |
if ($@) {
|
|
141 |
print $@;
|
|
142 |
if ($@ =~ /cannot\s+connect/i) {
|
|
143 |
print "\nConnection to remote site dropped aborting export\n";
|
|
144 |
last;
|
|
145 |
}
|
|
146 |
my $error = $@;
|
|
147 |
chomp $error;
|
|
148 |
$error =~ s/^error: ("?$comp $ver"? )?//i;
|
|
149 |
$failedExports{$comp}->{$ver} = $error;
|
|
150 |
} else {
|
|
151 |
if ($exported) {
|
|
152 |
push @{$goodExports{$comp}}, $ver;
|
|
153 |
} else {
|
|
154 |
push @{$alreadyExported{$comp}}, $ver;
|
|
155 |
}
|
|
156 |
}
|
|
157 |
}
|
|
158 |
}
|
|
159 |
}
|
|
160 |
|
|
161 |
sub GetCorrectVersionNumber {
|
|
162 |
#This function changes the version number string of each component to that
|
|
163 |
#stored in its reldata file. This is required because version numbers are case dependent
|
|
164 |
my $comp = shift;
|
|
165 |
my $verRef = shift;
|
|
166 |
|
|
167 |
my $relData = RelData->Open($iniData, $comp, $$verRef, $verbose);
|
|
168 |
my $env = $relData->Environment();
|
|
169 |
$$verRef = $env->{$comp};
|
|
170 |
}
|
|
171 |
|
|
172 |
sub PrintReport {
|
|
173 |
print "\n=========EXPORT SUMMARY==========\n";
|
|
174 |
|
|
175 |
my $tableData = [["Component", "Version", "status"]];
|
|
176 |
|
|
177 |
foreach my $comp (sort keys %goodExports) {
|
|
178 |
foreach my $ver (@{$goodExports{$comp}}) {
|
|
179 |
push (@$tableData, [$comp, $ver, 'successfully exported']);
|
|
180 |
}
|
|
181 |
}
|
|
182 |
|
|
183 |
foreach my $comp (sort keys %alreadyExported) {
|
|
184 |
foreach my $ver (@{$alreadyExported{$comp}}) {
|
|
185 |
push (@$tableData, [$comp, $ver, 'has already been exported']);
|
|
186 |
}
|
|
187 |
}
|
|
188 |
|
|
189 |
if (scalar @{$tableData} > 1) {
|
|
190 |
$iniData->TableFormatter->PrintTable($tableData, 1);
|
|
191 |
}
|
|
192 |
|
|
193 |
#handle failed exports
|
|
194 |
if (keys %failedExports) {
|
|
195 |
print "\n=========FAILED EXPORTS==========\n";
|
|
196 |
my $failureTableData = [["Component", "Version", "Failure reason"]];
|
|
197 |
foreach my $comp (sort keys %failedExports) {
|
|
198 |
foreach my $ver (sort keys %{$failedExports{$comp}}) {
|
|
199 |
push (@$failureTableData, [$comp, $ver, $failedExports{$comp}->{$ver}]);
|
|
200 |
}
|
|
201 |
}
|
|
202 |
$iniData->TableFormatter->PrintTable($failureTableData, 1);
|
|
203 |
print "\nError: Unable to export component release successfully\n";
|
|
204 |
}
|
|
205 |
else
|
|
206 |
{
|
|
207 |
if (keys %goodExports) {
|
|
208 |
print "\nAll releases exported successfully\n";
|
|
209 |
} else {
|
|
210 |
print "\nNothing to do!\n";
|
|
211 |
}
|
|
212 |
}
|
|
213 |
}
|
|
214 |
|
|
215 |
__END__
|
|
216 |
|
|
217 |
=head1 NAME
|
|
218 |
|
|
219 |
ExportRel - Exports a component release to a remote site.
|
|
220 |
|
|
221 |
=head1 SYNOPSIS
|
|
222 |
|
|
223 |
exportrel [options] (<component> <version>) | (<component_ver_list_file>)
|
|
224 |
|
|
225 |
options:
|
|
226 |
|
|
227 |
-h help
|
|
228 |
-f force export overwriting if necessary
|
|
229 |
-r use FTP reconnect and resume transfer mode
|
|
230 |
-d dummy run (don't do anything) - assumes -v
|
|
231 |
-e exclude source
|
|
232 |
-v verbose output (-vv very verbose)
|
|
233 |
|
|
234 |
=head1 DESCRIPTION
|
|
235 |
|
|
236 |
Takes a C<component> and C<version> number as arguments. Encrypts the release and sends it to the projects shared archive stored on a remote site.
|
|
237 |
|
|
238 |
The name of file containing a list of components and versions maybe passed as an argument to the tool instead of a single component to export multiple releases.
|
|
239 |
|
|
240 |
Using the C<-f> option will force releases to be exported even if they already exist on the remote site (this only applies to components existing in the users export table)
|
|
241 |
|
|
242 |
If the C<-r> option is used and the FTP connection is dropped during the upload of a release, the tools will automatically reconnect to the FTP site and resume the upload. This feature may not be supported by some FTP servers.
|
|
243 |
|
|
244 |
Using C<-e> option will create a component release without source.
|
|
245 |
|
|
246 |
=head1 KNOWN BUGS
|
|
247 |
|
|
248 |
None
|
|
249 |
|
|
250 |
=head1 COPYRIGHT
|
|
251 |
|
|
252 |
Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
253 |
All rights reserved.
|
|
254 |
This component and the accompanying materials are made available
|
|
255 |
under the terms of the License "Eclipse Public License v1.0"
|
|
256 |
which accompanies this distribution, and is available
|
|
257 |
at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
258 |
|
|
259 |
Initial Contributors:
|
|
260 |
Nokia Corporation - initial contribution.
|
|
261 |
|
|
262 |
Contributors:
|
|
263 |
|
|
264 |
Description:
|
|
265 |
|
|
266 |
|
|
267 |
=cut
|