releasing/cbrtools/perl/Cleaner.pm
author kelvzhu
Wed, 27 Oct 2010 16:03:51 +0800
changeset 662 60be34e1b006
parent 602 3145852acc89
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
602
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     1
# Copyright (c) 2002-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
use strict;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    18
use RelData;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    19
use File::Spec;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    20
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    21
package Cleaner;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    22
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    23
sub New {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    24
  my $class = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    25
  my $iniData = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    26
  my $remote = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    27
  my $verbose = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    28
  my $reallyClean = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    29
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    30
  die "Cleaner didn't get an inidata" unless $iniData;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    31
  die "Must tell Cleaner whether you want remote or local!!!" unless defined $remote;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    32
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    33
  my $self = {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    34
    iniData => $iniData,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    35
    remote => $remote,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    36
    verbose => $verbose,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    37
    reallyClean => $reallyClean,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    38
    force => 0,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    39
    relsToClean => {},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    40
    relsToKeep => {},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    41
    envsToKeep => {},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    42
    relsToKeepAfter => {},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    43
    envsToKeepAfter => {},
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    44
    keepAfter => undef,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    45
    cleanTo => undef,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    46
    remoteSite => undef,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    47
    cleaningSubroutine => undef,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    48
    expunge_already_cleaned => undef
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    49
  };
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    50
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    51
  bless $self, (ref $class || $class);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    52
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    53
  $self->{remoteSite} = $iniData->RemoteSite if ($self->{remote});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    54
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    55
  return $self;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    56
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    57
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    58
sub SetCleaningSubroutine {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    59
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    60
  my $cleaningsub = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    61
  $self->{cleaningSubroutine} = $cleaningsub;
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 SetFinishingSubroutine {
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
  $self->{finishingSubroutine} = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    67
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    68
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    69
sub SetRevertingSubroutine {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    70
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    71
  $self->{revertingSubroutine} = shift;
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 ProcessDescriptionLine {
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
  my $descriptionFile = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    77
  my $keyWord = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    78
  my @operand = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    79
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    80
  if ($keyWord =~ /^keep_env$/) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    81
    unless ($#operand == 1) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    82
      die "Error: Incorrect number of arguments to \'$keyWord\' keyword in \"$descriptionFile\"\nSyntax: keep_env <component> <version>\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    83
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    84
    my $comp = lc($operand[0]);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    85
    my $ver = lc($operand[1]);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    86
    if (exists $self->{envsToKeep}->{$comp}->{$ver}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    87
      die "Error: Environment \"$comp $ver\" specified for keeping more than once\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    88
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    89
    $self->{envsToKeep}->{$comp}->{$ver} = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    90
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    91
  elsif ($keyWord =~ /^keep_rel$/) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    92
    unless ($#operand == 1) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    93
      die "Error: Incorrect number of arguments to \'$keyWord\' keyword in \"$descriptionFile\"\nSyntax: keep_rel <component> <version>\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    94
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    95
    my $comp = lc($operand[0]);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    96
    my $ver = lc($operand[1]);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    97
    $self->{relsToKeep}->{$comp}->{$ver} = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    98
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    99
  elsif ($keyWord eq "keep_recent_env") {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   100
    unless ($#operand == 1) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   101
      die "Error: Incorrect number of arguments to \'$keyWord\' keyword in \"$descriptionFile\"\nSyntax: keep_recent_env <component> <num_days>\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   102
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   103
    my $comp = lc($operand[0]);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   104
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   105
    my $time = $operand[1];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   106
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   107
    if ($time !~ /^\d+$/) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   108
      die "Error: The <num_days> argument for the '$keyWord' keyword must be a positive number\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   109
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   110
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   111
    $time = time - ($time * 60 * 60 * 24);   
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   112
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   113
    if (exists $self->{envsToKeepAfter}->{$comp}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   114
      die "Error: keep_recent_env called more than once on component \'$comp\' in \"$descriptionFile\"\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   115
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   116
    $self->{envsToKeepAfter}->{$comp} = $time;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   117
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   118
  elsif ($keyWord eq "keep_recent_rel") {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   119
    if ($#operand == 0) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   120
      if (defined $self->{keepAfter}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   121
        die "Error: \'$keyWord\' keyword used more than once with no component name in \"$descriptionFile\"\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   122
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   123
      else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   124
        my $keepAfter = $operand[0];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   125
        
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   126
        if ($keepAfter !~ /^\d+$/) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   127
          die "Error: The <num_days> argument for the '$keyWord' keyword must be a positive number\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   128
        }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   129
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   130
        $self->{keepAfter} = time - ($keepAfter * 60 * 60 * 24);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   131
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   132
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   133
    elsif ($#operand == 1) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   134
      my $comp = lc($operand[0]);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   135
      my $time = $operand[1];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   136
      
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   137
      if ($time !~ /^\d+$/) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   138
        die "Error: Error: The <num_days> argument for the '$keyWord' keyword must be a positive number\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   139
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   140
      
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   141
      $time = time - ($time * 60 * 60 * 24);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   142
      if (exists $self->{relsToKeepAfter}->{$comp}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   143
        die "Error: keep_recent_rel called more than once on component \'$comp\' in \"$descriptionFile\"\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   144
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   145
      $self->{relsToKeepAfter}->{$comp} = $time;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   146
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   147
    else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   148
      die "Error: Incorrect number of arguments to \'$keyWord\' keyword in \"$descriptionFile\"\nSyntax: keep_recent_rel [<component>] <num_days>\n";
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
  elsif ($keyWord =~ /^keep_recent$/) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   152
    unless ($#operand == 0) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   153
      die "Error: Incorrect number of arguments to \'$keyWord\' keyword in \"$descriptionFile\"\nSyntax: keep_recent <num_days>\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   154
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   155
    if (defined $self->{keepAfter}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   156
      die "Error: \'$keyWord\' keyword used more than once in \"$descriptionFile\"\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   157
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   158
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   159
    my $keepAfter = $operand[0];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   160
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   161
    if ($keepAfter !~ /^\d+$/) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   162
      die "Error: The <num_days> argument for the '$keyWord' keyword must be a positive number\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   163
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   164
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   165
    $self->{keepAfter} = time - ($keepAfter * 60 * 60 * 24);  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   166
    print "Warning: The 'keep_recent' keyword has been deprecated, as it\nresults in broken environments. You can use the 'keep_recent_rel' keyword\nwithout a component name instead if you really mean this, to get rid of this\nwarning.\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   167
  } elsif ($keyWord =~ /^force$/) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   168
    if (@operand) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   169
      die "Error: Incorrect number of arguments to \'$keyWord\' keyword in \"$descriptionFile\"\nSyntax: force\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   170
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   171
    if ($self->{force}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   172
      die "Error: \'$keyWord\' keyword used more than once in \"$descriptionFile\"\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   173
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   174
    $self->{force} = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   175
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   176
  else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   177
    return 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   178
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   179
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   180
  return 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   181
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   182
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   183
sub PrintEnvsToKeep {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   184
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   185
  print "Environments to keep:\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   186
  $self->TablePrintHash($self->{envsToKeep});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   187
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   188
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   189
# Reads {envsToKeep} and {envsToKeepAfter}, updates {envsToKeep}, and fills out {relsToKeep}.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   190
sub FindRelsToKeep {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   191
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   192
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   193
  # Convert envsToKeepAfter into a list of envsToKeep
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   194
  foreach my $keepEnv (keys %{$self->{envsToKeepAfter}}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   195
    my $keepAfter = $self->{envsToKeepAfter}->{$keepEnv};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   196
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   197
    foreach my $ver (keys %{$self->{archiveComponents}->{$keepEnv}}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   198
      # Check reldata time
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   199
      my $timestamp;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   200
      if ($self->{remote}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   201
        my $file = $self->{iniData}->PathData->RemoteArchivePathForExistingComponent($keepEnv, $ver, $self->{iniData}->RemoteSite);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   202
        die "Failed to find path for \"$keepEnv\" \"$ver\"\n" unless $file;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   203
        $file .= "/$keepEnv$ver.zip";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   204
        $timestamp = $self->{remoteSite}->FileModifiedTime($file);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   205
        
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   206
      } elsif (-e File::Spec->catfile($self->GetPathForExistingComponent($keepEnv, $ver), 'reldata')) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   207
        my $relData = RelData->Open($self->{iniData}, $keepEnv, $ver, $self->{verbose});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   208
        $timestamp = $relData->ReleaseTime();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   209
      } else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   210
        next;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   211
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   212
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   213
      if ($timestamp >= $keepAfter) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   214
        $self->{envsToKeep}->{$keepEnv}->{$ver} = 1; # It's new; keep it
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   215
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   216
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   217
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   218
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   219
  # Convert envsToKeep into a list of relsToKeep
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   220
  foreach my $thisComp (sort(keys %{$self->{envsToKeep}})) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   221
    foreach my $thisVer (sort(keys %{$self->{envsToKeep}->{$thisComp}})) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   222
      if ($self->{verbose}) { print "Reading release data from $thisComp $thisVer...\n"; }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   223
   
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   224
      my $thisCompPath = $self->{iniData}->PathData->LocalArchivePathForExistingComponent($thisComp, $thisVer);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   225
     
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   226
      if ($thisCompPath) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   227
        $thisCompPath = File::Spec->catfile($thisCompPath, 'reldata'); 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   228
      } else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   229
        if ($self->{remote}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   230
          die "Error: Unable to continue since cleanremote requires a corresponding version of '$thisComp $thisVer' in your local archive(s).  Please check that your CBR configuration file is in order and is pointing to the correct location for your local archive(s).  Failing this you will need to ensure you have a copy of '$thisComp $thisVer' in one of your configured local archives\n";      
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   231
        } else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   232
          die "Internal error:  Release not found in local archive when attempting to get environment for kept component\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   233
        }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   234
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   235
      
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   236
      if (-e $thisCompPath) {  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   237
        my $thisRelData = RelData->Open($self->{iniData}, $thisComp, $thisVer, $self->{verbose});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   238
        my $thisRelEnv = $thisRelData->Environment();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   239
   
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   240
        foreach my $compToKeep (keys %{$thisRelEnv}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   241
          my $verToKeep = $thisRelEnv->{$compToKeep};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   242
          $self->{relsToKeep}->{lc($compToKeep)}->{lc($verToKeep)} = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   243
          delete $self->{archiveComponents}->{$compToKeep}->{$verToKeep}; # saves time when finding components to remove
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   244
        }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   245
      } elsif ($self->{remote}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   246
        die "Error: Unable to continue because the environment for '$thisComp $thisVer' could not be identified (corrupt release; missing reldata file)\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   247
      } else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   248
        print "Warning: Unable to identify the environment for '$thisComp $thisVer'. This may result in additional component releases being cleaned from the archive.  (Corrupt release; missing reldata file)\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   249
      }
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
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   254
sub Clean {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   255
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   256
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   257
  # remoteSite may be defined, or it may not...
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   258
  # If not, then this will operate on the local archive  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   259
  foreach my $archiveComponent (@{$self->{iniData}->PathData->ListComponents($self->{remoteSite})}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   260
    map {$self->{archiveComponents}->{$archiveComponent}->{$_} = 1} $self->{iniData}->PathData->ListVersions($archiveComponent, $self->{remoteSite});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   261
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   262
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   263
  $self->FindRelsToKeep();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   264
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   265
  if ($self->{verbose} > 1) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   266
    print "Releases to keep:\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   267
    $self->TablePrintHash($self->{relsToKeep});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   268
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   269
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   270
  $self->FindRelsToClean();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   271
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   272
  if (%{$self->{relsToClean}}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   273
    print "About to clean the following releases:\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   274
    $self->TablePrintHash($self->{relsToClean});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   275
    if ($self->Query("Continue?")) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   276
      $self->CleanReleases();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   277
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   278
    else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   279
      print "Aborting...\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   280
      exit;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   281
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   282
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   283
  else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   284
    print "Nothing to clean\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   285
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   286
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   287
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   288
# Walks the archive, filling out %relsToClean with releases that are not present in %relsToKeep.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   289
sub FindRelsToClean {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   290
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   291
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   292
  select STDOUT; $|=1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   293
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   294
  foreach my $thisArchComp (keys %{$self->{archiveComponents}}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   295
    foreach my $ver (keys %{$self->{archiveComponents}->{$thisArchComp}}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   296
      $self->CheckComp($thisArchComp, $ver);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   297
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   298
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   299
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   300
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   301
sub CheckComp {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   302
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   303
  my $comp = lc(shift);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   304
  my $thisVer = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   305
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   306
  unless (exists $self->{relsToKeep}->{$comp}->{lc($thisVer)}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   307
    my $timestamp;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   308
    if ($self->{remote}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   309
      my $file = $self->{iniData}->PathData->RemoteArchivePathForExistingComponent($comp, $thisVer, $self->{iniData}->RemoteSite);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   310
      die "Failed to find path for \"$comp\" \"$thisVer\"\n" unless $file;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   311
      $file .= "/$comp$thisVer.zip";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   312
      $timestamp = $self->{remoteSite}->FileModifiedTime($file);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   313
    } elsif (-e File::Spec->catfile($self->GetPathForExistingComponent($comp, $thisVer), 'reldata')) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   314
          my $relData = RelData->Open($self->{iniData}, $comp, $thisVer, $self->{verbose});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   315
          $timestamp = $relData->ReleaseTime();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   316
    } elsif (!$self->{reallyClean}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   317
          print "Warning: $comp $thisVer is not a complete release in " . $self->GetPathForExistingComponent($comp, $thisVer) . '.' .
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   318
          "\nThe component may be in the process of being released into the archive or it may be corrupt." .
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   319
          "\nRe-run with the -r option to remove this release from the archive.\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   320
          return;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   321
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   322
    else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   323
          $self->{relsToClean}->{$comp}->{lc($thisVer)} = $thisVer;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   324
          return;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   325
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   326
         
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   327
    if ($self->{keepAfter} && $timestamp >= $self->{keepAfter}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   328
      print "Not cleaning $comp $thisVer - too new\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   329
      return;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   330
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   331
    if (exists($self->{relsToKeepAfter}->{$comp}) && $timestamp >= $self->{relsToKeepAfter}->{$comp}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   332
      print "Not cleaning $comp $thisVer - too new\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   333
      return;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   334
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   335
    $self->{relsToClean}->{$comp}->{lc($thisVer)} = $thisVer;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   336
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   337
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   338
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   339
sub TablePrintHash {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   340
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   341
  my $hash = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   342
  my @tableData;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   343
  foreach my $thisComp (sort keys %{$hash}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   344
    foreach my $thisVer (sort keys %{$hash->{$thisComp}}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   345
      push (@tableData, [$thisComp, $thisVer]);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   346
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   347
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   348
  $self->{iniData}->TableFormatter->PrintTable(\@tableData);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   349
  print "\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   350
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   351
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   352
sub CleanReleases {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   353
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   354
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   355
  my $cleaningsub = $self->{cleaningSubroutine};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   356
  die "No execution sub provided" unless ref $cleaningsub;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   357
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   358
  my $failed = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   359
  my $cleaned = {};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   360
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   361
  print "Cleaning...\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   362
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   363
  foreach my $thisComp (sort keys %{$self->{relsToClean}}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   364
    foreach my $thisVer (sort values %{$self->{relsToClean}->{$thisComp}}) { # use values to get correct case
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   365
      my $path = $self->GetPathForExistingComponent($thisComp, $thisVer);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   366
      if (!defined($path)) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   367
        print "Unable to get path for $thisComp $thisVer: possible disconnection of FTP site?\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   368
        $failed = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   369
        last;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   370
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   371
      elsif (&$cleaningsub($thisComp, $thisVer, $path)) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   372
        # Cleaning worked
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   373
        $cleaned->{$thisComp}->{lc($thisVer)} = [$thisVer, $path];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   374
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   375
      else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   376
        print "Unable to delete $thisComp $thisVer from $path\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   377
        $failed = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   378
        last;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   379
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   380
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   381
    if ($failed) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   382
      last;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   383
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   384
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   385
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   386
  if ($failed) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   387
    my $revertsub = $self->{revertingSubroutine};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   388
    if (ref $revertsub) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   389
      # Attempt to roll back
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   390
      print "Warning: Cleaning failed. Rolling back...\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   391
      $failed = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   392
      foreach my $undoComp (sort keys %$cleaned) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   393
	my @vers = map( $_->[0], values %{$cleaned->{$undoComp}} );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   394
        foreach my $undoVer (sort @vers) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   395
          my $path = $cleaned->{$undoComp}->{lc($undoVer)}->[1];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   396
          if (!&$revertsub($undoComp, $undoVer, $path)) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   397
            $failed = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   398
	  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   399
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   400
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   401
      if ($failed) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   402
        die "Warning: Cleaning failed and rollback also failed - the archive may have been left in an indeterminate state\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   403
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   404
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   405
    else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   406
      # No rollback routine
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   407
      die "Warning: Cleaning failed - the archive may have been left in an indeterminate state\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   408
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   409
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   410
  else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   411
    my $finishingsub = $self->{finishingSubroutine};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   412
    if (ref $finishingsub) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   413
      # Finish the job
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   414
      foreach my $thisComp (sort keys %{$cleaned}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   415
	my @vers = map( $_->[0], values %{$cleaned->{$thisComp}} );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   416
        foreach my $thisVer (sort @vers) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   417
          my $path = $cleaned->{$thisComp}->{lc($thisVer)}->[1];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   418
          if (!&$finishingsub($thisComp, $thisVer, $path)) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   419
            print "Warning: Failed to complete cleaning of $thisComp at version $thisVer\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   420
            $failed = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   421
          }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   422
        }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   423
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   424
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   425
    if (!$failed) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   426
      print "Cleaning complete.\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   427
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   428
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   429
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   430
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   431
sub GetPathForExistingComponent {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   432
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   433
  my $thisComp = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   434
  my $thisVer = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   435
  my $path;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   436
  if ($self->{remote}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   437
    $path = $self->{iniData}->PathData->RemoteArchivePathForExistingComponent($thisComp, $thisVer, $self->{remoteSite});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   438
  } else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   439
    $path = $self->{iniData}->PathData->LocalArchivePathForExistingComponent($thisComp, $thisVer);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   440
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   441
  return $path;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   442
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   443
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   444
sub Query {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   445
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   446
  my $msg = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   447
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   448
  if ($self->{force}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   449
    print "Skipping question \"$msg\" because of \"force\" keyword - assuming \"yes\"\n" if ($self->{verbose});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   450
    return 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   451
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   452
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   453
  print "$msg [yes/no] ";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   454
  my $response = <STDIN>;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   455
  chomp $response;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   456
  return ($response =~ m/^y/i);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   457
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   458
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   459
1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   460
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   461
__END__
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   462
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   463
=head1 NAME
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   464
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   465
Cleaner.pm - A module to clean an archive
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   466
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   467
=head1 DESCRIPTION
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   468
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   469
A module to clean an archive. Supposed to implement the common bits between C<cleanlocalarch> and C<cleanremote>, but the first of those commands has been temporarily suspended. The basic plan is: let it process the lines of your cleaning description file, then give it a subroutine to operate on the releases that should be cleaned. It will do the intervening stages of working out what releases should be kept, and which should be clean.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   470
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   471
=head1 INTERFACE
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   472
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   473
=head2 New
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   474
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   475
Pass it an IniData object, and a 0 or 1 to indicate whether it should act locally or remotely. If it's acting remotely, it will get a RemoteSite object from the IniData object.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   476
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   477
=head2 SetCleaningSubroutine
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   478
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   479
Pass in a reference to a subroutine to actually do the first phase of cleaning. The subroutine will be passed the component name, the version number and the path. If this phase passes, the optional finishing routine will be called next. If it fails at any point, the reverting routine (if defined) will be called on each component which was 'cleaned'.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   480
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   481
=head2 SetFinishingSubroutine
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   482
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   483
Pass in a reference to a 'finishing' subroutine to complete the cleaning (see L<SetCleaningSubroutine|setcleaningsubroutine>). If this routine has not been called then no finishing routine will be set up, and the clean will be said to have completed once the first phase is done. The finishing subroutine will be passed the component name, the version number and the path.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   484
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   485
=head2 SetRevertingSubroutine
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   486
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   487
Pass in a reference to a 'reverting' subroutine to undo any 'cleaned' components (see L<SetCleaningSubroutine|setcleaningsubroutine>). If this routine has not been called then the cleaner will not attempt to revert changes if cleaning fails. The reverting subroutine will be passed the component name, the version number and the (original) path.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   488
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   489
=head2 ProcessDescriptionLine
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   490
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   491
This should be passed the name of the description file (for error messages only), then a keyword, then an array of operands. It will interpret lines keep_rel, keep_env, force, and keep_recent. If it understands a line it returns 1; otherwise it returns 0.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   492
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   493
=head2 PrintEnvsToKeep
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   494
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   495
This just prints a list of the environments it is going to keep.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   496
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   497
=head2 Clean
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   498
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   499
This actually does the cleaning. It first finds the releases to keep, then finds the releases to clean, then runs the cleaning subroutine for each one.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   500
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   501
=head1 KNOWN BUGS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   502
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   503
None.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   504
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   505
=head1 COPYRIGHT
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   506
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   507
 Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   508
 All rights reserved.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   509
 This component and the accompanying materials are made available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   510
 under the terms of the License "Eclipse Public License v1.0"
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   511
 which accompanies this distribution, and is available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   512
 at the URL "http://www.eclipse.org/legal/epl-v10.html".
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   513
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   514
 Initial Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   515
 Nokia Corporation - initial contribution.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   516
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   517
 Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   518
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   519
 Description:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   520
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   521
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   522
=cut