releasing/cbrtools/perl/envmembership
changeset 602 3145852acc89
equal deleted inserted replaced
600:6d08f4a05d93 602:3145852acc89
       
     1 #!perl
       
     2 # Copyright (c) 2001-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 use strict;
       
    19 use FindBin;
       
    20 use lib "$FindBin::Bin";
       
    21 use Getopt::Long;
       
    22 use IniData;
       
    23 use RelData;
       
    24 use Utils;
       
    25 use CommandController;
       
    26 
       
    27 
       
    28 #
       
    29 # Globals.
       
    30 #
       
    31 
       
    32 my $verbose = 0;
       
    33 my $iniData = IniData->New();
       
    34 my $force;
       
    35 my $commandController = CommandController->New($iniData, 'EnvMembership');
       
    36 
       
    37 #
       
    38 # Main.
       
    39 #
       
    40 
       
    41 ProcessCommandLine();
       
    42 
       
    43 
       
    44 #
       
    45 # Subs.
       
    46 #
       
    47 
       
    48 sub ProcessCommandLine {
       
    49   Getopt::Long::Configure ("bundling");
       
    50   my $help;
       
    51   GetOptions("h" => \$help, "v+" => \$verbose, "f" => \$force);
       
    52 
       
    53   if ($help) {
       
    54     Usage(0);
       
    55   }
       
    56 
       
    57   # Functional description:
       
    58   # create reldata objects for each release of <environment>
       
    59   # for each release find if <component> is present in the environment
       
    60   # and if so if <version> matches the version in the environment.
       
    61   # if these conditions are met, place the current <environment> release id in 
       
    62   # an array and print the contents of the array at the end of the script
       
    63   #
       
    64   #
       
    65   if ($#ARGV == 2) {
       
    66     # Extract the command line arguments (Note: GetOptions() will have already
       
    67     # stripped out the options part of the command line
       
    68     my $component_name = shift @ARGV;
       
    69     my $component_version= shift @ARGV;
       
    70     my $env_name= shift @ARGV;
       
    71 		
       
    72     # Scalar variable $envRelDatas will contain a reference to an array of reldata
       
    73     # objects following this call.
       
    74     my $envRelDatas = RelData->OpenSet($iniData, $env_name, $verbose);
       
    75     my @outputTable;
       
    76     my @tableHeader = ("Component", "Version");
       
    77     push (@outputTable, \@tableHeader);
       
    78     foreach my $currentEnvRelData (@$envRelDatas) {
       
    79       my $currentEnv = $currentEnvRelData->Environment();
       
    80       # $currentEnv now contains a reference to a hash containing 
       
    81       # component name / version pairs for all the components that were
       
    82       # present in the current release of the environment component
       
    83       if ($currentEnv->{$component_name}) {
       
    84 	# component is present in the current environment
       
    85 	if ($currentEnv->{$component_name} eq $component_version) {
       
    86 	  # component version of interest is present in the current environment
       
    87 	  my @tableRow = ($currentEnvRelData->Component(),$currentEnvRelData->Version());
       
    88 	  push (@outputTable, \@tableRow);
       
    89 	}
       
    90       }
       
    91     }
       
    92     # print the environment versions in which componet version is present
       
    93     my $tableLength = @outputTable;
       
    94     if ($tableLength > 0) {
       
    95       $iniData->TableFormatter->PrintTable(\@outputTable);
       
    96     }
       
    97   } else {
       
    98     print "Error: Invalid number of arguments\n";
       
    99     Usage(1);
       
   100   }
       
   101 }
       
   102 
       
   103 sub Usage {
       
   104   my $exitCode = shift;
       
   105 
       
   106   Utils::PrintDeathMessage($exitCode, "\nUsage: envmembership [options] <component> <version> <environment>
       
   107 
       
   108 options:
       
   109 
       
   110 -h  help
       
   111 -f  (deprecated)
       
   112 -v  verbose output (-vv very verbose)\n");
       
   113 
       
   114 }
       
   115 
       
   116 __END__
       
   117 
       
   118 =head1 NAME
       
   119 
       
   120 EnvMembership - Returns the environments to which a particular component belongs
       
   121 
       
   122 =head1 SYNOPSIS
       
   123 
       
   124   envmembership [options] <component> <version> <environment>
       
   125 
       
   126 options:
       
   127 
       
   128   -h  help
       
   129   -f  (deprecated)
       
   130   -v  verbose output (-vv very verbose)
       
   131 
       
   132 =head1 DESCRIPTION
       
   133 
       
   134 Returns all the versions of a specified component for which a particular version of another specified component is present in its release environment. For example, to discover which release of a component called C<my_product> contains the component C<my_comp> at version C<my_ver>, type:
       
   135 
       
   136   envmembership my_comp my_ver my_product 
       
   137 
       
   138 =head1 STATUS
       
   139 
       
   140 Supported. If you find a problem, please report it to us.
       
   141 
       
   142 =head1 KNOWN BUGS
       
   143 
       
   144 None.
       
   145 
       
   146 =head1 COPYRIGHT
       
   147 
       
   148  Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
       
   149  All rights reserved.
       
   150  This component and the accompanying materials are made available
       
   151  under the terms of the License "Eclipse Public License v1.0"
       
   152  which accompanies this distribution, and is available
       
   153  at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
   154  
       
   155  Initial Contributors:
       
   156  Nokia Corporation - initial contribution.
       
   157  
       
   158  Contributors:
       
   159  
       
   160  Description:
       
   161  
       
   162 
       
   163 =cut