releasing/cbrtools/perl/EnvData
changeset 607 378360dbbdba
parent 602 3145852acc89
equal deleted inserted replaced
591:22486c9c7b15 607:378360dbbdba
       
     1 #!perl
       
     2 # Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of the License "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 # 
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 # 
       
    12 # Contributors:
       
    13 # 
       
    14 # Description:
       
    15 # 
       
    16 #
       
    17 
       
    18 
       
    19 use strict;
       
    20 use FindBin;
       
    21 use lib "$FindBin::Bin";
       
    22 use Getopt::Long;
       
    23 use IniData;
       
    24 use EnvDb;
       
    25 use CommandController;
       
    26 
       
    27 my ($remove, $mrpName, $verbose, $comp, $forceRemove);
       
    28 
       
    29 my $iniData = IniData->New();
       
    30 my $commandController = CommandController->New($iniData, 'EnvData');
       
    31 
       
    32 ProcessCommandLine();
       
    33 
       
    34 my $envDb = EnvDb->Open($iniData, $verbose);
       
    35 
       
    36 if ($remove) {
       
    37     RemoveEntryFromDB();
       
    38 }
       
    39 elsif (!$mrpName) {
       
    40     DisplayInformation();
       
    41 }
       
    42 else {
       
    43     AddEntryToDB();
       
    44 }
       
    45 
       
    46 sub ProcessCommandLine {
       
    47     Getopt::Long::Configure ("bundling");
       
    48     
       
    49     my $help;
       
    50     GetOptions("h" => \$help, "r" => \$remove, "m=s" => \$mrpName, "v+" => \$verbose, "f" => \$forceRemove);
       
    51     
       
    52     if ($help) {
       
    53         Usage(0);
       
    54     }
       
    55 
       
    56     $comp = lc(shift @ARGV);
       
    57 
       
    58     if (scalar @ARGV) {
       
    59             print "Error: Invalid number of arguments\n";
       
    60             Usage(1);
       
    61         }    
       
    62     elsif ($remove && $mrpName) {
       
    63         print "Error: Can not specify -m and -r options together\n";
       
    64         Usage(1);
       
    65     }
       
    66     elsif (($remove || $mrpName) && !$comp) {
       
    67         print "Error: You must specify a component name\n";
       
    68         Usage(1);       
       
    69     }
       
    70 }
       
    71 
       
    72 sub Usage {
       
    73   my $exitCode = shift;
       
    74 
       
    75   Utils::PrintDeathMessage($exitCode, "\nUsage: envdata [options] <component>
       
    76 EnvData is used for adding components to the evironment database...
       
    77   
       
    78 options:
       
    79 
       
    80 -h             help
       
    81 -m <mrp_name>  specify a new mrp file name
       
    82 -v             verbose output (-vv very verbose)\n");
       
    83 }
       
    84 
       
    85 sub AddEntryToDB {
       
    86     Utils::CheckExists($mrpName);
       
    87     Utils::AbsoluteFileName(\$mrpName);
       
    88     
       
    89     if($iniData->HasMappings()) {
       
    90       $mrpName = $iniData->PerformReverseMapOnFileName($mrpName);
       
    91     }
       
    92     
       
    93     $mrpName = Utils::RemoveSourceRoot($mrpName);
       
    94     
       
    95     if ($envDb->ComponentExistsInDatabase($comp) && $envDb->Status($comp) != EnvDb::STATUS_INFORMATION_ONLY) {
       
    96         die "EnvData can only be used to update non-installed components\n";
       
    97     }
       
    98 
       
    99     $envDb->SetVersion($comp, '__info__');
       
   100     $envDb->SetStatus($comp, EnvDb::STATUS_INFORMATION_ONLY);
       
   101     $envDb->GenerateEmptySignature($comp, '__info__');
       
   102 
       
   103     $envDb->SetMrpName($comp, $mrpName);
       
   104     
       
   105     print "Entry for $comp added to the environment database\n";
       
   106 }
       
   107 
       
   108 sub RemoveEntryFromDB {
       
   109     if ($envDb->ComponentExistsInDatabase($comp) && $envDb->Status($comp) != EnvDb::STATUS_INFORMATION_ONLY) {
       
   110         die "EnvData can only be used to update non-installed components\n";
       
   111     }
       
   112 
       
   113     my $ver = $envDb->Version($comp, 1);
       
   114     
       
   115     if (defined $ver) {
       
   116         if ($forceRemove) {
       
   117             $envDb->SetVersion($comp, undef);
       
   118         }
       
   119         else {
       
   120             print "Remove environment database entry for $comp? [y/n] ";
       
   121             my $response = <STDIN>;
       
   122             chomp $response;
       
   123             if ($response =~ /^y$/i) {
       
   124                 $envDb->SetVersion($comp, undef);
       
   125             }
       
   126             else {
       
   127                 die "Remove aborted\n";
       
   128             }
       
   129         }
       
   130     }
       
   131     else {
       
   132         die "Error: No information for $comp exists in the environment database\n";
       
   133     }
       
   134 }
       
   135 
       
   136 sub DisplayInformation {
       
   137     my $versionInfo = $envDb->VersionInfo(1);
       
   138     
       
   139     my $tableData = [["Component", "Status", "MRP"]];
       
   140     
       
   141     if ($comp) {
       
   142         if (exists $versionInfo->{$comp}) {
       
   143             push @{$tableData}, [$comp, EnvDb::StatusString($envDb->Status($comp)), $envDb->MrpName($comp)];
       
   144         }
       
   145     }
       
   146     else {
       
   147         foreach my $entry (sort keys %{$versionInfo}) {
       
   148                 push @{$tableData}, [$entry, EnvDb::StatusString($envDb->Status($entry)), $envDb->MrpName($entry)];
       
   149         }
       
   150     }
       
   151 
       
   152     if (scalar(@{$tableData}) > 1) {
       
   153         print "\n";
       
   154         $iniData->TableFormatter->PrintTable($tableData, 1);
       
   155     }
       
   156     else {
       
   157         print "No information exists in the environment database". ($comp ? " for $comp" : '') ."\n";        
       
   158     }
       
   159 }
       
   160 
       
   161 
       
   162 =head1 NAME
       
   163 
       
   164 EnvData
       
   165 
       
   166 =head1 SYNOPSIS
       
   167 
       
   168   envdata [options] [<component>]
       
   169 
       
   170 options:
       
   171   -h             help
       
   172   -m <mrp_name>  specify a new mrp file name
       
   173   -v             verbose output (-vv very verbose)
       
   174   -r             remove entry from database
       
   175   -f             force removal from database (no confirmation prompt)\n");
       
   176 
       
   177 =head1 DESCRIPTION
       
   178 
       
   179 Displays the information contained within the environment database.  Can also add
       
   180 and delete information about components which are not installed.  This is particularly
       
   181 useful for when IPR information needs to be obtained from MRP files, but the MRP file
       
   182 locations are not known to the CBR Tools as the components are not already part of
       
   183 the environment, for example during the overnight build process.
       
   184 
       
   185 
       
   186 =head1 KNOWN BUGS
       
   187 
       
   188 None.
       
   189 
       
   190 =head1 COPYRIGHT
       
   191 
       
   192  Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
   193  All rights reserved.
       
   194  This component and the accompanying materials are made available
       
   195  under the terms of the License "Eclipse Public License v1.0"
       
   196  which accompanies this distribution, and is available
       
   197  at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
   198  
       
   199  Initial Contributors:
       
   200  Nokia Corporation - initial contribution.
       
   201  
       
   202  Contributors:
       
   203  
       
   204  Description:
       
   205  
       
   206 
       
   207 =cut