Subversion Repositories DevTools

Rev

Rev 2026 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
392 dpurdie 1
#! perl
2
########################################################################
5710 dpurdie 3
# Copyright (c) VIX TECHNOLOGY (AUST) LTD
392 dpurdie 4
#
5
# Module name   : jats.sh
6
# Module type   : Makefile system
7
# Compiler(s)   : n/a
8
# Environment(s): jats
9
#
10
# Description   : Create TAR files for all packages provided in a given release
11
#
12
#                 Walk compete dependency tree to locate all inconsistient packages
13
#                 Locates packages in dpkg_archive/deploy_archive
14
#                 Creates TAR files for packages
15
#
16
#                 Currently hard coded to Phase 2.2 - Part 4
17
#
18
# Usage:
19
#
20
# Version   Who      Date        Description
21
#
22
#......................................................................#
23
 
24
require 5.006_001;
25
use strict;
26
use warnings;
27
use JatsError;
28
use JatsSystem;
29
use Getopt::Long;
30
use Pod::Usage;                             # required for help support
31
use JatsRmApi;
32
 
33
use DBI;
34
 
35
my $VERSION = "1.2.3";                      # Update this
36
my $opt_verbose = 1;
37
my $opt_help = 0;
38
my $opt_manual;
39
my $opt_rtag_id = 4081;                     # Phase 2.2 - Part 4
40
my $RM_DB;
41
 
42
#
43
#   Package information
44
#
45
my %Package;
46
my @StrayPackages;
47
 
48
#-------------------------------------------------------------------------------
49
# Function        : Main Entry
50
#
51
# Description     :
52
#
53
# Inputs          :
54
#
55
# Returns         :
56
#
57
my $result = GetOptions (
58
                "help+"     => \$opt_help,          # flag, multiple use allowed
59
                "manual"    => \$opt_manual,        # flag
60
                "verbose+"  => \$opt_verbose,       # flag
61
                "rtag_id=s"  => \$opt_rtag_id,       # string
62
                );
63
 
64
#
65
#   Process help and manual options
66
#
67
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
68
pod2usage(-verbose => 1)  if ($opt_help == 2 );
69
pod2usage(-verbose => 2)  if ($opt_manual || ($opt_help > 2));
70
 
71
ErrorConfig( 'name'    =>'PLAY13' );
72
 
73
Error ("No RTAGID specified") unless ( $opt_rtag_id );
74
 
75
getPkgDetailsByRTAG_ID($opt_rtag_id);
76
LocateStrays();
77
LocatePackages();
78
#DebugDumpData ("Package", \%Package );
79
 
80
exit;
81
 
82
 
83
sub getPkgDetailsByRTAG_ID
84
{
85
    my ($RTAG_ID) = @_;
86
    my $foundDetails = 0;
87
    my (@row);
88
 
89
    # if we are not or cannot connect then return 0 as we have not found anything
90
    connectRM(\$RM_DB) unless ( $RM_DB );
91
 
92
    # First get details from pv_id
93
 
94
    my $m_sqlstr = "SELECT pv.PV_ID, pkg.PKG_NAME, pv.PKG_VERSION, pv.PKG_LABEL, pv.SRC_PATH, pv.BUILD_TYPE" .
95
                    " FROM RELEASE_CONTENT rc, PACKAGE_VERSIONS pv, PACKAGES pkg" .
96
                    " WHERE rc.RTAG_ID = $RTAG_ID AND rc.PV_ID = pv.PV_ID AND pv.PKG_ID = pkg.PKG_ID";
97
    my $sth = $RM_DB->prepare($m_sqlstr);
98
    if ( defined($sth) )
99
    {
100
        if ( $sth->execute( ) )
101
        {
102
            if ( $sth->rows )
103
            {
104
                while ( @row = $sth->fetchrow_array )
105
                {
106
                    my $pv_id = $row[0];
107
                    my $name = $row[1];
108
                    my $ver = $row[2];
109
                    my $label = $row[3] || '';
110
                    my $path = $row[4] || '';
111
 
112
                    $path =~ tr~\\/~/~s;
113
#print "$row[5] --";
114
#printf ( "%40s %15s %50s %s\n",  $name, $ver, $label, $path);
115
#printf ( "copy e:\\%s\\%s .\n",  $name, $ver, $label, $path);
116
#print "$name $ver\n";
117
                    $Package{$name}{$ver}{done} = 1;
118
                    $Package{$name}{$ver}{base} = 1;
119
                    GetDepends( $pv_id, $name, $ver );
120
                }
121
            }
122
            $sth->finish();
123
        }
124
    }
125
    else
126
    {
127
        Error("Prepare failure" );
128
    }
129
 
130
#    $RM_DB->disconnect() || Error ("Disconnect failed");
131
}
132
 
133
#-------------------------------------------------------------------------------
134
# Function        : GetDepends
135
#
136
# Description     : Extract the dependancies for a given package version
137
#
138
# Inputs          : $pvid
139
#
140
# Returns         :
141
#
142
sub GetDepends
143
{
144
    my ($pv_id, $name, $ver ) = @_;
145
 
146
    #
147
    #   Now extract the package dependacies
148
    #
149
    my $m_sqlstr = "SELECT pkg.PKG_NAME, pv.PKG_VERSION, pd.DPV_ID" .
150
                   " FROM PACKAGE_DEPENDENCIES pd, PACKAGE_VERSIONS pv, PACKAGES pkg" .
151
                   " WHERE pd.PV_ID = \'$pv_id\' AND pd.DPV_ID = pv.PV_ID AND pv.PKG_ID = pkg.PKG_ID";
152
    my $sth = $RM_DB->prepare($m_sqlstr);
153
    if ( defined($sth) )
154
    {
155
        if ( $sth->execute( ) )
156
        {
157
            if ( $sth->rows )
158
            {
159
                while ( my @row = $sth->fetchrow_array )
160
                {
161
#                    print "$name ===== @row\n";
162
                    my $name = $row[0];
163
                    my $ver = $row[1];
164
 
165
                    unless ( exists $Package{$name}{$ver}{done} )
166
                    {
167
                        $Package{$name}{$ver}{needed} = 1;
168
 
169
                        my @DATA = ($name, $ver, $row[2]);
170
                        push @StrayPackages, \@DATA;
171
                    }
172
                }
173
            }
174
            $sth->finish();
175
        }
176
    }
177
    else
178
    {
179
        Error("GetDepends:Prepare failure" );
180
    }
181
}
182
 
183
#-------------------------------------------------------------------------------
184
# Function        : LocateStrays
185
#
186
# Description     :
187
#
188
# Inputs          :
189
#
190
# Returns         :
191
#
192
sub LocateStrays
193
{
194
 
195
    while ( $#StrayPackages >= 0 )
196
    {
197
        my $DATA = pop @StrayPackages;
198
        my $name = $DATA->[0];
199
        my $ver = $DATA->[1];
200
        my $pv_id = $DATA->[2];
201
 
202
        next if ( exists $Package{$name}{$ver}{done} );
203
        GetDepends(  $pv_id, $name, $ver );
204
        $Package{$name}{$ver}{done} = 1;
205
    }
206
}
207
 
208
#-------------------------------------------------------------------------------
209
# Function        : LocatePackages
210
#
211
# Description     :
212
#
213
# Inputs          :
214
#
215
# Returns         :
216
#
217
sub LocatePackages
218
{
219
    open (OFILE, ">", "logfile.txt") || Error("Cannot open output file: logfile.txt");
220
    foreach my $pkg ( sort keys %Package )
221
    {
222
        foreach my $ver ( sort keys %{$Package{$pkg}} )
223
        {
224
            my $pdir;
225
            my $found = 0;
226
            foreach my $var ( 'GBE_DPKG', 'GBE_DPLY' )
227
            {
228
                my $dir = $ENV{$var};
229
                next unless ( -d $dir );
230
 
231
                $pdir = "$dir/$pkg/$ver";
232
                next unless ( -d $pdir );
233
                $found = 1;
234
                $Package{$pkg}{$ver}{dir} = $dir;
235
                last;
236
            }
237
            if ( $found )
238
            {
239
                print "Processing: $pkg, $ver, $pdir\n";
240
                my $rv = TarItUp( $pkg, $ver, $pdir );
241
                print "Error Processing: $pkg, $ver, $pdir\n" if $rv;
242
                print OFILE "Error Processing: $pkg, $ver, $pdir\n" if $rv;
243
            }
244
            else
245
            {
246
                print "Not Found:, $pkg, $ver\n" unless $found;
247
                print OFILE "Not Found:, $pkg, $ver\n" unless $found;
248
            }
249
        }
250
    }
251
 
252
    foreach my $pkg ( sort keys %Package )
253
    {
254
        foreach my $ver ( sort keys %{$Package{$pkg}} )
255
        {
256
            next if ( $Package{$pkg}{$ver}{base} );
257
 
258
            print "Inconsistient package: $pkg, $ver\n";
259
            print OFILE "Inconsistient package: $pkg, $ver\n";
260
 
261
        }
262
    }
263
 
264
    close OFILE;
265
}
266
 
267
#-------------------------------------------------------------------------------
268
# Function        : TarItUp
269
#
270
# Description     : Tar up a package
271
#
272
# Inputs          : $1  Name
273
#                   $2  Version
274
#                   $3  Source Dir
275
# Returns         :
276
#
277
sub TarItUp
278
{
279
    my ( $pkg, $ver, $pdir ) = @_;
280
 
281
    #
282
    #   Generate an output name
283
    #
284
    my $tname = "${pkg}_${ver}";
285
    $tname =~ s~\s~_~g;
286
    $tname =~ tr~\\/~_~s;
287
 
288
    my $rv = System ("tar" , '-cEf', "$tname.tar", $pdir);
289
    return $rv;
290
}