Subversion Repositories DevTools

Rev

Rev 6383 | Go to most recent revision | 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;
356
        push @{$retData},\%data;
357
    }
358
 
359
    #
360
    #   Process each file
361
    #
362
    foreach my $file ( @fileList) {
363
        my %data;
364
 
365
        my $source = catfile($DPKG_DOC, $file);
366
        $data{md5sum} = genMd5Sum($source);
367
        $data{size} = (stat($source))[7];
368
 
369
        $data{name} = $file;
370
        $data{fullname} = 'doc/' . $file;
371
        $data{path} = 'doc/';
372
        $data{type} = 'file';
373
        $data{machtype} = 'unknown';
374
        $data{host} = $GBE_HOSTNAME;
375
        push @{$retData},\%data;
376
    }
377
 
378
    return $retData;
379
}
380
 
381
#-------------------------------------------------------------------------------
4625 dpurdie 382
# Function        : generateFileList
383
#                   generateFileListProc 
384
#
385
# Description     : A fileList has not been found in the target package
386
#                   Perhaps the package was not created by the build system
387
#                   
388
#                   Generate a fileList        
389
#
390
# Inputs          : None
391
#
392
# Returns         : Path to the generated file list
393
#
394
my @generateFileListData;
395
my $baseLength;
396
sub generateFileList
397
{
398
    my $outXmlFile;
399
    Verbose("Generate internal filelist - none found in package");
400
 
401
    #
402
    #   Scan the package and process each file
403
    #
404
    $baseLength = length($DPKG_ROOT);
405
    File::Find::find( \&generateFileListProc, $DPKG_ROOT );
406
 
407
    #
408
    #   Write out XML of the Generated file list
409
    #
410
    my $data;
411
    $data->{file} = \@generateFileListData;
412
 
413
    #
414
    #   Write out sections of XML
415
    #       Want control over the output order
416
    #       Use lots of attributes and only elements for arrays
417
    #       Save as one attribute per line - for readability
418
    #
419
    $outXmlFile = catdir($OUT_ROOT,"built.files.$GBE_HOSTNAME.xml");
420
 
421
    Verbose2('Meta File', $outXmlFile);
422
    my $xs = XML::Simple->new( NoAttr =>0, AttrIndent => 1 );
423
 
424
    open (my $XML, '>', $outXmlFile) || Error ("Cannot create output file: $outXmlFile", $!);
425
    $xs->XMLout($data, 
426
                'RootName' => 'files', 
427
                'XMLDecl'  => '<?xml version="1.0" encoding="UTF-8"?>',
428
                'OutputFile' => $XML);
429
    close $XML;
430
 
431
    return $outXmlFile;
432
}
433
 
434
sub generateFileListProc
435
{
436
    my %data;
437
    my $md5sum;
438
    my $source = $File::Find::name;
439
    my $type = 'dir';
440
 
441
    my $target = substr($source, $baseLength);
442
    $target =~ s~^/~~;
443
    $target =~ s~/$~~;
444
    Verbose2("GenFileList: $source, $target");
445
    return if (length ($target) == 0);
446
 
447
    if (-l $source)
448
    {
449
        $type = 'link';
450
    }
451
    elsif ( -f $source)
452
    {
453
        $type = 'file';
6391 dpurdie 454
        $md5sum = genMd5Sum($source);
4625 dpurdie 455
    }
456
 
4697 dpurdie 457
    #
458
    #   Convert from iso-8859-1 into utf-8
459
    #
460
    $target = decode( 'iso-8859-1', $target );
461
    $target = encode( 'utf-8', $target );
4625 dpurdie 462
 
463
    if (-d $source)
464
    {
465
        $data{path} = $target;
466
    }
467
    else
468
    {
469
        $data{path} = StripFileExt($target);
470
        $data{name} = StripDir($target);
471
        if (defined $md5sum)
472
        {
473
            $data{size} = (stat($source))[7];
474
            $data{md5sum} = $md5sum;
475
        }
476
    }
477
 
478
    $data{fullname} = $target;
479
    $data{type} = $type;
480
    $data{machtype} = 'unknown';
481
    $data{host} = $GBE_HOSTNAME;
482
 
6391 dpurdie 483
    # Put a nice '/' on the end of the path elements
4625 dpurdie 484
    $data{path} .= '/'
485
        if ( exists ($data{path}) && length($data{path}) > 0);
486
 
487
    push @generateFileListData, \%data;
488
}
489
 
490
#-------------------------------------------------------------------------------
6391 dpurdie 491
# Function        : genMd5Sum 
492
#
493
# Description     : Generate the MD5SUM of a specified file
494
#
495
# Inputs          : $source - Full path to file 
496
#
497
# Returns         : md5sum of the file
498
#                   Will not return on error 
499
#
500
sub genMd5Sum
501
{
502
    my ($source) = @_;
503
    my $md5sum;
504
 
505
    Verbose2("Calculate MD5 Digest: $source");
506
    open(my $fh , $source) or Error ("Can't open '$source': $!");
507
    binmode $fh, ':crlf';
508
    $md5sum = Digest::MD5->new->addfile($fh)->hexdigest;
509
    close $fh;
510
 
511
    return $md5sum;
512
}
513
 
514
#-------------------------------------------------------------------------------
4625 dpurdie 515
# Function        : updateRmFiles 
516
#
517
# Description     : 
518
#
6391 dpurdie 519
# Inputs          : $genFileData            - Data for generated files [Optional] 
4625 dpurdie 520
#
521
# Returns         : 
522
#
523
my $RM_DB;
524
my  $updateRmFilesData;
525
sub updateRmFiles
526
{
6391 dpurdie 527
    my ($genFileData) = @_;
4625 dpurdie 528
    my $eCount = 0;
529
    #
530
    #   If in use the the autobuilder - which it should be, then
531
    #   modify the user name to access RM with a proxy user. This is the
532
    #   same method used in the 'buildtool'
533
    #
534
    if ($ENV{GBE_ABT} && $ENV{GBE_RM_USERNAME} && $ENV{GBE_RM_USERNAME} !~ m~]$~ )
535
    {
536
        Verbose("Access RM database as proxy user");
537
        $ENV{GBE_RM_USERNAME} = $ENV{GBE_RM_USERNAME} . '[release_manager]'; 
538
    }
539
 
540
    #
541
    #   Read in the release note data base
542
    #
543
    my $rnDataBase = catdir($DPKG_DOC, 'release_note.xml');
544
    if (! -f $rnDataBase )
545
    {
546
        Error("Release Note XML database not found: $!", $rnDataBase);
547
    }
548
 
549
    #
6383 dpurdie 550
    #   Extract essential information
551
    #   Don't use a simple parser - its gets it wrong
552
    #   
553
    my $xml;
554
    my $parser = XML::LibXML->new();
555
    my $doc    = $parser->parse_file($rnDataBase);
556
 
557
    #
558
    #   Extract the 'package' data
559
    #   Only expect one of them
560
 
561
    my @nodes = $doc->findnodes('/package_data/package');
562
    my $node = $nodes[0];
563
    Error ("Package section not found in $rnDataBase") unless defined $node;
564
 
565
    my %eldata;
566
    foreach my $atr ($node->findnodes( "./@*")) {     
567
        Debug("Package Data:" .  $atr->nodeName() . ":" . $atr->value);
568
        $xml->{package}{$atr->nodeName} = $atr->value;
569
    }
570
 
571
    #
572
    #   Extract the file data
573
    #   Tricky - needs to be an array
574
    #
575
    foreach my $element ($doc->findnodes('/package_data/files/file')) {
576
       my %eldata;
577
       foreach my $node ($element->findnodes( "./@*")) {     
578
           Debug("File:" .  $node->nodeName() . ":" . $node->value);
579
           $eldata{$node->nodeName} = $node->value;
580
       }
581
       push @{$xml->{file}}, \%eldata;
582
    }
583
    #DebugDumpData("XML DATA", $xml);
584
 
585
    #
4625 dpurdie 586
    #   Sanity Test the data
587
    #
588
    Error("Sanity Check Failure. PVID") unless($opt_pvid eq $xml->{package}{pvid});
589
    Error("Sanity Check Failure. Name") unless($opt_pname eq $xml->{package}{name});
590
    Error("Sanity Check Failure. Version") unless($opt_pversion eq $xml->{package}{version});
6383 dpurdie 591
    Error("Sanity Check Failure. File Section") unless(exists $xml->{file});
4625 dpurdie 592
 
593
    #
6391 dpurdie 594
    #   Append any additional file data
595
    #       This will be the doc/ doc/release_note.xml and doc/RELEASE_NOTES.....html
596
    #
597
    if ($genFileData) {
598
        foreach ( @{$genFileData}) {
599
            push @{$xml->{file}}, $_;
600
        }
601
    }
602
 
603
    #
4625 dpurdie 604
    #   Delete any existing entry(s)
605
    #
606
    updateRmFilesDelete();
607
 
608
    #
609
    #   Release Manager Database will barf if there are duplicate entries
610
    #   Maintain a hash of items processed, and only process each once
611
    #
612
    my %fullNameSeen;
613
 
6383 dpurdie 614
    $updateRmFilesData = "";
615
    foreach my $entry (@{$xml->{file}})
4625 dpurdie 616
    {
617
        #
618
        #   Ignore 'merge' entries
619
        #
620
        next if ((exists $entry->{type}) && ($entry->{type} eq 'merge'));
621
        #
622
        #   Clean up the data
623
        #
624
        my $fname = $entry->{name} || '';
625
        my $fpath  = $entry->{path} || '';
626
        my $fsize  = $entry->{size} || 0;
627
        my $fmd5  = $entry->{md5sum} || '';
628
        $fpath =~ s~/$~~ unless $fname;
629
 
630
        unless( $fullNameSeen{$fpath}{$fname} )
631
        {
632
            $fullNameSeen{$fpath}{$fname} = 1;
633
 
634
            #
635
            #   Create SQL fragment for the insert
636
            #
637
            $eCount++;
6116 dpurdie 638
            my $quoteFname = $fname;
639
            $quoteFname =~ s~'~''~g;
4625 dpurdie 640
            my $entry = " INTO release_manager.release_components ( pv_id, file_name, file_path, byte_size, crc_cksum, crc_modcrc ) " .
6116 dpurdie 641
                        " VALUES ( $opt_pvid, '$quoteFname', '$fpath',$fsize , '$fmd5', '')";
4625 dpurdie 642
            $updateRmFilesData .= $entry;
643
 
644
            # The size of the aggregation is key to performance
645
            # Too big is as bad as too small
646
            if (length($updateRmFilesData) > 10000)
647
            {
648
                updateRmFilesInsert();
649
            }
650
        }
651
        else
652
        {
653
            Warning("Multiple file entries for: $fpath $fname");
654
        }
655
    }
656
    updateRmFilesInsert();
657
    Verbose ("Inserted $eCount entries into Release_Components");
658
}
659
 
660
#-------------------------------------------------------------------------------
661
# Function        : updateRmFilesInsert 
662
#
663
# Description     : Insert entries using the partial SQL statement 
664
#                   Must be called when the partial SQL buffer get large
665
#                   as well as at the end to fluch any outstanding inserts
666
#
667
# Inputs          : 
668
#
669
# Returns         : 
670
#
671
sub updateRmFilesInsert
672
{
673
    if (length($updateRmFilesData) > 0)
674
    {
675
        executeRmQuery(
676
            'updateRmFilesInsert',
6116 dpurdie 677
            'INSERT ALL' . $updateRmFilesData . ' SELECT 1 FROM DUAL'
4625 dpurdie 678
            );
679
 
680
        $updateRmFilesData = ""; 
681
    }
682
}
683
#-------------------------------------------------------------------------------
684
# Function        : updateRmFilesDelete 
685
#
686
# Description     : Delete ALL entires in the 'release_components' table associated
687
#                   with the current pvid
688
#                   
689
#                   Needs to be done before new entries are added.    
690
#
691
# Inputs          : 
692
#
693
# Returns         : 
694
#
695
sub updateRmFilesDelete
696
{
697
    executeRmQuery(
698
        'updateRmFilesDelete',
699
        'delete from release_manager.release_components where pv_id=' . $opt_pvid
700
        );
701
}
702
 
703
#-------------------------------------------------------------------------------
704
# Function        : updateRmNoteInfo 
705
#
706
# Description     : Insert Release Note Info into the Release Manager Database
707
#                   This has the side effect that RM will see the Release Note
708
#                   as being fully generated.
709
#
710
# Inputs          : 
711
#
712
# Returns         : 
713
#
714
sub updateRmNoteInfo
715
{
716
    #
717
    #   Determine the path to the Release Note in a form that is suitable for the Release Manager
718
    #   Database. This expects: /dpkg_archive/PkgName/PkgVer/doc/pkgFileName
719
    #
720
    my $rnPath = join('/', '', 'dpkg_archive', $opt_pname, $opt_pversion, 'doc', $opt_outname);
721
    Verbose("RN_INFO:", $rnPath);
722
 
723
    # Into the database
724
    executeRmQuery (
725
        'updateRmNoteInfo', 
726
        'update release_manager.package_versions set release_notes_info=\'' . $rnPath . '\' where pv_id=' . $opt_pvid
727
        );
728
}
729
 
730
#-------------------------------------------------------------------------------
731
# Function        : executeRmQuery 
732
#
733
# Description     : Execute a simple RM query. One that does not expect any return data
734
#
735
# Inputs          : $fname           - OprName, for error reporting
736
#                   $m_sqlstr        - SQL String
737
#
738
# Returns         : Will exit on error
739
#
740
sub executeRmQuery
741
{
742
    my ($fname, $m_sqlstr) = @_;
743
 
744
    #
6391 dpurdie 745
    #   Testing only
746
    #   Display the Database access commands - don't execute them
747
    #
748
    if ($opt_noRM) {
749
        Debug0("$fname", $m_sqlstr);
750
        return;
751
    }
752
 
753
    #
4625 dpurdie 754
    #   Connect to the Database - once
755
    #
756
    connectRM(\$RM_DB, 0) unless $RM_DB;
757
 
758
    Verbose2('ExecuteQuery:', $fname);
759
    #
760
    #   Create the full SQL statement
761
    #
762
    my $sth = $RM_DB->prepare($m_sqlstr);
763
    if ( defined($sth) )
764
    {
765
        if ( $sth->execute() )
766
        {
767
            $sth->finish();
768
        }
769
        else
770
        {
771
            Error("$fname: Execute failure: $m_sqlstr", $sth->errstr() );
772
        }
773
    }
774
    else
775
    {
776
        Error("$fname: Prepare failure");
777
    }
778
}
779
 
780
 
781
#-------------------------------------------------------------------------------
782
#   Documentation
783
#
784
 
785
=pod
786
 
787
=for htmltoc    SYSUTIL::
788
 
789
=head1 NAME
790
 
791
jats_gen_releasenote - Generate a Release Note
792
 
793
=head1 SYNOPSIS
794
 
795
 jats jats_gen_releasenote [options]
796
 
797
 Options:
798
    -help              - Brief help message
799
    -help -help        - Detailed help message
800
    -man               - Full documentation
801
    -verbose           - Display additional progress messages
802
    -outfile=name      - [Optional] Name of the output XML file
803
    -archive=name      - [Optional] Name package archive
804
    -releasenote=path  - Path to the Release Note Data
805
    -UpdateRmFiles     - Update the Files list in Release Manager
6391 dpurdie 806
    -WorkDir=path      - [Test] Path to work area
807
    -NoRM              - [Test] No RM present
4625 dpurdie 808
 
809
 
810
=head1 OPTIONS
811
 
812
=over 8
813
 
814
=item B<-help>
815
 
816
Print a brief help message and exits.
817
 
818
=item B<-help -help>
819
 
820
Print a detailed help message with an explanation for each option.
821
 
822
=item B<-man>
823
 
824
Prints the manual page and exits.
825
 
826
=item B<-pvid=nn>
827
 
828
This option provides identifies the PackageVersion to be processed.
829
 
830
This option is mandatory.
831
 
832
=item B<-outfile=name>
833
 
834
This option specifies the output file name.
835
 
836
If not provided by the user the output filename will be created in the current directory
837
and it will be named after the package name and package version.
838
 
839
If the filename does not end in .xml, then .xml will be appended to the file name.
840
 
841
=item B<-UpdateRmFiles>
842
 
843
This option will case the utility to ppdate the Files list in Release Manager.
844
 
845
The existing file list will be replaced by the one within the package.
846
 
847
Note: Write Access to Release Manager is required.
848
 
6391 dpurdie 849
=item B<-WorkDir=Path>
850
 
851
This option is provided to aid in testing of this tool. 
852
 
853
If provided the tool will use the specified path when creating files.
854
 
855
=item B<-NoRM>
856
 
857
This option is provided to aid in testing of this tool. 
858
 
859
When provided, this option will supress access to the Release Manager database. Instead the
860
SQL commands will be displayed.
861
 
4625 dpurdie 862
=back
863
 
864
=head1 DESCRIPTION
865
 
866
This utility program is used to extract sufficient information from Release Manager and other
867
associated databases so that a Release Note can be created.
868
 
869
The extracted data is stored in an XML format. The intent is that XSLT will be used to create
870
an HTML based release note.
871
 
872
 
873
=head1 EXAMPLE
874
 
875
=head2 jats jats_gen_releasenote -releasenote=/tmp/myreleasenote.xml
876
 
877
This will process release note data in the specified XML file.
878
 
879
=cut