|
1 # Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 # All rights reserved. |
|
3 # This component and the accompanying materials are made available |
|
4 # under the terms of the License "Eclipse Public License v1.0" |
|
5 # which accompanies this distribution, and is available |
|
6 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 # |
|
8 # Initial Contributors: |
|
9 # Nokia Corporation - initial contribution. |
|
10 # |
|
11 # Contributors: |
|
12 # |
|
13 # Description: |
|
14 # |
|
15 # |
|
16 |
|
17 package RelTransfer; |
|
18 |
|
19 use strict; |
|
20 use Utils; |
|
21 |
|
22 # |
|
23 # Constructor |
|
24 # |
|
25 |
|
26 sub New { |
|
27 my $invocant = shift; |
|
28 my $class = ref($invocant) || $invocant; |
|
29 my %args = @_; |
|
30 my $self = {iniData => $args{ini_data}, |
|
31 verbose => $args{verbose}, |
|
32 force => $args{force}, |
|
33 dummy => $args{dummy}, |
|
34 excludeSource => $args{excludeSource}, |
|
35 pgpPassPhrase => $args{passphrase} |
|
36 }; |
|
37 |
|
38 if($self->{excludeSource}){ |
|
39 PrintHeinousWarning(); |
|
40 } |
|
41 |
|
42 $self->{verbose} ||= 1 if $self->{dummy}; |
|
43 bless $self, $class; |
|
44 $self->Initialize(); |
|
45 return $self; |
|
46 } |
|
47 |
|
48 sub Initialize { |
|
49 my $self = shift; |
|
50 |
|
51 Utils::InitialiseTempDir($self->{iniData}); #create and initialize temp dir |
|
52 $self->{crypt} = $self->CreateCrypt(); #create a Crypt:: object |
|
53 $self->{remoteSite} = $self->CreateRemoteSite(); #create a RemoteSite:: object |
|
54 } |
|
55 |
|
56 sub PrintHeinousWarning { |
|
57 Utils::QueryUnsupportedTool(<<GUILTY, 0); # Set $reallyrun as 0 |
|
58 Warning: The use of the -e flag is for internal use only. Using the -e flag can corrupt an export archive if used incorrectly. Please ensure that the target export archive is specifically for non source releases. Export archives should not contain releases which contain both source and non source. |
|
59 |
|
60 Do you want to continue? (y/n) |
|
61 GUILTY |
|
62 } |
|
63 |
|
64 sub CreateCrypt { |
|
65 my $self = shift; |
|
66 |
|
67 my $module = 'Crypt::'.$self->{iniData}->PgpTool; |
|
68 eval "require $module"; |
|
69 my $crypt = $module->New(default_path => $self->{iniData}->PgpConfigPath(), |
|
70 verbose => $self->{verbose}); |
|
71 return $crypt; |
|
72 } |
|
73 |
|
74 sub CreateRemoteSite { |
|
75 my $self = shift; |
|
76 |
|
77 my $module = 'RemoteSite::'.$self->{iniData}->RemoteSiteType(); |
|
78 eval "require $module"; |
|
79 my $remote = $module->New(host => $self->{iniData}->RemoteHost(), |
|
80 username => $self->{iniData}->RemoteUsername(), |
|
81 password => $self->{iniData}->RemotePassword(), |
|
82 passive_mode => $self->{iniData}->PasvTransferMode(), |
|
83 resume_mode => $self->{iniData}->FtpServerSupportsResume(), |
|
84 proxy => $self->{iniData}->Proxy(), |
|
85 proxy_username => $self->{iniData}->ProxyUsername(), |
|
86 proxy_password => $self->{iniData}->ProxyPassword(), |
|
87 timeout => $self->{iniData}->FtpTimeout(), |
|
88 reconnects => $self->{reconnects}, |
|
89 max_export_volume_size => $self->{iniData}->MaxExportVolumeSize(), |
|
90 verbose => $self->{verbose}); |
|
91 return $remote; |
|
92 } |
|
93 |
|
94 # |
|
95 # Abstract methods |
|
96 # |
|
97 |
|
98 sub TransferRelease { |
|
99 my $self = shift; |
|
100 $self->HandleError("Call to abstract method ".ref($_[0])."::TransferRelease"); |
|
101 } |
|
102 |
|
103 # |
|
104 # Private |
|
105 # |
|
106 |
|
107 sub PathData { |
|
108 my $self = shift; |
|
109 return $self->{iniData}->PathData; |
|
110 } |
|
111 |
|
112 sub ReleaseExistsInLocalArchive { |
|
113 my $self = shift; |
|
114 my $comp = shift; |
|
115 my $ver = shift; |
|
116 |
|
117 my $path = $self->PathData->LocalArchivePathForExistingComponent($comp, $ver); # undef if component doesn't exist |
|
118 return ($path && -d $path); |
|
119 } |
|
120 |
|
121 sub ReleaseExistsOnRemoteSite { |
|
122 my $self = shift; |
|
123 my $comp = shift; |
|
124 my $ver = shift; |
|
125 |
|
126 my $relDir = $self->PathData->RemoteArchivePathForExistingComponent($comp, $ver, $self->{remoteSite}); |
|
127 return 0 unless $relDir; |
|
128 return 1; # if RemoteArchivePathForExistingComponent returns a true value, then it exists |
|
129 } |
|
130 |
|
131 sub CleanupTempDir { |
|
132 my $self = shift; |
|
133 my $tempDir = Utils::TempDir(); |
|
134 |
|
135 print "Cleaning \"$tempDir\"...\n" if ($self->{verbose} > 1); |
|
136 |
|
137 opendir(DIR, $tempDir) or die "Error: cannot open $tempDir\n"; |
|
138 my @allFiles = grep {$_ ne '.' and $_ ne '..'} map {"$tempDir/$_"} readdir DIR; |
|
139 closedir(DIR); |
|
140 unlink @allFiles; |
|
141 } |
|
142 |
|
143 sub HandleError { |
|
144 my $self = shift; |
|
145 my $errorString = shift; |
|
146 |
|
147 die "Error: $errorString\n"; |
|
148 } |
|
149 |
|
150 # |
|
151 # Destructor |
|
152 # |
|
153 |
|
154 sub DESTROY { |
|
155 my $self = shift; |
|
156 |
|
157 if (-e Utils::TempDir()) { |
|
158 Utils::RemoveTempDir(); |
|
159 } |
|
160 } |
|
161 |
|
162 1; |
|
163 |
|
164 __END__ |
|
165 |
|
166 =head1 NAME |
|
167 |
|
168 RelTransfer.pm - Base class for modules used to export and import releases |
|
169 |
|
170 =head1 DESCRIPTION |
|
171 |
|
172 A typical project involves many development teams working at different locations. To share releases between the various sites a central repositry (e.g typically an FTP server) is setup with each team transferring releases to and from this remote site. |
|
173 |
|
174 This module is the base class for modules used to export and import single releases between the local archive and the remote site. |
|
175 |
|
176 The export and import subclass modules must implement the abstract method C<TransferRelease> to perform the actual export/import of the release. |
|
177 |
|
178 =head1 KNOWN BUGS |
|
179 |
|
180 None |
|
181 |
|
182 =head1 COPYRIGHT |
|
183 |
|
184 Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
185 All rights reserved. |
|
186 This component and the accompanying materials are made available |
|
187 under the terms of the License "Eclipse Public License v1.0" |
|
188 which accompanies this distribution, and is available |
|
189 at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
190 |
|
191 Initial Contributors: |
|
192 Nokia Corporation - initial contribution. |
|
193 |
|
194 Contributors: |
|
195 |
|
196 Description: |
|
197 |
|
198 |
|
199 =cut |