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