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