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