releasing/cbrtools/perl/CatData.pm
author lorewang
Wed, 01 Dec 2010 16:05:36 +0800
changeset 715 e0739b8406dd
parent 602 3145852acc89
permissions -rw-r--r--
Specify extenal tool with path
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 CatData;
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 Data::Dumper;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    21
use MrpData;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    22
use PathData;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    23
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    24
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    25
# Public.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    26
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    27
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    28
sub New {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    29
  my $pkg = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    30
  my $self = {};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    31
  bless $self, $pkg;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    32
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    33
  my $iniData = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    34
  my $fileToWriteTo = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    35
  my $mrpData = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    36
  my $category = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    37
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    38
  $self->{data}->{category} = $category;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    39
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    40
  foreach my $exportfile (keys %{$mrpData->ExportInfoForCat($category)}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    41
    my $destination = $mrpData->ExportSourceFileInfoForCat($category, $exportfile);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    42
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    43
    # Consider any mappings if defined in the reltools.ini file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    44
    if($iniData->HasMappings()){
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    45
      $destination = $iniData->PerformReverseMapOnFileName($destination);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    46
      $destination = Utils::RemoveSourceRoot($destination);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    47
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    48
    $self->{data}->{exportinfo}->{$exportfile} = $destination;
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
  # Used to write infomation store to to file named $fileToWriteTo
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    52
  $self->WriteToFile($fileToWriteTo);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    53
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    54
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    55
sub Open {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    56
  my $pkg = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    57
  my $self = {};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    58
  bless $self, $pkg;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    59
  $self->{iniData} = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    60
  $self->{comp} = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    61
  $self->{ver} = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    62
  $self->{category} = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    63
  $self->ReadFromFile();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    64
  return $self;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    65
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    66
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    67
sub Category {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    68
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    69
  die unless exists $self->{data}->{category};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    70
  return $self->{data}->{category};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    71
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    72
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    73
sub ExportInfo {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    74
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    75
  die unless exists $self->{data}->{exportinfo};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    76
  return $self->{data}->{exportinfo};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    77
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    78
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    79
sub ExportSource {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    80
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    81
  my $destination = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    82
  die unless exists $self->{data}->{exportinfo}->{$destination};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    83
  return $self->{data}->{exportinfo}->{$destination};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    84
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    85
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    86
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    87
# Private.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    88
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    89
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    90
sub WriteToFile {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    91
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    92
  my $fileToWriteTo = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    93
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    94
  if (-e $fileToWriteTo) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    95
    Utils::SetFileWritable($fileToWriteTo);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    96
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    97
  open (OUT, ">$fileToWriteTo") or die "Error: Couldn't open \"$fileToWriteTo\" for writing: $!\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    98
  print OUT Data::Dumper->Dump([$self->{data}], ['self->{data}']);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    99
  close (OUT);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   100
  Utils::SetFileReadOnly($fileToWriteTo);
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
sub ReadFromFile {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   104
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   105
  my $category = $self->{category};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   106
  my $pathData = $self->{iniData}->PathData;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   107
  my $comp = $self->{comp};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   108
  my $ver = $self->{ver};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   109
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   110
  my $relDir = $pathData->LocalArchivePathForExistingComponent($comp, $ver);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   111
  die "Error: \"$comp $ver\" does not exist\n" unless $relDir;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   112
  if (!-e "$relDir\\exports$category.txt") {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   113
    print "Info: Can't find \"$relDir\\exports$category.txt\" \"$comp $ver\" is an incompatible release\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   114
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   115
  else{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   116
    $self->{project} = $pathData->ComponentProject($comp, $ver);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   117
    unless (-e $relDir) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   118
      die "Error: $comp $ver does not exist\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   119
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   120
    my $file = "$relDir\\exports$category.txt";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   121
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   122
    open (IN, $file) or die "Error: Couldn't open \"$file\" for reading: $!\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   123
    local $/ = undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   124
    my $data = <IN>;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   125
    die "Error: Reldata in \"$relDir\" is blank" unless $data =~ (m/\S/);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   126
    eval ($data) or die "Error: Couldn't parse reldata in \"$relDir\"\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   127
    close (IN);
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
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   131
1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   132
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   133
=head1 NAME
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   134
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   135
CatData.pm - Provides an interface to data associated with categories for a release.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   136
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   137
=head1 DESCRIPTION
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   138
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   139
Stores the source and export location of export files in a release. All information is stored in a single file named F<catdata> within the release directory using the module Data::Dumper.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   140
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   141
=head1 INTERFACE
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   142
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   143
=head2 New
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   144
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   145
Creates a new C<CatData> object and corresponding data file. Expects to be passed a filename to write to, a C<MrpData> reference, and a category.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   146
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   147
=head2 Open
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   148
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   149
Creates a C<CatData> object from an existing data file. Expects to be passed an C<IniData> reference, a component name, a version and a category.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   150
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   151
=head2 Category
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   152
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   153
Returns the category value.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   154
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   155
=head2 ExportInfo
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   156
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   157
Returns the exportinfo.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   158
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   159
=head2 ExportSource
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   160
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   161
Expects an export destination. Returns the export source location.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   162
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   163
=head2 WriteToFile
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   164
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   165
Expects to be passed a filename which is used to write a F<catdata>.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   166
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   167
=head2 ReadFromFile
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   168
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   169
Enables a F<catdata> file to be read so that all infomation contained can be read.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   170
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   171
=head1 KNOWN BUGS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   172
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   173
None.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   174
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   175
=head1 COPYRIGHT
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   176
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   177
 Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   178
 All rights reserved.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   179
 This component and the accompanying materials are made available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   180
 under the terms of the License "Eclipse Public License v1.0"
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   181
 which accompanies this distribution, and is available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   182
 at the URL "http://www.eclipse.org/legal/epl-v10.html".
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   183
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   184
 Initial Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   185
 Nokia Corporation - initial contribution.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   186
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   187
 Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   188
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   189
 Description:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   190
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   191
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   192
=cut