Subversion Repositories DevTools

Rev

Rev 7300 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7300 Rev 7304
Line 50... Line 50...
50
 
50
 
51
#
51
#
52
#   Constants
52
#   Constants
53
#
53
#
54
my $CONFFILE = '.bomGen';
54
my $CONFFILE = '.bomGen';
-
 
55
my $BOMFILE = '.bomCots';
55
my $MANIFEST = 'MANIFEST.json';
56
my $MANIFEST = 'MANIFEST.json';
56
my $TFVARS   = 'MANIFEST.tf';
57
my $TFVARS   = 'MANIFEST.tf';
57
 
58
 
58
#
59
#
59
#   Globals
60
#   Globals
Line 129... Line 130...
129
#   Non Filter operations
130
#   Non Filter operations
130
#   Must supply an rtagid
131
#   Must supply an rtagid
131
Error("Need --rtagid", "Example: -rtagid=2362" )
132
Error("Need --rtagid", "Example: -rtagid=2362" )
132
    unless ($opt_rtagid);
133
    unless ($opt_rtagid);
133
 
134
 
-
 
135
Error("No Filters defined.", "Add filters before creating BOM") 
-
 
136
    unless ( @confFilters );
-
 
137
 
134
#
138
#
135
#   This command is destined to be used in a directory where group permissions
139
#   This command is destined to be used in a directory where group permissions
136
#   are important. Ensure that the user is not killing group access
140
#   are important. Ensure that the user is not killing group access
137
#
141
#
138
umask 0002;
142
umask 0002;
Line 205... Line 209...
205
            $data->{version} = $2;
209
            $data->{version} = $2;
206
            $data->{prj} = $3;
210
            $data->{prj} = $3;
207
            $data->{arch} = $4;
211
            $data->{arch} = $4;
208
            $data->{type} = $5;
212
            $data->{type} = $5;
209
            $data->{arch} =~ s~_[PD]~~;
213
            $data->{arch} =~ s~_[PD]~~;
-
 
214
            $alias = join('.', $data->{name}, $data->{prj}, $data->{arch}, $data->{type} );
210
        }
215
        }
211
        elsif ( $file =~ m~^(.*)-($pv)\.(.*)\.(rpm)$~i)
216
        elsif ( $file =~ m~^(.*)-($pv)\.(.*)\.(rpm)$~i)
212
        {
217
        {
213
            # COTS package
218
            # COTS package
214
            $data->{name} = $1;
219
            $data->{name} = $1;
Line 254... Line 259...
254
        #
259
        #
255
        #   Create a nice alias
260
        #   Create a nice alias
256
        #       ERG -> VIX  (not done)
261
        #       ERG -> VIX  (not done)
257
        #       All lowercase
262
        #       All lowercase
258
        #
263
        #
259
        $alias = join ('.', $data->{name}, $data->{prj}, $data->{type});
264
        $alias = join ('.', $data->{name}, $data->{prj}, $data->{type} ) unless defined $alias;
260
        $alias = lc ($alias);
265
        $alias = lc ($alias);
261
        #$alias =~ s~^erg~vix~;
266
        #$alias =~ s~^erg~vix~;
262
        #$alias =~ s~^vix~vix-~;
267
        #$alias =~ s~^vix~vix-~;
263
        #$alias =~ s~^vix--~vix-~;
268
        #$alias =~ s~^vix--~vix-~;
264
        push (@edup, join( ' : ', $alias, $file ,$bomInfo->{files}{$alias}{fullname})  ) if exists $bomInfo->{files}{$alias};
269
        push (@edup, join( ' : ', $alias, $file ,$bomInfo->{files}{$alias}{fullname})  ) if exists $bomInfo->{files}{$alias};
265
 
270
 
266
        delete $data->{type};
271
        delete $data->{type};
267
        $bomInfo->{files}{$alias} = $data;
272
        $bomInfo->{files}{$alias} = $data;
-
 
273
#Debug0("Alias: $file-> $alias");
268
    }
274
    }
269
 
275
 
270
    ReportError ("Cannot extract file metadata from:", @elist)  if (@elist);
276
    ReportError ("Cannot extract file metadata from:", @elist)  if (@elist);
271
    ReportError ("Duplicate aliases for:", @edup)  if (@edup);
277
    ReportError ("Duplicate aliases for:", @edup)  if (@edup);
272
    ErrorDoExit();
278
    ErrorDoExit();
Line 373... Line 379...
373
        push (@filelist, $dstFile) unless (exists $bomList{$dstFile} );
379
        push (@filelist, $dstFile) unless (exists $bomList{$dstFile} );
374
    }
380
    }
375
 
381
 
376
    if ( @filelist)
382
    if ( @filelist)
377
    {
383
    {
378
        Message ("Delete execess files", @filelist );
384
        Verbose ("Delete execess files", @filelist );
379
        unless ( defined($opt_test) )
385
        unless ( defined($opt_test) )
380
        {
386
        {
381
            foreach my $file ( @filelist )
387
            foreach my $file ( @filelist )
382
            {
388
            {
383
                Verbose("Delete: $file...");
389
                Verbose2("Delete: $file...");
384
                if ( unlink("$opt_rootdir/$file") ne 1 )
390
                if ( unlink("$opt_rootdir/$file") ne 1 )
385
                {
391
                {
386
                    Warning("Failed to delete: $file. ($!)");
392
                    Warning("Failed to delete: $file. ($!)");
387
                }
393
                }
388
            }
394
            }
Line 488... Line 494...
488
sub LoadFilterConfig
494
sub LoadFilterConfig
489
{
495
{
490
    if ( -f "$opt_rootdir/$CONFFILE" )
496
    if ( -f "$opt_rootdir/$CONFFILE" )
491
    {
497
    {
492
        Message("Loading Config File");
498
        Message("Loading Config File");
493
 
-
 
494
        local $/;
-
 
495
        open(my $fh, "<$opt_rootdir/$CONFFILE") || Error("Failed to open config file");
-
 
496
        my $json_text = <$fh>;
-
 
497
        my $perl_scalar = decode_json( $json_text );
499
        my $perl_scalar = ReadJsonFile("$opt_rootdir/$CONFFILE");
498
        Error ("Invalid format in Config file")
500
        Error ("Invalid format in Config file")
499
            unless (ref($perl_scalar->{filters}) eq 'ARRAY');
501
            unless (ref($perl_scalar->{filters}) eq 'ARRAY');
500
 
502
 
501
        push (@confFilters, @{$perl_scalar->{filters}});
503
        push (@confFilters, @{$perl_scalar->{filters}});
502
        push (@confFiles, @{$perl_scalar->{keptfiles}}) if exists ($perl_scalar->{keptfiles});
504
        push (@confFiles, @{$perl_scalar->{keptfiles}}) if exists ($perl_scalar->{keptfiles});
503
        close($fh);
-
 
504
    }
505
    }
505
}
506
}
506
 
507
 
507
#-------------------------------------------------------------------------------
508
#-------------------------------------------------------------------------------
-
 
509
# Function        : ReadJsonFile 
-
 
510
#
-
 
511
# Description     : Read a JSON file and return the data 
-
 
512
#
-
 
513
# Inputs          : $fname  - Name of the file to read 
-
 
514
#
-
 
515
# Returns         : Ref to the JSON 
-
 
516
#
-
 
517
sub ReadJsonFile
-
 
518
{
-
 
519
    my ($fname) = @_;
-
 
520
    local $/;
-
 
521
    open(my $fh, $fname ) || Error("Failed to open $fname. $!");
-
 
522
    my $json_text = <$fh>;
-
 
523
    my $perl_scalar = decode_json( $json_text );
-
 
524
    close($fh);
-
 
525
 
-
 
526
    return $perl_scalar;
-
 
527
}
-
 
528
 
-
 
529
#-------------------------------------------------------------------------------
-
 
530
# Function        : WriteJsonFile 
-
 
531
#
-
 
532
# Description     : Write data into a file as JSON
-
 
533
#
-
 
534
# Inputs          : $fname  - Name of file to write
-
 
535
#                   $data   - Ref to data to write 
-
 
536
#
-
 
537
# Returns         : Will not return on error
-
 
538
#
-
 
539
sub WriteJsonFile
-
 
540
{
-
 
541
    my ($fname, $data) = @_;
-
 
542
    FileCreate ($fname, to_json( $data, { ascii => 1, pretty => 1 }));
-
 
543
}
-
 
544
 
-
 
545
 
-
 
546
#-------------------------------------------------------------------------------
508
# Function        : ProcessFilterArgs
547
# Function        : ProcessFilterArgs
509
#
548
#
510
# Description     : Process the filter based arguments 
549
# Description     : Process the filter based arguments 
511
#
550
#
512
# Inputs          : 
551
# Inputs          : 
Line 517... Line 556...
517
{
556
{
518
    my $filterArgSeen;
557
    my $filterArgSeen;
519
    my $writeConf;
558
    my $writeConf;
520
 
559
 
521
 
560
 
522
    unless ( @confFilters )
-
 
523
    {
-
 
524
        Error("No Filters defined.", "Add filters before creating BOM");
-
 
525
    }
-
 
526
 
561
 
527
    if ( @opt_addFilters )
562
    if ( @opt_addFilters )
528
    {
563
    {
529
        Message ("Adding command line filters to the release config file");
564
        Message ("Adding command line filters to the release config file");
530
        foreach my $element (@opt_addFilters) {
565
        foreach my $element (@opt_addFilters) {
Line 568... Line 603...
568
        Verbose ("Write config file");
603
        Verbose ("Write config file");
569
 
604
 
570
        #
605
        #
571
        #   Add known files
606
        #   Add known files
572
        #
607
        #
573
        UniquePush (\@confFiles, $CONFFILE, $MANIFEST, $TFVARS);
608
        UniquePush (\@confFiles, $CONFFILE, $BOMFILE, $MANIFEST, $TFVARS);
574
 
609
 
575
        my $config;
610
        my $config;
576
        push @{$config->{filters}},@confFilters;
611
        push @{$config->{filters}},@confFilters;
577
        push @{$config->{keptfiles}},@confFiles;
612
        push @{$config->{keptfiles}},@confFiles;
578
        FileCreate ("$opt_rootdir/$CONFFILE", to_json( $config, { ascii => 1, pretty => 1 }));
613
        WriteJsonFile("$opt_rootdir/$CONFFILE",$config);
579
    }
614
    }
580
 
615
 
581
    #
616
    #
582
    #   Display information to the user
617
    #   Display information to the user
583
    #
618
    #
Line 703... Line 738...
703
#
738
#
704
# Returns         : 
739
# Returns         : 
705
#
740
#
706
sub GetPackageData
741
sub GetPackageData
707
{
742
{
708
    my $m_sqlstr =  "SELECT p.PKG_NAME, pv.PKG_VERSION" .
743
    my $m_sqlstr =  "SELECT p.PKG_NAME, " .
-
 
744
                    " pv.PKG_VERSION, " .
-
 
745
                    " l.name " .
709
                    " FROM package_versions pv, RELEASE_CONTENT rc, PACKAGES p" .
746
                    "FROM package_versions pv, " .
-
 
747
                    " RELEASE_MANAGER.RELEASE_CONTENT rc, " .
-
 
748
                    " RELEASE_MANAGER.PACKAGES p, " .
-
 
749
                    " RELEASE_MANAGER.LICENCING pl, " .
-
 
750
                    " RELEASE_MANAGER.LICENCES l " .
710
                    " WHERE rc.rtag_id = " . $opt_rtagid .
751
                    "WHERE rc.rtag_id     = $opt_rtagid " .
711
                    " AND rc.pv_id = pv.pv_id" .
752
                    " AND rc.pv_id         = pv.pv_id " .
712
                    " and p.PKG_ID = pv.pkg_id" .
753
                    " AND p.PKG_ID         = pv.pkg_id " .
713
                    " and pv.IS_DEPLOYABLE = 'Y'";
754
                    " AND pv.IS_DEPLOYABLE = 'Y' " .
-
 
755
                    " AND pl.PV_ID(+)      = pv.pv_id " .
-
 
756
                    " AND pl.LICENCE       = l.LICENCE(+)" ;
714
#                    " and ( pv.IS_DEPLOYABLE = 'Y' or upper( p.PKG_NAME) like 'ERG%' or upper( p.PKG_NAME) like 'VIX%' )";
757
#                    " and ( pv.IS_DEPLOYABLE = 'Y' or upper( p.PKG_NAME) like 'ERG%' or upper( p.PKG_NAME) like 'VIX%' )";
715
 
758
 
-
 
759
 
-
 
760
 
716
    my ( $PKG_NAME, $PKG_VERSION );
761
    my ( $PKG_NAME, $PKG_VERSION, $LICENSE );
717
    my $sth = $DM_DB->prepare($m_sqlstr);
762
    my $sth = $DM_DB->prepare($m_sqlstr);
718
    if ( defined($sth) )
763
    if ( defined($sth) )
719
    {
764
    {
720
        if ( $sth->execute( ) )
765
        if ( $sth->execute( ) )
721
        {
766
        {
722
            if ( $sth->rows )
767
            if ( $sth->rows )
723
            {
768
            {
724
                while ( ( $PKG_NAME, $PKG_VERSION ) = $sth->fetchrow_array )
769
                while ( ( $PKG_NAME, $PKG_VERSION, $LICENSE ) = $sth->fetchrow_array )
725
                {
770
                {
726
                    Verbose ("Deployable: $PKG_NAME, $PKG_VERSION");
771
                    Verbose ("Deployable: $PKG_NAME, $PKG_VERSION");
727
                    my $pkgDir = "$ENV{GBE_DPKG}/$PKG_NAME";
772
                    my $pkgDir = "$ENV{GBE_DPKG}/$PKG_NAME";
728
                    my $srcDir = "$ENV{GBE_DPKG}/$PKG_NAME/$PKG_VERSION";
773
                    my $srcDir = "$ENV{GBE_DPKG}/$PKG_NAME/$PKG_VERSION";
729
                    my $dstDir = $opt_rootdir;
774
                    my $dstDir = $opt_rootdir;
Line 742... Line 787...
742
                                next unless ( -f $srcPath );
787
                                next unless ( -f $srcPath );
743
                                $foundFiltered = 1;
788
                                $foundFiltered = 1;
744
                                $filtersUsed{$filter} = 1;
789
                                $filtersUsed{$filter} = 1;
745
                                my $dstFile = basename($srcPath);
790
                                my $dstFile = basename($srcPath);
746
                                my $srcFile = $srcPath;
791
                                my $srcFile = $srcPath;
747
                                $srcFile =~ s~^$srcDir/~~;
792
                                ReportError("File provided by multiple packages: $dstFile") if exists ($bomList{$dstFile});
748
                                $bomList{$srcFile}{path} = $srcPath;
793
                                $bomList{$dstFile}{path} = $srcPath;
749
                                $bomList{$srcFile}{package} = $PKG_NAME;
794
                                $bomList{$dstFile}{package} = $PKG_NAME;
750
                                $bomList{$srcFile}{version} = $PKG_VERSION;
795
                                $bomList{$dstFile}{version} = $PKG_VERSION;
-
 
796
                                $bomList{$dstFile}{license} = $LICENSE || '';
751
                            }
797
                            }
752
                        }
798
                        }
753
 
799
 
754
                        # if no files found using filters then issue warning
800
                        # if no files found using filters then issue warning
755
                        Warning("No Files found for Package Version $PKG_NAME/$PKG_VERSION using supplied filters") 
801
                        Warning("No Files found for Package Version $PKG_NAME/$PKG_VERSION using supplied filters") 
Line 798... Line 844...
798
    }
844
    }
799
    else
845
    else
800
    {
846
    {
801
        Error("Prepare failure", $sth->errstr(), $m_sqlstr );
847
        Error("Prepare failure", $sth->errstr(), $m_sqlstr );
802
    }
848
    }
-
 
849
 
-
 
850
    #
-
 
851
    #   Report Commercial packages
-
 
852
    #   Write out a file to contain the list of COTS files
-
 
853
    #
-
 
854
    my @Commercial;
-
 
855
    foreach my $file (sort keys %bomList)
-
 
856
    {
-
 
857
        next unless ($bomList{$file}{license} =~ m ~^Commercial~);
-
 
858
        $bomList{$file}{cots} = 1;
-
 
859
        push @Commercial, $file;
-
 
860
    }
-
 
861
    Message ("Commercial software packages:", @Commercial);
-
 
862
    my $data;
-
 
863
    $data->{COTS} = \@Commercial;
-
 
864
    WriteJsonFile ("$opt_rootdir/$BOMFILE", $data);
-
 
865
 
-
 
866
    ErrorDoExit();
803
}
867
}
804
 
868
 
805
#-------------------------------------------------------------------------------
869
#-------------------------------------------------------------------------------
806
#   Documentation
870
#   Documentation
807
#
871
#