|
1 #!perl |
|
2 # Copyright (c) 2007-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 IniData; |
|
23 use CommandController; |
|
24 use Cwd 'abs_path'; |
|
25 use Symbian::CBR::CreateDelta; |
|
26 use Symbian::CBR::ApplyDelta; |
|
27 use Symbian::CBR::Release::Manifest; |
|
28 use Carp; |
|
29 use File::Spec; |
|
30 |
|
31 # |
|
32 # Globals. |
|
33 # |
|
34 |
|
35 my $verbose = 0; |
|
36 my $overwrite = 0; |
|
37 my $noevalid = 0; |
|
38 my $nodelta = 0; |
|
39 my $iniData = IniData->New(); |
|
40 my $commandController = CommandController->New( $iniData, 'DeltaEnv' ); |
|
41 my $referenceComp; |
|
42 my $referenceVer; |
|
43 my $nominatedComp; |
|
44 my $nominatedVer; |
|
45 my $report; |
|
46 my $createDelta; |
|
47 my $applyDelta; |
|
48 my $releaseManifestFile; |
|
49 my $receivingArchive; |
|
50 my $pgpKey; |
|
51 my $deltaPackagePath; |
|
52 |
|
53 |
|
54 # |
|
55 # Main. |
|
56 # |
|
57 |
|
58 ProcessCommandLine(); |
|
59 |
|
60 # |
|
61 # Subs. |
|
62 # |
|
63 |
|
64 sub ProcessCommandLine { |
|
65 Getopt::Long::Configure ( "bundling" ); |
|
66 my $help; |
|
67 my $maxdeltasize; |
|
68 |
|
69 GetOptions( 'h' => \$help, 'o' => \$overwrite, 'v+' => \$verbose, 'noevalid+' => \$noevalid, 'nodelta+' => \$nodelta, 'c+' => \$createDelta, 'a+' => \$applyDelta, 'r+' => \$report, 'rb=s' => \$referenceComp, 'rv=s' => \$referenceVer, 'nb=s' => \$nominatedComp, 'nv=s' => \$nominatedVer, 'rm=s' => \$releaseManifestFile, 'ra=s' => \$receivingArchive, 'p=s' => \$pgpKey, 'dp=s' => \$deltaPackagePath, 'maxdelta=s' => \$maxdeltasize ); |
|
70 |
|
71 if ( $help ) { |
|
72 Usage(0); |
|
73 } |
|
74 elsif ( $report ) { |
|
75 generateReleaseManifest(); |
|
76 } |
|
77 elsif ($createDelta) { |
|
78 createDeltaEnv($maxdeltasize); |
|
79 } |
|
80 elsif ($applyDelta) { |
|
81 ReconstructEnv(); |
|
82 } |
|
83 else { |
|
84 print "Error: Invalid option.\n"; |
|
85 Usage(1); |
|
86 } |
|
87 } |
|
88 |
|
89 sub Usage { |
|
90 my $exitCode = shift; |
|
91 |
|
92 if ($report) { |
|
93 GenerateReleaseManifestUsage($exitCode); |
|
94 } |
|
95 if ($createDelta) { |
|
96 CreateDeltaUsage($exitCode); |
|
97 } |
|
98 if ($applyDelta) { |
|
99 ApplyDeltaUsage($exitCode); |
|
100 } |
|
101 |
|
102 Utils::PrintDeathMessage($exitCode, "\n |
|
103 |
|
104 options: |
|
105 |
|
106 -h help |
|
107 -r generate release manifest mode |
|
108 -c create delta mode |
|
109 -a apply delta mode |
|
110 -v verbose output |
|
111 -r -h generate release manifest mode help |
|
112 -c -h create delta mode help |
|
113 -a -h apply delta mode help \n" ); |
|
114 } |
|
115 |
|
116 sub GenerateReleaseManifestUsage { |
|
117 my $exitCode = shift; |
|
118 |
|
119 Utils::PrintDeathMessage($exitCode, "\nUsage: deltaenv -r [options] <component> <version> [report path] |
|
120 |
|
121 options: |
|
122 |
|
123 -h help |
|
124 -o overwrite existing release manifest file |
|
125 -v verbose output \n" ); |
|
126 } |
|
127 |
|
128 sub CreateDeltaUsage { |
|
129 my $exitCode = shift; |
|
130 |
|
131 Utils::PrintDeathMessage($exitCode, "\nUsage: deltaenv -c [options] --nb <nominated baseline> --nv <nominated version> [--rm <release manifest>|--rb <reference baseline> --rv <reference version> --ra <receiving archive>] -p <PGP key> [--dp <delta release package>] |
|
132 |
|
133 options: |
|
134 |
|
135 -h help |
|
136 -v verbose output |
|
137 -o overwrite existing delta release package |
|
138 --nodelta include whole files where modified (don't create deltas) |
|
139 --noevalid use raw binary comparison (don't use evalid) |
|
140 --nb <nominated baseline> nominated baseline component name |
|
141 --nv <nominated version> nominated baseline component version |
|
142 --rm <release manifest> release manifest file |
|
143 --rb <reference baseline> reference baseline component name |
|
144 --rv <reference version> reference baseline component version |
|
145 --ra <receiving archive> receiving archive path |
|
146 -p <PGP key> PGP key of recipient |
|
147 --maxdelta <max size> max size to delta (larger files treated as --nodelta) |
|
148 --dp <delta release package> delta release package path \n" ); |
|
149 } |
|
150 |
|
151 sub ApplyDeltaUsage { |
|
152 my $exitCode = shift; |
|
153 |
|
154 Utils::PrintDeathMessage($exitCode, "\nUsage: deltaenv -a [options] <delta release package> |
|
155 |
|
156 options: |
|
157 |
|
158 -h help |
|
159 -o overwrite existing components |
|
160 -v verbose output \n" ); |
|
161 } |
|
162 |
|
163 sub generateReleaseManifest { |
|
164 my $comp = shift @ARGV; |
|
165 my $ver = shift @ARGV; |
|
166 my $destinationManifestPath = shift @ARGV; |
|
167 unless ( defined $comp and defined $ver and $#ARGV == -1 ) { |
|
168 print "Error: Reference component and version must be specified.\n"; |
|
169 GenerateReleaseManifestUsage(1); |
|
170 } |
|
171 my $localArchive = $iniData->PathData->LocalArchivePathForExistingComponent($comp, $ver); |
|
172 die "Error: $comp $ver does not exist.\n" unless (defined $localArchive); |
|
173 |
|
174 if ($localArchive !~ s/\Q$comp\E[\\\/]\Q$ver\E([\\\/])?$//) { # Remove the component name |
|
175 die "Error: (INTERNAL) Unable to remove component information $comp $ver from the archive path $localArchive\n"; |
|
176 } |
|
177 |
|
178 my $archiveReleaseManifestDir = File::Spec->catdir($localArchive, ".cbr"); |
|
179 my $archiveFile = $comp."_".$ver."_manifest.xml"; |
|
180 $archiveFile = File::Spec->catfile($archiveReleaseManifestDir, $archiveFile); |
|
181 |
|
182 my $releaseManifest = Symbian::CBR::Release::Manifest->new( $iniData, $verbose ); |
|
183 unless ( defined $destinationManifestPath ) { |
|
184 $destinationManifestPath = Cwd::cwd(); |
|
185 } |
|
186 |
|
187 if (-e $archiveFile and !$overwrite) { |
|
188 $releaseManifest->Load($archiveFile); |
|
189 } |
|
190 else { |
|
191 $releaseManifest->GenerateManifest($comp, $ver); |
|
192 } |
|
193 |
|
194 if ($overwrite or !-e $archiveFile) { |
|
195 eval{ $releaseManifest->Save($archiveReleaseManifestDir);}; |
|
196 print "Warning: Not backing up manifest file in $archiveReleaseManifestDir path because $@" if($@); |
|
197 } |
|
198 |
|
199 $releaseManifest->Save( $destinationManifestPath ); |
|
200 } |
|
201 |
|
202 sub createDeltaEnv { |
|
203 my $maxdeltasize = shift; |
|
204 unless ( defined $nominatedComp and defined $nominatedVer and $#ARGV == -1 ) { |
|
205 print "Error: Invalid arguments\n"; |
|
206 CreateDeltaUsage(1); |
|
207 } |
|
208 unless (defined $releaseManifestFile or (defined $referenceComp and defined $referenceVer)) { |
|
209 print "Error: Invalid arguments\n"; |
|
210 CreateDeltaUsage(1); |
|
211 } |
|
212 |
|
213 # Parse max delta file size |
|
214 my $maxdeltabytes; |
|
215 if (defined $maxdeltasize) { |
|
216 if ($maxdeltasize =~ /^\d+$/) { |
|
217 $maxdeltabytes = $maxdeltasize; |
|
218 } elsif ($maxdeltasize =~ /^(\d+)k$/i) { |
|
219 $maxdeltabytes = $1*1024; |
|
220 } elsif ($maxdeltasize =~ /^(\d+)m$/i) { |
|
221 $maxdeltabytes = $1*1024*1024; |
|
222 } elsif ($maxdeltasize =~ /^(\d+)g$/i) { |
|
223 $maxdeltabytes = $1*1024*1024*1024; |
|
224 } else { |
|
225 die "Error: Option '--maxdelta ".$maxdeltasize."' is not a valid size (sizes must be in bytes, or have a K, M or G postfix)\n"; |
|
226 } |
|
227 } |
|
228 |
|
229 # Get a release manifest to represent the nominated baseline in the receiving archive |
|
230 my $deltaAllFiles; |
|
231 my $releaseManifest = Symbian::CBR::Release::Manifest->new( $iniData, $verbose ); |
|
232 if ( defined $releaseManifestFile) { |
|
233 $releaseManifestFile = File::Spec->rel2abs($releaseManifestFile); |
|
234 print "Reading $releaseManifestFile file.\n"; |
|
235 $releaseManifest->Load( $releaseManifestFile ); |
|
236 } |
|
237 elsif (defined $receivingArchive) { |
|
238 $releaseManifest->GenerateManifest($referenceComp, $referenceVer, $receivingArchive); |
|
239 } |
|
240 else { |
|
241 $deltaAllFiles = 1; |
|
242 } |
|
243 |
|
244 # Create the delta |
|
245 $referenceComp = $releaseManifest->{'baselineName'} unless (defined $referenceComp); |
|
246 $referenceVer = $releaseManifest->{'baselineVersion'} unless (defined $referenceVer); |
|
247 unless ( defined $deltaPackagePath ) { |
|
248 $deltaPackagePath = Cwd::cwd(); |
|
249 } |
|
250 my $packageZipFile = $referenceVer."_".$nominatedVer.".zip"; |
|
251 $packageZipFile = File::Spec->catfile($deltaPackagePath, $packageZipFile); |
|
252 die "Error: Delta release for $referenceVer and $nominatedVer is already present in $deltaPackagePath. Please use -o option to overwrite.\n" if (-e $packageZipFile and !$overwrite); |
|
253 my $createDelta = Symbian::CBR::CreateDelta->new( $iniData, $pgpKey, $releaseManifest, $verbose, $noevalid, $nodelta, $maxdeltabytes ); |
|
254 $createDelta->{deltaAllFiles} = 1 if ($deltaAllFiles); |
|
255 $createDelta->{exportAll} = 1 unless (defined $pgpKey); |
|
256 $createDelta->createDeltaEnv( $referenceComp, $referenceVer, $nominatedComp, $nominatedVer, $deltaPackagePath ); |
|
257 print "Successfully created deltas for baseline.\n"; |
|
258 } |
|
259 |
|
260 sub ReconstructEnv { |
|
261 my $zipFile = shift @ARGV; |
|
262 unless (defined $zipFile and $#ARGV == -1 ) { |
|
263 print "Error: Invalid arguments\n"; |
|
264 ApplyDeltaUsage(1); |
|
265 } |
|
266 print "Reconstructing Environment\n"; |
|
267 my $reconstructEnv = Symbian::CBR::ApplyDelta->new($iniData,$verbose); |
|
268 $reconstructEnv->ReconstructEnv($zipFile, $overwrite); |
|
269 print "Reconstructed baseline successfully.\n"; |
|
270 } |
|
271 |
|
272 |
|
273 __END__ |
|
274 |
|
275 =head1 NAME |
|
276 |
|
277 DeltaEnv - Creates and applies deltas for modified components between pair of baselines. |
|
278 |
|
279 =head1 SYNOPSIS |
|
280 |
|
281 options: |
|
282 |
|
283 -h help |
|
284 -r generate release manifest mode |
|
285 -c create delta mode |
|
286 -a apply delta mode |
|
287 -v verbose output |
|
288 -r -h generate release manifest mode help |
|
289 -c -h create delta mode help |
|
290 -a -h apply delta mode help |
|
291 |
|
292 |
|
293 Generate release manifest mode |
|
294 |
|
295 deltaenv -r [options] <component> <version> [report path] |
|
296 |
|
297 options: |
|
298 |
|
299 -h help |
|
300 -o overwrite existing release manifest file |
|
301 -v verbose output |
|
302 |
|
303 |
|
304 Create delta mode |
|
305 |
|
306 deltaenv -c [options] --nb <nominated baseline> --nv <nominated version> [--rm <release manifest>|--rb <reference baseline> --rv <reference version> --ra <receiving archive>] -p <PGP key> [--dp <delta release package>] |
|
307 |
|
308 options: |
|
309 |
|
310 -h help |
|
311 -v verbose output |
|
312 -o overwrite existing delta release package |
|
313 --nodelta include whole files where modified (don't create deltas) |
|
314 --noevalid use raw binary comparison (don't use evalid) |
|
315 --nb <nominated baseline> nominated baseline component name |
|
316 --nv <nominated version> nominated baseline component version |
|
317 --rm <release manifest> release manifest file |
|
318 --rb <reference baseline> reference baseline component name |
|
319 --rv <reference version> reference baseline component version |
|
320 --ra <receiving archive> receiving archive path |
|
321 -p <PGP key> PGP key of recipient |
|
322 --maxdelta <max size> max size to delta (larger files treated as --nodelta) |
|
323 --dp <delta release package> delta release package path |
|
324 |
|
325 |
|
326 Apply delta mode |
|
327 |
|
328 deltaenv -a [options] <delta release package> |
|
329 |
|
330 options: |
|
331 |
|
332 -h help |
|
333 -o overwrite existing components |
|
334 -v verbose output |
|
335 |
|
336 =head1 DESCRIPTION |
|
337 |
|
338 This command can be used in 3 modes: generate release manifest, create delta, and apply delta. |
|
339 |
|
340 Generate Release Manifest : |
|
341 Generates a release manifest file, which lists all files available in the reference baseline at the receiving archive. It is used in create delta mode, in order that it has an accurate representation of the reference baseline to make the delta against. |
|
342 |
|
343 The release manifest contains the list of components and their versions in the reference baseline environment. It also lists all the files in each component, and all the metadata files, and each file's size, timestamp and MD5 checksum. |
|
344 |
|
345 |
|
346 Create delta mode : |
|
347 Creates a smallest possible delta package, using which whole baseline can be reconstructed at the receiving site. this delta package contains deltas for modified files from reference version to the nominated version of a component, newly added files for the existing components, newly added components for the baseline and delta release manifest file. This delta package can be transferred by the user to receiving site instead of whole baseline. |
|
348 |
|
349 |
|
350 Apply delta mode : |
|
351 Reconstructs a nominated baseline using reference version and delta release package which is created in create delta mode. Using create delta and apply delta mode, amount of data to be transferred from sending site to receiving site can be reduced. |
|
352 |
|
353 |
|
354 =head1 KNOWN BUGS |
|
355 |
|
356 None. |
|
357 |
|
358 =head1 COPYRIGHT |
|
359 |
|
360 Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
361 All rights reserved. |
|
362 This component and the accompanying materials are made available |
|
363 under the terms of the License "Eclipse Public License v1.0" |
|
364 which accompanies this distribution, and is available |
|
365 at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
366 |
|
367 Initial Contributors: |
|
368 Nokia Corporation - initial contribution. |
|
369 |
|
370 Contributors: |
|
371 |
|
372 Description: |
|
373 |
|
374 |
|
375 =cut |