Subversion Repositories DevTools

Rev

Rev 6391 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4625 dpurdie 1
########################################################################
2
# Copyright (c) VIX TECHNOLOGY (AUST) LTD
3
#
4
# Module name   : jats_gen_releasenote.pl
5
# Module type   : Makefile system
6
# Compiler(s)   : Perl
7
# Environment(s): jats
8
#
9
# Description   : Generate the package Release Note
10
#                 Requires
11
#                   1) Release Note data generated by jats_get_releasenote_data.pl
12
#                   2) Target package in dpkg_archive
13
#                   3) One or more built.files.xxx.xml (optional, but desirable)
14
#
15
#                 Will:
16
#                   Merge built.files.xxx.xml files into the release note data
17
#                   Insert build meta data
18
#                   Save the Release Note MetaData within the package
19
#                   Generate the HTML release note - save within the package
20
#                   Insert Release_Contents into RM Database
21
#
22
# Usage:        See POD
23
#
24
#......................................................................#
25
 
26
require 5.008_002;
27
use strict;
28
use warnings;
29
 
30
use Pod::Usage;
31
use Getopt::Long;
32
use XML::Simple;
33
use File::Path;
34
use File::Copy;
6383 dpurdie 35
use XML::LibXML;
4625 dpurdie 36
use Digest::MD5;
37
use File::Find;
38
use FindBin;                                # Determine the current directory
4697 dpurdie 39
use Encode qw(decode encode);
4625 dpurdie 40
 
41
use JatsError;
42
use JatsSystem;
43
use Getopt::Long;
44
use Pod::Usage;
45
use FileUtils;
46
use JatsEnv;
47
use JatsRmApi;
48
 
49
use DBI;
50
 
51
my $VERSION = "1.0.0";                                      # Update this. Inserted into meta data field
52
 
53
# User options
54
my $opt_verbose = 0;
55
my $opt_help = 0;
56
my $opt_archive;
57
my $archive_tag;
58
my $opt_pname;
59
my $opt_pversion;
60
my $opt_release_note;
61
my $opt_pvid;
62
my $opt_outname;
63
my $opt_outputXml;
64
my $opt_updateRmFiles;
65
my $opt_workingDir;
6391 dpurdie 66
my $opt_noRM;
4625 dpurdie 67
 
68
#   Global vars
69
our $GBE_HOSTNAME;
70
my $DPKG_ROOT;
71
my $DPKG_DOC;
72
my $JATS_RN;
73
my $OUT_ROOT;
74
 
75
 
76
#
77
#   Structure to translate -archive=xxx option to archive variable
78
#   These are the various dpkg_archives known to JATS
79
#
80
my %Archive2Var =( 'main'       =>  'GBE_DPKG',
81
                   'store'      =>  'GBE_DPKG_STORE',
82
                   'cache'      =>  'GBE_DPKG_CACHE',
83
                   'local'      =>  'GBE_DPKG_LOCAL',
84
                   'sandbox'    =>  'GBE_DPKG_SBOX',
85
                   'deploy'     =>  'GBE_DPLY',
86
                   );
87
 
88
#-------------------------------------------------------------------------------
89
# Function        : Main Entry
90
#
91
# Description     :
92
#
93
# Inputs          :
94
#
95
# Returns         :
96
#
97
{
98
    my $result = GetOptions (
99
                    "help+"         => \$opt_help,              # flag, multiple use allowed
100
                    "manual:3"      => \$opt_help,              # flag, set value
101
                    "verbose:+"     => \$opt_verbose,           # flag, increment
102
                    "archive=s"     => \$opt_archive,           # string
103
                    "releasenote=s" => \$opt_release_note,      # string
104
                    "UpdateRmFiles" => \$opt_updateRmFiles,     # flag
105
                    "WorkDir=s"     => \$opt_workingDir,        # String
6391 dpurdie 106
                    "noRM"          => \$opt_noRM,              # Flag
4625 dpurdie 107
                    );
108
 
109
    #
110
    #   Process help and manual options
111
    #
112
    pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
113
    pod2usage(-verbose => 1)  if ($opt_help == 2 );
114
    pod2usage(-verbose => 2)  if ($opt_help > 2);
115
 
116
    ErrorConfig( 'name'    =>'GenRn', 'verbose' => $opt_verbose );
117
    InitFileUtils();
118
 
119
    #
120
    #   Needed EnvVars
121
    #
122
    EnvImport ('GBE_HOSTNAME');
123
    $JATS_RN = $FindBin::Bin;
124
    Error("Release Note tools not found", $JATS_RN)
125
        unless (-d $JATS_RN);
126
 
127
 
128
    #
129
    #   Sanity Check
130
    #
131
    Error("Release Note data not provided") unless $opt_release_note;
132
    Error("Release Note data not found") unless -f $opt_release_note;
133
    if (defined $opt_workingDir)
134
    {
135
        $opt_workingDir = FullPath($opt_workingDir);
136
        Error("Working directory is not a directory") unless -d $opt_workingDir;
137
        Error("Working directory is writable") unless -w $opt_workingDir;
138
    }
139
 
140
    #
141
    #   Determine the target archive
142
    #   The default archive is GBE_DPKG, but this may be changed
143
    #
144
    $opt_archive = 'main' unless ( $opt_archive );
145
    my $archive_tag = $Archive2Var{$opt_archive};
146
    Error("Unknown archive specified: $opt_archive")
147
        unless ( $archive_tag );
148
    $DPKG_ROOT = $ENV{$archive_tag} || '';
149
    Verbose ("Archive Variable: $archive_tag" );
150
    Verbose2 ("Archive Path: $DPKG_ROOT" );
151
 
152
    #
153
    #   Process the release note and extract essential information
154
    #
155
    processReleaseNote();
156
 
157
    #
158
    #   Locate the target package
159
    #
160
    $DPKG_ROOT = catdir($DPKG_ROOT, $opt_pname, $opt_pversion);
161
    Verbose ("Package Path: ", DisplayPath($DPKG_ROOT) );
162
    Error ("Package not found in archive", $DPKG_ROOT) unless -d $DPKG_ROOT;
163
 
164
    #   OUT_ROOT is really only used for testing
165
    #   Needs to mimic $DPKG_ROOT
166
    $OUT_ROOT = defined($opt_workingDir) ? $opt_workingDir : $DPKG_ROOT; 
167
    Verbose2 ("Output Path: $OUT_ROOT" );
168
 
169
    #
170
    #   Calculate output filenames
171
    #   Html Release Note:
172
    #       RELEASE_NOTES_PVID_PKGNAME_CLEANV.html
173
    #
174
    $DPKG_DOC = catdir($OUT_ROOT, 'doc');
175
    $opt_outputXml = catdir($DPKG_DOC, 'release_note.xml');
176
 
177
    my $cleanv = $opt_pversion;
178
    $cleanv =~ s~\.~_~g;
179
    $opt_outname = join('_',
180
                        'RELEASE_NOTES',
181
                        $opt_pvid,
182
                        $opt_pname,
183
                        $cleanv,    
184
                        ) . '.html';
185
    Verbose("Note Name: $opt_outname");
186
 
187
    #
188
    #   Locate the release note data file
189
    #   This was created as a prerequisite to the build
190
    #   Note: windows requires '/' in the file list
191
    #
192
    my @filesList;
6391 dpurdie 193
    my $appendGenFiles = 1;
4625 dpurdie 194
    foreach my $item ( glob(catdir($DPKG_ROOT, 'built.files.*.xml'))) {
195
        $item =~ s~\\~/~g;
196
        push @filesList, $item;
197
    }
198
    unless (scalar @filesList > 0)
199
    {
4697 dpurdie 200
        Warning("No file list found within the package: $opt_pname/$opt_pversion");
6391 dpurdie 201
        $appendGenFiles = 0;
4625 dpurdie 202
        #
203
        #   No filelist found in the package
204
        #   This may occur for packages that did not go though the build system
205
        #   Create a package-list
206
        #
207
        my $item = generateFileList();
208
        $item =~ s~\\~/~g;
209
        push @filesList, $item;
210
    }
211
 
212
    #
213
    #   Create output directory within the package
214
    #
215
    mkpath($DPKG_DOC, 0, 0775);
216
 
217
    #
6391 dpurdie 218
    #   Generate name of temp file
219
    #   
220
    my $builtFiles = 'built.files.releasenote.xml';
221
    if (defined $opt_workingDir) {
222
        $builtFiles = join('/', $opt_workingDir, $builtFiles);
223
    }
224
    Verbose("TempFile: $builtFiles");
225
 
226
    #
4625 dpurdie 227
    #   Merge the Release Note and the various file lists into a single
228
    #   XML file. Keep the file local
229
    #
230
    System('--NoShell', '--Exit', 'java', '-jar', 
231
           catdir($JATS_RN, 'saxon9he.jar'), 
232
           '-xsl:' . catdir($JATS_RN, 'merge.xslt'),
233
           "-s:$opt_release_note",
234
           'fileList=' . join(',', @filesList),
6391 dpurdie 235
           '-o:' . $builtFiles
4625 dpurdie 236
            );
237
 
238
    #
239
    #   Generate the HTML Release Note
240
    #   Output directly to the body of the package
241
    #
242
    System('--NoShell', '--Exit', 'java', '-jar', 
243
           catdir($JATS_RN, 'saxon9he.jar'), 
244
           '-xsl:' . catdir($JATS_RN, 'releaseNote2html.xslt'),
6391 dpurdie 245
           '-s:' . $builtFiles,
4625 dpurdie 246
           "-o:" . catdir($DPKG_DOC, $opt_outname)
247
            );
248
 
249
    #
250
    #   Transfer the XML database directly into the package
251
    #
6391 dpurdie 252
    unless( File::Copy::copy($builtFiles, $opt_outputXml) ) {
4625 dpurdie 253
        Error("Cannot transfer XML release note", $!, $opt_outputXml);
254
    }
6391 dpurdie 255
    unlink $builtFiles; 
4625 dpurdie 256
 
257
    #
258
    #   Delete the built.files.xxx.xml that may be present in the root of the package
259
    #   These are no longer needed - they have been incorporated into the release_note.xml file
260
    #
261
    foreach my $item ( glob(catdir($DPKG_ROOT, 'built.files.*.xml'))) {
262
        unlink $item;
263
    }
264
 
265
    #
266
    #   Update the Release Manager entry - File Data
267
    #
268
    if ($opt_updateRmFiles)
269
    {
6391 dpurdie 270
        my $genFileData;
271
        $genFileData = genFileData($opt_outname, 'release_note.xml') if ($appendGenFiles);
272
 
273
        updateRmFiles($genFileData);
4625 dpurdie 274
        updateRmNoteInfo();
275
    }
276
 
277
    #
278
    #   All done
279
    #
280
    Verbose ("Release Note:", DisplayPath(catdir($DPKG_DOC, $opt_outname)));
281
    exit 0;
282
}
283
 
284
#-------------------------------------------------------------------------------
285
# Function        : processReleaseNote 
286
#
287
# Description     : Extract essential information from the Release Note Data
288
#
289
# Inputs          : 
290
#
291
# Returns         : Populates global variables 
292
#
293
sub processReleaseNote
294
{
295
 
6383 dpurdie 296
    #
297
    #   Extract essential information
298
    #   
299
    my $xml;
300
    my $parser = XML::LibXML->new();
301
    my $doc    = $parser->parse_file($opt_release_note);
4625 dpurdie 302
 
6383 dpurdie 303
    #
304
    #   Extract the 'package' data
305
    #   Only expect one of them
306
    #   
307
    my @nodes = $doc->findnodes('/package_data/package');
308
    my $node = $nodes[0];
309
    Error ("Package section not found in $opt_release_note") unless defined $node;
310
 
311
    $opt_pname    = $node->getAttribute( 'name' );
312
    $opt_pversion = $node->getAttribute( 'version' );
313
    $opt_pvid     = $node->getAttribute( 'pvid' );
4625 dpurdie 314
 
315
    Verbose("Package Name: $opt_pname") ;
316
    Verbose("Package Version: $opt_pversion") ;
317
    Verbose("Package Pvid: $opt_pvid") ;
318
}
319
 
320
#-------------------------------------------------------------------------------
6391 dpurdie 321
# Function        : genFileData  
322
#
323
# Description     : Generate File Data for some locally generated files so that they
324
#                   will appear in the Release Manager database 
325
#
326
# Inputs          : List of files to process
327
#                   Assumed they are in the $DPKG_DOC directory 
328
#
329
# Returns         : An array of data items
330
#                   Need:
331
#                       {path}
332
#                       {name}
333
#                       {size}
334
#                       {md5sum}
335
#                       {fullname}
336
#                       {type}
337
#                       {machtype}
338
#                       {host}
339
#                   
340
sub genFileData
341
{
342
    my (@fileList) = @_;
343
    my $retData;
344
    Verbose('genFileData');
345
 
346
    #
347
    #   Create entry for the 'doc' folder
348
    #
349
    {
350
        my %data;
351
        $data{fullname} = 'doc';
352
        $data{path} = 'doc';
353
        $data{type} = 'dir';
354
        $data{machtype} = 'unknown';
355
        $data{host} = $GBE_HOSTNAME;
6395 dpurdie 356
        $data{noWarn} = 1;
6391 dpurdie 357
        push @{$retData},\%data;
358
    }
359
 
360
    #
361
    #   Process each file
362
    #
363
    foreach my $file ( @fileList) {
364
        my %data;
365
 
366
        my $source = catfile($DPKG_DOC, $file);
367
        $data{md5sum} = genMd5Sum($source);
368
        $data{size} = (stat($source))[7];
369
 
370
        $data{name} = $file;
371
        $data{fullname} = 'doc/' . $file;
372
        $data{path} = 'doc/';
373
        $data{type} = 'file';
374
        $data{machtype} = 'unknown';
375
        $data{host} = $GBE_HOSTNAME;
376
        push @{$retData},\%data;
377
    }
378
 
379
    return $retData;
380
}
381
 
382
#-------------------------------------------------------------------------------
4625 dpurdie 383
# Function        : generateFileList
384
#                   generateFileListProc 
385
#
386
# Description     : A fileList has not been found in the target package
387
#                   Perhaps the package was not created by the build system
388
#                   
389
#                   Generate a fileList        
390
#
391
# Inputs          : None
392
#
393
# Returns         : Path to the generated file list
394
#
395
my @generateFileListData;
396
my $baseLength;
397
sub generateFileList
398
{
399
    my $outXmlFile;
400
    Verbose("Generate internal filelist - none found in package");
401
 
402
    #
403
    #   Scan the package and process each file
404
    #
405
    $baseLength = length($DPKG_ROOT);
406
    File::Find::find( \&generateFileListProc, $DPKG_ROOT );
407
 
408
    #
409
    #   Write out XML of the Generated file list
410
    #
411
    my $data;
412
    $data->{file} = \@generateFileListData;
413
 
414
    #
415
    #   Write out sections of XML
416
    #       Want control over the output order
417
    #       Use lots of attributes and only elements for arrays
418
    #       Save as one attribute per line - for readability
419
    #
420
    $outXmlFile = catdir($OUT_ROOT,"built.files.$GBE_HOSTNAME.xml");
421
 
422
    Verbose2('Meta File', $outXmlFile);
423
    my $xs = XML::Simple->new( NoAttr =>0, AttrIndent => 1 );
424
 
425
    open (my $XML, '>', $outXmlFile) || Error ("Cannot create output file: $outXmlFile", $!);
426
    $xs->XMLout($data, 
427
                'RootName' => 'files', 
428
                'XMLDecl'  => '<?xml version="1.0" encoding="UTF-8"?>',
429
                'OutputFile' => $XML);
430
    close $XML;
431
 
432
    return $outXmlFile;
433
}
434
 
435
sub generateFileListProc
436
{
437
    my %data;
438
    my $md5sum;
439
    my $source = $File::Find::name;
440
    my $type = 'dir';
441
 
442
    my $target = substr($source, $baseLength);
443
    $target =~ s~^/~~;
444
    $target =~ s~/$~~;
445
    Verbose2("GenFileList: $source, $target");
446
    return if (length ($target) == 0);
447
 
448
    if (-l $source)
449
    {
450
        $type = 'link';
451
    }
452
    elsif ( -f $source)
453
    {
454
        $type = 'file';
6391 dpurdie 455
        $md5sum = genMd5Sum($source);
4625 dpurdie 456
    }
457
 
4697 dpurdie 458
    #
459
    #   Convert from iso-8859-1 into utf-8
460
    #
461
    $target = decode( 'iso-8859-1', $target );
462
    $target = encode( 'utf-8', $target );
4625 dpurdie 463
 
464
    if (-d $source)
465
    {
466
        $data{path} = $target;
467
    }
468
    else
469
    {
470
        $data{path} = StripFileExt($target);
471
        $data{name} = StripDir($target);
472
        if (defined $md5sum)
473
        {
474
            $data{size} = (stat($source))[7];
475
            $data{md5sum} = $md5sum;
476
        }
477
    }
478
 
479
    $data{fullname} = $target;
480
    $data{type} = $type;
481
    $data{machtype} = 'unknown';
482
    $data{host} = $GBE_HOSTNAME;
483
 
6391 dpurdie 484
    # Put a nice '/' on the end of the path elements
4625 dpurdie 485
    $data{path} .= '/'
486
        if ( exists ($data{path}) && length($data{path}) > 0);
487
 
488
    push @generateFileListData, \%data;
489
}
490
 
491
#-------------------------------------------------------------------------------
6391 dpurdie 492
# Function        : genMd5Sum 
493
#
494
# Description     : Generate the MD5SUM of a specified file
495
#
496
# Inputs          : $source - Full path to file 
497
#
498
# Returns         : md5sum of the file
499
#                   Will not return on error 
500
#
501
sub genMd5Sum
502
{
503
    my ($source) = @_;
504
    my $md5sum;
505
 
506
    Verbose2("Calculate MD5 Digest: $source");
507
    open(my $fh , $source) or Error ("Can't open '$source': $!");
508
    binmode $fh, ':crlf';
509
    $md5sum = Digest::MD5->new->addfile($fh)->hexdigest;
510
    close $fh;
511
 
512
    return $md5sum;
513
}
514
 
515
#-------------------------------------------------------------------------------
4625 dpurdie 516
# Function        : updateRmFiles 
517
#
518
# Description     : 
519
#
6391 dpurdie 520
# Inputs          : $genFileData            - Data for generated files [Optional] 
4625 dpurdie 521
#
522
# Returns         : 
523
#
524
my $RM_DB;
525
my  $updateRmFilesData;
526
sub updateRmFiles
527
{
6391 dpurdie 528
    my ($genFileData) = @_;
4625 dpurdie 529
    my $eCount = 0;
530
    #
531
    #   If in use the the autobuilder - which it should be, then
532
    #   modify the user name to access RM with a proxy user. This is the
533
    #   same method used in the 'buildtool'
534
    #
535
    if ($ENV{GBE_ABT} && $ENV{GBE_RM_USERNAME} && $ENV{GBE_RM_USERNAME} !~ m~]$~ )
536
    {
537
        Verbose("Access RM database as proxy user");
538
        $ENV{GBE_RM_USERNAME} = $ENV{GBE_RM_USERNAME} . '[release_manager]'; 
539
    }
540
 
541
    #
542
    #   Read in the release note data base
543
    #
544
    my $rnDataBase = catdir($DPKG_DOC, 'release_note.xml');
545
    if (! -f $rnDataBase )
546
    {
547
        Error("Release Note XML database not found: $!", $rnDataBase);
548
    }
549
 
550
    #
6383 dpurdie 551
    #   Extract essential information
552
    #   Don't use a simple parser - its gets it wrong
553
    #   
554
    my $xml;
555
    my $parser = XML::LibXML->new();
556
    my $doc    = $parser->parse_file($rnDataBase);
557
 
558
    #
559
    #   Extract the 'package' data
560
    #   Only expect one of them
561
 
562
    my @nodes = $doc->findnodes('/package_data/package');
563
    my $node = $nodes[0];
564
    Error ("Package section not found in $rnDataBase") unless defined $node;
565
 
566
    my %eldata;
567
    foreach my $atr ($node->findnodes( "./@*")) {     
568
        Debug("Package Data:" .  $atr->nodeName() . ":" . $atr->value);
569
        $xml->{package}{$atr->nodeName} = $atr->value;
570
    }
571
 
572
    #
573
    #   Extract the file data
574
    #   Tricky - needs to be an array
575
    #
576
    foreach my $element ($doc->findnodes('/package_data/files/file')) {
577
       my %eldata;
578
       foreach my $node ($element->findnodes( "./@*")) {     
579
           Debug("File:" .  $node->nodeName() . ":" . $node->value);
580
           $eldata{$node->nodeName} = $node->value;
581
       }
582
       push @{$xml->{file}}, \%eldata;
583
    }
584
    #DebugDumpData("XML DATA", $xml);
585
 
586
    #
4625 dpurdie 587
    #   Sanity Test the data
588
    #
589
    Error("Sanity Check Failure. PVID") unless($opt_pvid eq $xml->{package}{pvid});
590
    Error("Sanity Check Failure. Name") unless($opt_pname eq $xml->{package}{name});
591
    Error("Sanity Check Failure. Version") unless($opt_pversion eq $xml->{package}{version});
6383 dpurdie 592
    Error("Sanity Check Failure. File Section") unless(exists $xml->{file});
4625 dpurdie 593
 
594
    #
6391 dpurdie 595
    #   Append any additional file data
596
    #       This will be the doc/ doc/release_note.xml and doc/RELEASE_NOTES.....html
597
    #
598
    if ($genFileData) {
599
        foreach ( @{$genFileData}) {
600
            push @{$xml->{file}}, $_;
601
        }
602
    }
603
 
604
    #
4625 dpurdie 605
    #   Delete any existing entry(s)
606
    #
607
    updateRmFilesDelete();
608
 
609
    #
610
    #   Release Manager Database will barf if there are duplicate entries
611
    #   Maintain a hash of items processed, and only process each once
612
    #
613
    my %fullNameSeen;
614
 
6383 dpurdie 615
    $updateRmFilesData = "";
616
    foreach my $entry (@{$xml->{file}})
4625 dpurdie 617
    {
618
        #
619
        #   Ignore 'merge' entries
620
        #
621
        next if ((exists $entry->{type}) && ($entry->{type} eq 'merge'));
622
        #
623
        #   Clean up the data
624
        #
625
        my $fname = $entry->{name} || '';
626
        my $fpath  = $entry->{path} || '';
627
        my $fsize  = $entry->{size} || 0;
628
        my $fmd5  = $entry->{md5sum} || '';
629
        $fpath =~ s~/$~~ unless $fname;
630
 
631
        unless( $fullNameSeen{$fpath}{$fname} )
632
        {
633
            $fullNameSeen{$fpath}{$fname} = 1;
634
 
635
            #
636
            #   Create SQL fragment for the insert
637
            #
638
            $eCount++;
6116 dpurdie 639
            my $quoteFname = $fname;
640
            $quoteFname =~ s~'~''~g;
4625 dpurdie 641
            my $entry = " INTO release_manager.release_components ( pv_id, file_name, file_path, byte_size, crc_cksum, crc_modcrc ) " .
6116 dpurdie 642
                        " VALUES ( $opt_pvid, '$quoteFname', '$fpath',$fsize , '$fmd5', '')";
4625 dpurdie 643
            $updateRmFilesData .= $entry;
644
 
645
            # The size of the aggregation is key to performance
646
            # Too big is as bad as too small
647
            if (length($updateRmFilesData) > 10000)
648
            {
649
                updateRmFilesInsert();
650
            }
651
        }
652
        else
653
        {
6395 dpurdie 654
            unless ($entry->{noWarn}) {
655
                Warning("Multiple file entries for: $opt_pname, $opt_pversion : $fpath $fname");
656
            }
4625 dpurdie 657
        }
658
    }
659
    updateRmFilesInsert();
660
    Verbose ("Inserted $eCount entries into Release_Components");
661
}
662
 
663
#-------------------------------------------------------------------------------
664
# Function        : updateRmFilesInsert 
665
#
666
# Description     : Insert entries using the partial SQL statement 
667
#                   Must be called when the partial SQL buffer get large
668
#                   as well as at the end to fluch any outstanding inserts
669
#
670
# Inputs          : 
671
#
672
# Returns         : 
673
#
674
sub updateRmFilesInsert
675
{
676
    if (length($updateRmFilesData) > 0)
677
    {
678
        executeRmQuery(
679
            'updateRmFilesInsert',
6116 dpurdie 680
            'INSERT ALL' . $updateRmFilesData . ' SELECT 1 FROM DUAL'
4625 dpurdie 681
            );
682
 
683
        $updateRmFilesData = ""; 
684
    }
685
}
686
#-------------------------------------------------------------------------------
687
# Function        : updateRmFilesDelete 
688
#
689
# Description     : Delete ALL entires in the 'release_components' table associated
690
#                   with the current pvid
691
#                   
692
#                   Needs to be done before new entries are added.    
693
#
694
# Inputs          : 
695
#
696
# Returns         : 
697
#
698
sub updateRmFilesDelete
699
{
700
    executeRmQuery(
701
        'updateRmFilesDelete',
702
        'delete from release_manager.release_components where pv_id=' . $opt_pvid
703
        );
704
}
705
 
706
#-------------------------------------------------------------------------------
707
# Function        : updateRmNoteInfo 
708
#
709
# Description     : Insert Release Note Info into the Release Manager Database
710
#                   This has the side effect that RM will see the Release Note
711
#                   as being fully generated.
712
#
713
# Inputs          : 
714
#
715
# Returns         : 
716
#
717
sub updateRmNoteInfo
718
{
719
    #
720
    #   Determine the path to the Release Note in a form that is suitable for the Release Manager
721
    #   Database. This expects: /dpkg_archive/PkgName/PkgVer/doc/pkgFileName
722
    #
723
    my $rnPath = join('/', '', 'dpkg_archive', $opt_pname, $opt_pversion, 'doc', $opt_outname);
724
    Verbose("RN_INFO:", $rnPath);
725
 
726
    # Into the database
727
    executeRmQuery (
728
        'updateRmNoteInfo', 
729
        'update release_manager.package_versions set release_notes_info=\'' . $rnPath . '\' where pv_id=' . $opt_pvid
730
        );
731
}
732
 
733
#-------------------------------------------------------------------------------
734
# Function        : executeRmQuery 
735
#
736
# Description     : Execute a simple RM query. One that does not expect any return data
737
#
738
# Inputs          : $fname           - OprName, for error reporting
739
#                   $m_sqlstr        - SQL String
740
#
741
# Returns         : Will exit on error
742
#
743
sub executeRmQuery
744
{
745
    my ($fname, $m_sqlstr) = @_;
746
 
747
    #
6391 dpurdie 748
    #   Testing only
749
    #   Display the Database access commands - don't execute them
750
    #
751
    if ($opt_noRM) {
752
        Debug0("$fname", $m_sqlstr);
753
        return;
754
    }
755
 
756
    #
4625 dpurdie 757
    #   Connect to the Database - once
758
    #
759
    connectRM(\$RM_DB, 0) unless $RM_DB;
760
 
761
    Verbose2('ExecuteQuery:', $fname);
762
    #
763
    #   Create the full SQL statement
764
    #
765
    my $sth = $RM_DB->prepare($m_sqlstr);
766
    if ( defined($sth) )
767
    {
768
        if ( $sth->execute() )
769
        {
770
            $sth->finish();
771
        }
772
        else
773
        {
774
            Error("$fname: Execute failure: $m_sqlstr", $sth->errstr() );
775
        }
776
    }
777
    else
778
    {
779
        Error("$fname: Prepare failure");
780
    }
781
}
782
 
783
 
784
#-------------------------------------------------------------------------------
785
#   Documentation
786
#
787
 
788
=pod
789
 
790
=for htmltoc    SYSUTIL::
791
 
792
=head1 NAME
793
 
794
jats_gen_releasenote - Generate a Release Note
795
 
796
=head1 SYNOPSIS
797
 
798
 jats jats_gen_releasenote [options]
799
 
800
 Options:
801
    -help              - Brief help message
802
    -help -help        - Detailed help message
803
    -man               - Full documentation
804
    -verbose           - Display additional progress messages
805
    -outfile=name      - [Optional] Name of the output XML file
806
    -archive=name      - [Optional] Name package archive
807
    -releasenote=path  - Path to the Release Note Data
808
    -UpdateRmFiles     - Update the Files list in Release Manager
6391 dpurdie 809
    -WorkDir=path      - [Test] Path to work area
810
    -NoRM              - [Test] No RM present
4625 dpurdie 811
 
812
 
813
=head1 OPTIONS
814
 
815
=over 8
816
 
817
=item B<-help>
818
 
819
Print a brief help message and exits.
820
 
821
=item B<-help -help>
822
 
823
Print a detailed help message with an explanation for each option.
824
 
825
=item B<-man>
826
 
827
Prints the manual page and exits.
828
 
829
=item B<-pvid=nn>
830
 
831
This option provides identifies the PackageVersion to be processed.
832
 
833
This option is mandatory.
834
 
835
=item B<-outfile=name>
836
 
837
This option specifies the output file name.
838
 
839
If not provided by the user the output filename will be created in the current directory
840
and it will be named after the package name and package version.
841
 
842
If the filename does not end in .xml, then .xml will be appended to the file name.
843
 
844
=item B<-UpdateRmFiles>
845
 
846
This option will case the utility to ppdate the Files list in Release Manager.
847
 
848
The existing file list will be replaced by the one within the package.
849
 
850
Note: Write Access to Release Manager is required.
851
 
6391 dpurdie 852
=item B<-WorkDir=Path>
853
 
854
This option is provided to aid in testing of this tool. 
855
 
856
If provided the tool will use the specified path when creating files.
857
 
858
=item B<-NoRM>
859
 
860
This option is provided to aid in testing of this tool. 
861
 
862
When provided, this option will supress access to the Release Manager database. Instead the
863
SQL commands will be displayed.
864
 
4625 dpurdie 865
=back
866
 
867
=head1 DESCRIPTION
868
 
869
This utility program is used to extract sufficient information from Release Manager and other
870
associated databases so that a Release Note can be created.
871
 
872
The extracted data is stored in an XML format. The intent is that XSLT will be used to create
873
an HTML based release note.
874
 
875
 
876
=head1 EXAMPLE
877
 
878
=head2 jats jats_gen_releasenote -releasenote=/tmp/myreleasenote.xml
879
 
880
This will process release note data in the specified XML file.
881
 
882
=cut