Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
392 dpurdie 1
########################################################################
5710 dpurdie 2
# Copyright (c) VIX TECHNOLOGY (AUST) LTD
392 dpurdie 3
#
4
# Module name   : jats.sh
5
# Module type   : Makefile system
6
# Compiler(s)   : n/a
7
# Environment(s): jats
8
#
9
# Description   : Get package information
10
#                 for a package name and version as specified on the
11
#                 command line.
12
#
13
#                 Determine the package id
14
#                 Locate all packages that have the same package name
15
#                 Create a hash of previous versions
16
#                 Create a JPG showing the version history
17
#
18
#......................................................................#
19
 
20
require 5.006_001;
21
use strict;
22
use warnings;
23
use JatsError;
24
use JatsRmApi;
25
 
26
 
27
#use Data::Dumper;
28
use Cwd;
29
use DBI;
30
use Getopt::Long;
31
use Pod::Usage;                             # required for help support
32
my $RM_DB;
33
 
34
my $opt_package;
35
 
36
################################################################################
37
#   Global data
38
#
39
my $VERSION = "1.0.0";
40
my %ReleasePackages;            # Packages in the release
41
my %BuildPackages;              # Packages for this build
42
my $last_pv_id;
43
my $pkg_id;
44
my %versions;
45
 
46
 
47
#
48
#   Options
49
#
50
my $opt_help = 0;
51
my $opt_manual = 0;
52
my $opt_verbose = 0;
53
 
54
my $result = GetOptions (
55
                "help+"     => \$opt_help,          # flag, multiple use allowed
56
                "manual"    => \$opt_manual,        # flag
57
                "verbose+"  => \$opt_verbose,       # flag
58
                );
59
 
60
#
61
#   Process help and manual options
62
#
63
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
64
pod2usage(-verbose => 1)  if ($opt_help == 2 );
65
pod2usage(-verbose => 2)  if ($opt_manual || ($opt_help > 2));
66
 
67
#
68
#   Configure the error reporting process now that we have the user options
69
#
70
ErrorConfig( 'name'    =>'PLAY9c',
71
             'verbose' => $opt_verbose );
72
 
73
unless ( $ARGV[0] )
74
{
75
    Error( "Specify a package as 'name'" );
76
}
77
$opt_package = $ARGV[0];
78
Verbose( "Base Package: $opt_package");
79
 
80
#
81
#   Body of the process
82
#
83
GetPkgIdByName ( $opt_package );
84
GetData_by_pkg_id ( $pkg_id );
85
 
86
#
87
# Process the 'versions' hash and add back references
88
#
89
 
90
#
91
#   Find start
92
#   Entry with no previous
93
#
94
foreach my $entry ( keys(%versions) )
95
{
96
    foreach ( @{ $versions{$entry}{next}} )
97
    {
98
        $versions{$_}{last} = $entry;
99
    }
100
}
101
my @startPoints;
102
my $last_entry = 0;
103
foreach my $entry ( keys(%versions) )
104
{
105
    unless ( exists $versions{$entry}{last} )
106
    {
107
        push @startPoints, $entry;
108
    }
109
 
110
    if ( $entry > $last_entry )
111
    {
112
        $last_entry = $entry;
113
    }
114
}
115
 
116
#
117
#   Walk backwards from the LAST entry and mark the main path through the tree
118
#
119
my $entry = $last_entry;
120
while ( $entry )
121
{
122
    $versions{$entry}{'main'} = 1;
123
    $entry = $versions{$entry}{last};
124
}
125
 
126
DebugDumpData ("Versions", \%versions );
127
DebugDumpData ("Starts", \@startPoints );
128
 
129
#
130
#   Ordered by PVID. Which will be creation date
131
#   as they are created sequentially.
132
#
133
foreach my $entry (sort {$versions{$a}{version} cmp $versions{$b}{version}} keys(%versions) )
134
{
135
    print GetVname($entry)," $versions{$entry}{version}\n";
136
}
137
 
138
 
139
my $filebase = "$ARGV[0]_versions";
140
open (FH, ">$filebase.dot" ) or die "Cannot open output";
141
print FH "digraph world {\n";
142
#print FH "\trankdir=LR;\n";
143
print FH "\tnode[fontsize=24];\n";
144
 
145
sub GetVname
146
{
147
    my ($entry) = @_;
148
    my $me = $versions{$entry}{vname};
149
    unless ( $me )
150
    {
151
        $me = 'Unknown-' . $entry;
152
    }
153
    return $me;
154
}
155
 
156
foreach my $entry ( sort keys(%versions) )
157
{
158
    my @versions;
159
    my $me = GetVname($entry);
160
    foreach ( @{ $versions{$entry}{next}} )
161
    {
162
        push @versions, GetVname( $_);
163
    }
164
 
165
    print FH "\t", pentry($me)  ," -> { ", plist ( ' ; ', @versions ), " }\n";
166
#    print FH "\t", pentry($me)  ,"[label=\"$me\\nmain\"];\n" if ($versions{$entry}{main});
167
    print FH "\t", pentry($me)  ,"[shape=rectangle];\n" if ($versions{$entry}{main});
168
 
169
}
170
 
171
 
172
print FH "\n};\n";
173
close FH;
174
 
175
#
176
#   Convert DOT to a SVG
177
#
178
print "Generating graphical images\n";
179
system( "dot $filebase.dot -Tjpg -o$filebase.jpg" );  # -v
180
system( "dot $filebase.dot -Tsvg -o$filebase.svg" );  # -v
181
 
182
#
183
#   Display a list of terminal packages
184
#   These are packages that are not used by any other package
185
#
186
print "\n";
187
print "Generated: $filebase.dot\n";
188
print "Generated: $filebase.jpg\n";
189
print "Generated: $filebase.svg\n";
190
 
191
 
192
exit 0;
193
 
194
 
195
#-------------------------------------------------------------------------------
196
# Function        : GetPkgIdByName
197
#
198
# Description     :
199
#
200
# Inputs          : pkg_name
201
#
202
# Returns         :
203
#
204
sub GetPkgIdByName
205
{
206
    my ( $pkg_name ) = @_;
207
    my (@row);
208
    my $pv_id;
209
 
210
    #
211
    #   Establish a connection to Release Manager
212
    #
213
    connectRM(\$RM_DB) unless ( $RM_DB );
214
 
215
    #
216
    #   Extract data from Release Manager
217
    #
218
    my $m_sqlstr = "SELECT pkg.PKG_NAME, pkg.PKG_ID" .
219
                   " FROM RELEASE_MANAGER.PACKAGES pkg" .
220
                   " WHERE pkg.PKG_NAME = \'$pkg_name\'";
221
 
222
    my $sth = $RM_DB->prepare($m_sqlstr);
223
    if ( defined($sth) )
224
    {
225
        if ( $sth->execute( ) )
226
        {
227
            if ( $sth->rows )
228
            {
229
                while ( @row = $sth->fetchrow_array )
230
                {
231
                    Verbose( "DATA: " . join(',', @row) );
232
                    $pkg_id = $row[1] || 0;
233
                    last;
234
                }
235
            }
236
            else
237
            {
238
                Warning("GetPkgIdByName:No Data for: $pkg_name");
239
            }
240
            $sth->finish();
241
        }
242
    }
243
    else
244
    {
245
        Error("GetPkgIdByName:Prepare failure" );
246
    }
247
}
248
 
249
#-------------------------------------------------------------------------------
250
# Function        : GetData_by_pkg_id
251
#
252
# Description     :
253
#
254
# Inputs          : pv_id
255
#
256
# Returns         :
257
#
258
sub GetData_by_pkg_id
259
{
260
    my ( $pkg_id ) = @_;
261
    my (@row);
262
 
263
    #
264
    #   Establish a connection to Release Manager
265
    #
266
    connectRM(\$RM_DB) unless ( $RM_DB );
267
 
268
    #
269
    #   Extract data from Release Manager
270
    #
271
    my $m_sqlstr = "SELECT pkg.PKG_NAME, pv.PKG_VERSION, pkg.PKG_ID, pv.PV_ID, pv.LAST_PV_ID, pv.CREATED_STAMP, release_manager.PK_RMAPI.return_vcs_tag(pv.PV_ID)".
272
                   " FROM RELEASE_MANAGER.PACKAGES pkg, RELEASE_MANAGER.PACKAGE_VERSIONS pv" .
273
                   " WHERE pv.PKG_ID = \'$pkg_id\' AND pkg.PKG_ID = pv.PKG_ID";
274
 
275
 
276
    my $sth = $RM_DB->prepare($m_sqlstr);
277
    if ( defined($sth) )
278
    {
279
        if ( $sth->execute( ) )
280
        {
281
            if ( $sth->rows )
282
            {
283
                while ( @row = $sth->fetchrow_array )
284
                {
285
                    Verbose( "DATA: " . join(',', @row) );
286
                    my $pkg_name = $row[0] || 'Unknown';
287
                    my $pkg_ver = $row[1] || 'Unknown';
288
                    my $pv_id = $row[3] || 'Unknown';
289
                    my $last_pv_id = $row[4] || 'Unknown';
290
                    my $created =  $row[5] || 'Unknown';
291
                    my $vcstag =  $row[6] || 'Unknown';
292
                    print "$pkg_name, $pkg_ver, $pv_id, $last_pv_id, $created\n";
293
 
294
                    #
295
                    #   Add data to the hash
296
                    #       Remove entries that address themselves
297
                    #
298
                    push (@{$versions{$last_pv_id}{next}}, $pv_id) unless ($pv_id == $last_pv_id) ;
299
                    $versions{$pv_id}{vname} = $pkg_ver;
300
                    $versions{$pv_id}{vcsTag} = $vcstag;
301
 
302
                    #
303
                    #   Convert version into full form for comparisions
304
                    #
305
                    if ( $pkg_ver =~ m~(\d+)\.(\d+)\.(\d+)(\.(.*))?~ )
306
                    {
307
                        my $patch = $3;
308
                        my $build = '000';
309
                        if ( length( $patch) >= 4 )
310
                        {
311
                            $build = substr( $patch, -3 ,3);
312
                            $patch = substr( $patch,  0 ,length($patch)-3);
313
                        }
314
 
315
                        $pkg_ver = sprintf("%3.3d.%3.3d.%3.3d.%3.3d%s", $1,$2,$patch,$build,$4 || '.0000');
316
                    }
317
                    $versions{$pv_id}{version} = $pkg_ver;
318
 
319
 
320
#                    last;
321
                }
322
            }
323
            $sth->finish();
324
        }
325
    }
326
    else
327
    {
328
        Error("GetData:Prepare failure" );
329
    }
330
}
331
 
332
#-------------------------------------------------------------------------------
333
# Function        : plist
334
#
335
# Description     : Generate an entry list as text
336
#                   Replace "." with "_" since DOT doesn't like .'s
337
#                   Seperate the arguments
338
#
339
# Inputs          : $pref       - Prefix string
340
#                   @_          - An array of entries to process
341
#
342
# Returns         : A string
343
#
344
sub plist
345
{
346
    my $pref = shift;
347
    my $result = "";
348
    foreach  ( @_ )
349
    {
350
        $_ =~ s~\.~_~g;
351
        $result .= '"' . $_ . '"' . $pref;
352
    }
353
    return $result;
354
}
355
 
356
sub pentry
357
{
358
 
359
    my $result = "";
360
    foreach  ( @_ )
361
    {
362
        next unless ( $_ );
363
        $_ =~ s~\.~_~g;
364
        $result .= '"' . $_ . '"'
365
    }
366
    return $result;
367
}
368
 
369