releasing/cbrtools/perl/RelTransfer/Import.pm
author Ross Qin <ross.qin@nokia.com>
Thu, 28 Oct 2010 11:18:50 +0800
changeset 667 a3b39a14147a
parent 602 3145852acc89
permissions -rw-r--r--
Remove the PrintingServices component from TB10.1 on wards(on behalf of dane.waby@nokia.com)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
602
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     1
# Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     2
# All rights reserved.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     3
# This component and the accompanying materials are made available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     4
# under the terms of the License "Eclipse Public License v1.0"
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     5
# which accompanies this distribution, and is available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     6
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     7
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     8
# Initial Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     9
# Nokia Corporation - initial contribution.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    10
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    11
# Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    12
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    13
# Description:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    14
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    15
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    16
# Description:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    17
# RelTransfer::Import.pm
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    18
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    19
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    20
package RelTransfer::Import;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    21
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    22
use strict;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    23
use Utils;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    24
use File::Copy;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    25
use File::Basename;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    26
use File::Path;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    27
use Cwd;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    28
use RelTransfer;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    29
use vars qw(@ISA);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    30
@ISA=("RelTransfer");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    31
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    32
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    33
# Constructor
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    34
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    35
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    36
sub Initialize {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    37
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    38
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    39
  $self->SUPER::Initialize();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    40
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    41
  #set the passphrase for decryption
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    42
  $self->SetPgpPassPhrase();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    43
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    44
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    45
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    46
# Public methods
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    47
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    48
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    49
sub TransferRelease {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    50
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    51
  my $comp = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    52
  my $ver = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    53
  my $noPassphraseRetry = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    54
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    55
  print "\nImporting $comp $ver...\n" if ($self->{verbose});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    56
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    57
  #check to see if ok to import
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    58
  if ($self->ReleaseExistsInLocalArchive($comp, $ver) and not $self->{force}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    59
    my $localReleaseDir = $self->PathData->LocalArchivePathForExistingComponent($comp, $ver);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    60
    my $reldatafile = File::Spec->catfile( $localReleaseDir,"reldata");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    61
    if (-f $reldatafile) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    62
      print "$comp $ver already exists in local archive\n" if ($self->{verbose});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    63
      return 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    64
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    65
    print "$comp $ver is corrupted - attempting to remove and re-import.\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    66
    my $origDir = cwd();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    67
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    68
    chdir(dirname($localReleaseDir)); #If you try to rmtree a UNC path the cwd must also be a UNC path
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    69
    rmtree ($localReleaseDir) or die "$localReleaseDir can't be deleted\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    70
    chdir($origDir);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    71
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    72
  unless ($self->ReleaseExistsOnRemoteSite($comp, $ver)) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    73
    die "Error: $comp $ver does not exist on remote site\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    74
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    75
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    76
  my $excludeRelease = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    77
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    78
  #Get remote release file, unzip, decrypt and move to local archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    79
  # We pass around the remote archive path because with the project-based
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    80
  # PathData scheme, the remote location might affect which local location
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    81
  # to put it in.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    82
  my $remoteDir = $self->PathData->RemoteArchivePathForExistingComponent($comp, $ver, $self->{remoteSite});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    83
  eval {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    84
    $self->GetZippedReleaseFile($comp, $ver, $remoteDir);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    85
    select STDOUT;$|=1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    86
    $self->UnzipReleaseFile($comp, $ver);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    87
    select STDOUT;$|=1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    88
    $self->DecryptReleaseFiles($comp, $ver, $noPassphraseRetry);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    89
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    90
    # DEF104279 - If the users key can decrypt the exclude.txt then the user is not able to recieve this release.  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    91
    opendir(DIR, Utils::TempDir()) or die "Error: cannot open Utils::TempDir()\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    92
    $excludeRelease = 1 if (grep /exclude.txt$/, readdir DIR);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    93
    closedir(DIR);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    94
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    95
    $self->MoveDecryptedFilesToArchive($comp, $ver, $remoteDir) if (!$excludeRelease);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    96
  };
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    97
  if ($@) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    98
    my $error = $@;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    99
    $self->CleanupTempDir();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   100
    my $localReleaseDir = $self->PathData->LocalArchivePathForImportingComponent($comp, $ver, $remoteDir);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   101
    if (-d $localReleaseDir) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   102
      my $origDir = cwd();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   103
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   104
      chdir(dirname($localReleaseDir)); #If you try to rmtree a UNC path the cwd must also be a UNC path
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   105
      rmtree ($localReleaseDir) or die "$localReleaseDir can't be deleted\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   106
      chdir($origDir);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   107
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   108
    die $error;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   109
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   110
  $self->CleanupTempDir();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   111
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   112
  print "$comp $ver successfully imported from remote site.\n" if ($self->{verbose} && !$excludeRelease);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   113
  return 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   114
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   115
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   116
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   117
# Private methods
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   118
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   119
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   120
sub GetZippedReleaseFile {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   121
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   122
  my $comp = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   123
  my $ver = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   124
  my $remoteDir = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   125
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   126
  my $localFile = Utils::TempDir()."/$comp$ver.zip";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   127
  my $remoteFile = "$remoteDir/$comp$ver.zip";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   128
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   129
  $self->{remoteSite}->GetFile($remoteFile, $localFile);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   130
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   131
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   132
sub UnzipReleaseFile {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   133
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   134
  my $comp = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   135
  my $ver = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   136
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   137
  if ($self->{verbose}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   138
    print "Unzipping $comp$ver.zip ...\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   139
  }	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   140
  my $tempDir = Utils::TempDir();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   141
  $tempDir =~ s/[\/\\]$//;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   142
  $tempDir .= "/";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   143
  my $zipName = File::Spec->catfile("$tempDir","$comp$ver.zip");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   144
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   145
  my $zip = Archive::Zip->new($zipName);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   146
  foreach my $member ($zip->members()) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   147
    my $filename=$member->fileName();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   148
    eval {Utils::ExtractFile($tempDir, $filename,$member, 0, 1, $self->{verbose})};  # 0 is being passed in because we are not validating 1 = Overwrite.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   149
    die "$@\n" if ($@); 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   150
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   151
  unlink $zipName;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   152
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   153
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   154
sub DecryptReleaseFiles {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   155
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   156
  my $comp = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   157
  my $ver = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   158
  my $noPassphraseRetry = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   159
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   160
  #build up list of pgp encrypted files in TEMP_DIR 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   161
  my $tempDir = Utils::TempDir();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   162
  opendir(TEMPDIR, $tempDir);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   163
  my @encryptedFiles = grep {/\.pgp$/} readdir TEMPDIR;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   164
  closedir(TEMPDIR);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   165
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   166
  my $noFilesDecrypted = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   167
 TRYAGAIN:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   168
  foreach my $encryptedFile (@encryptedFiles) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   169
    my ($decryptedFile) = ($encryptedFile =~ /(.+).pgp$/);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   170
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   171
    #set the passphrase for decryption
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   172
    $self->SetPgpPassPhrase();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   173
    # returns if it's already set
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   174
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   175
    if ($self->{verbose}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   176
      print "Decrypting $encryptedFile ... \n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   177
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   178
    eval {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   179
      $self->{crypt}->Decrypt("$tempDir/$encryptedFile", "$tempDir/$decryptedFile", $self->{pgpPassPhrase});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   180
    };
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   181
    if ($@) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   182
      if ($@ =~ /BAD_PASSPHRASE/i) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   183
	$@ =~ s/BAD_PASSPHRASE//;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   184
	print "Incorrect PGP passphrase\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   185
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   186
        if ($noPassphraseRetry) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   187
          die "\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   188
        }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   189
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   190
	$self->{pgpPassPhrase} = undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   191
	redo TRYAGAIN;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   192
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   193
      elsif ($@ =~ /NO_SECKEY/i) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   194
	# Do nothing - it's perfectly possible that we don't have access to certain release files, particularly
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   195
	# since the addition of 'exclude' keyword to ExportData.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   196
      }	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   197
      else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   198
	die $@;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   199
      }	
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   200
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   201
    else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   202
      $noFilesDecrypted = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   203
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   204
    unlink "$tempDir/$encryptedFile";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   205
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   206
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   207
  if ($noFilesDecrypted) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   208
    die "Error: Unable to decrypt any part of $comp $ver (see FAQ for more detail)\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   209
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   210
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   211
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   212
sub MoveDecryptedFilesToArchive {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   213
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   214
  my $comp = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   215
  my $ver = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   216
  my $remotedir = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   217
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   218
  if ($self->{verbose}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   219
    print "Moving release files to local archive ... \n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   220
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   221
  my $tempDir = Utils::TempDir(); 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   222
  opendir(DIR, $tempDir) or die "Error: cannot open $tempDir\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   223
  my @releaseFiles = grep {$_ ne '.' and $_ ne '..'} readdir DIR;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   224
  closedir(DIR);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   225
  if (grep(lc($_) eq "reldata", @releaseFiles)) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   226
    # Move the 'reldata' entry to the end
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   227
    @releaseFiles = grep(lc($_) ne "reldata", @releaseFiles);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   228
    push @releaseFiles, "reldata";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   229
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   230
  unless (@releaseFiles) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   231
    die; # If we've got this far, there should have been some files decyrpted.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   232
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   233
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   234
  #create release directory if doesnot exist
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   235
  my $localReleaseDir = $self->PathData->LocalArchivePathForImportingComponent($comp, $ver, $remotedir);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   236
  unless (-e $localReleaseDir) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   237
    Utils::MakeDir($localReleaseDir);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   238
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   239
  else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   240
    #clean the local release directory if it already exists
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   241
    opendir(DIR, $localReleaseDir) or die "Error: cannot open $localReleaseDir\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   242
    my @allFiles = grep {$_ ne '.' and $_ ne '..'} map {"$localReleaseDir/$_"} readdir DIR;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   243
    closedir(DIR);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   244
    unlink @allFiles;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   245
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   246
  foreach my $releaseFile (@releaseFiles) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   247
    move("$tempDir/$releaseFile", "$localReleaseDir/$releaseFile") or die "Error: Unable to move $tempDir/$releaseFile to $localReleaseDir/$releaseFile: $!";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   248
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   249
    Utils::SetFileReadOnly("$localReleaseDir/$releaseFile");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   250
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   251
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   252
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   253
sub SetPgpPassPhrase {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   254
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   255
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   256
  return if ($self->{pgpPassPhrase});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   257
  print "PGP passphrase: \n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   258
  $self->{pgpPassPhrase} = Utils::QueryPassword();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   259
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   260
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   261
1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   262
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   263
__END__
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   264
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   265
=head1 NAME
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   266
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   267
RelTransfer::Import.pm - Import releases from the remote site
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   268
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   269
=head1 SYNOPSIS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   270
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   271
 use RelTransfer::Import;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   272
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   273
 $importer = RelTransfer::Import->New(ini_data => $iniData,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   274
				      force => 1,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   275
				      verbose => 1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   276
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   277
 $importer->TransferRelease('componentname', 'componentversion');
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   278
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   279
=head1 DESCRIPTION
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   280
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   281
Implements the abstract TransferRelease method from the C<RelTransfer> base class module which transfers a release from the remote site to the local archive.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   282
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   283
=head1 INTERFACE
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   284
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   285
=head2 New
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   286
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   287
Passed an argument list in the form of hash key value pairs. The supported arguments are...
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   288
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   289
 ini_data    =>  $iniData_object
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   290
 force       =>  $force_integer
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   291
 verbose     =>  $verbosity_integer
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   292
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   293
Returns a reference to a C<RelTransfer::Import> object.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   294
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   295
=head2 TransferRelease
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   296
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   297
Passed a component name and version number. Performs the following steps:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   298
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   299
=over 4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   300
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   301
=item *
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   302
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   303
Check to see if the release can or needs to be imported. If the release already exists on the local archive or does not exist on the remote site then do not attempt to import 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   304
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   305
=item *
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   306
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   307
Get the release zip from the remote site
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   308
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   309
=item *
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   310
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   311
Unzip the release zip
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   312
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   313
=item *
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   314
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   315
Decrypt the release files (ie the reldata, source and binary zips)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   316
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   317
=item *
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   318
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   319
Move the release files to the local archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   320
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   321
=back
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   322
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   323
=head1 KNOWN BUGS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   324
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   325
None
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   326
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   327
=head1 COPYRIGHT
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   328
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   329
 Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   330
 All rights reserved.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   331
 This component and the accompanying materials are made available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   332
 under the terms of the License "Eclipse Public License v1.0"
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   333
 which accompanies this distribution, and is available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   334
 at the URL "http://www.eclipse.org/legal/epl-v10.html".
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   335
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   336
 Initial Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   337
 Nokia Corporation - initial contribution.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   338
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   339
 Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   340
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   341
 Description:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   342
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   343
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   344
=cut