Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
7323 dpurdie 1
########################################################################
2
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
3
#
4
# Module name   : jats_extract_packages.pl
5
# Module type   : Makefile system
6
# Compiler(s)   : Perl
7
# Environment(s): jats build system
8
#
9
# Description   : Extracts the contents of dpkg_archive for a set of packages
10
#                 for a specified release.
11
#                 
12
#                 Temp utility to assist Pulse Integration developers
13
#......................................................................#
14
 
15
require 5.008_002;
16
use File::Basename;
17
use File::Copy;
18
use File::Path;
19
use strict;
20
use warnings;
21
use JatsEnv;
22
use JatsError;
23
use JatsSystem;
24
use JatsRmApi;
25
use FileUtils;
26
use DBI;
27
use Getopt::Long;
28
use Pod::Usage;                             # required for help support
29
 
30
#
31
#   Config Options
32
#
33
my $VERSION = "1.0.0";                      # Update this
34
my $opt_help = 0;
35
my $opt_verbose = $ENV{'GBE_VERBOSE'};      # Allow global verbose
36
my $opt_rtagid;
37
my $opt_rootdir = '.';
38
my $opt_test;
39
 
40
 
41
#
42
#   Constants
43
#
44
my @ignoreList = qw (android-ndk Dinkumware_STL netbula);
45
#
46
#   Globals
47
#
48
my $DM_DB;              # Data Base Interface
49
 
50
#-------------------------------------------------------------------------------
51
# Function        : Main
52
#
53
# Description     : Main entry point
54
#                   Parse user options
55
#
56
# Inputs          :
57
#
58
# Returns         :
59
#
60
 
61
my $result = GetOptions (
62
                "help:+"            => \$opt_help,              # flag, multiple use allowed
63
                "manual:3"          => \$opt_help,              # flag, multiple use allowed
64
                "verbose:+"         => \$opt_verbose,           # flag
65
                "rtagid|rtag_id=s"  => \$opt_rtagid,            # Number
66
                "rootdir=s"         => \$opt_rootdir,           # string
67
 
68
                "test"              => \$opt_test,              # flag
69
                );
70
 
71
#
72
#   Process help and manual options
73
#
74
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
75
pod2usage(-verbose => 1)  if ($opt_help == 2 );
76
pod2usage(-verbose => 2)  if ($opt_help > 2);
77
 
78
ErrorConfig( 'name'    => 'GenDeploy',
79
             'verbose' => $opt_verbose );
80
 
81
#
82
#   Sanity tests
83
#
84
 
85
# Supplied rootdir must exists as a directory
86
Error("Root dir not specified") 
87
    unless defined $opt_rootdir;
88
Error("Root dir not a valid directory: ", $opt_rootdir )
89
    unless( -d $opt_rootdir );
90
 
91
    # Environment var GBE_DPKG must exists as a directory
92
Error("GBE_DPKG Environment var is not a directory")
93
    unless ( -d $ENV{GBE_DPKG} );
94
 
95
 
96
#   Non Filter operations
97
#   Must supply an rtagid
98
Error("Need --rtagid", "Example: -rtagid=2362" )
99
    unless ($opt_rtagid);
100
 
101
#
102
#   This command is destined to be used in a directory where group permissions
103
#   are important. Ensure that the user is not killing group access
104
#
105
umask 0002;
106
Message("Copying packages from $ENV{GBE_DPKG} to $opt_rootdir");
107
 
108
#
109
#   Processing
110
#
111
connectRM(\$DM_DB);
112
GetPackageData();               # Get RM Data
113
exit 0;
114
 
115
#-------------------------------------------------------------------------------
116
# Function        : GetPackageData 
117
#
118
# Description     : Extract data from RM based on the provided rtag_id
119
#
120
# Inputs          : 
121
#
122
# Returns         : 
123
#
124
sub GetPackageData
125
{
126
    my $baseTar = 'stuff.tar';
127
    System ("tar cvf $baseTar --files-from /dev/null");
128
 
129
 
130
    my $m_sqlstr =  "SELECT p.PKG_NAME, pv.PKG_VERSION" .
131
                    " FROM package_versions pv, RELEASE_CONTENT rc, PACKAGES p" .
132
                    " WHERE rc.rtag_id = " . $opt_rtagid .
133
                    " AND rc.pv_id = pv.pv_id" .
134
                    " and p.PKG_ID = pv.pkg_id";
135
 
136
    my ( $PKG_NAME, $PKG_VERSION );
137
    my $sth = $DM_DB->prepare($m_sqlstr);
138
    if ( defined($sth) )
139
    {
140
        if ( $sth->execute( ) )
141
        {
142
            if ( $sth->rows )
143
            {
144
                while ( ( $PKG_NAME, $PKG_VERSION ) = $sth->fetchrow_array )
145
                {
146
                    my $skip = 0;
147
                    foreach ( @ignoreList)
148
                    {
149
                        if (uc($_) eq uc($PKG_NAME))
150
                        {
151
                            $skip = 1;
152
                            last;;
153
                        }
154
                    }
155
                    next if $skip;
156
 
157
 
158
                    Verbose ("Deployable: $PKG_NAME, $PKG_VERSION");
159
                    my $pkgDir = "$ENV{GBE_DPKG}/$PKG_NAME";
160
                    my $srcDir = "$ENV{GBE_DPKG}/$PKG_NAME/$PKG_VERSION";
161
                    my $dstDir = $opt_rootdir;
162
 
163
                    if ( -d "$srcDir" )
164
                    {
165
                        my $tarName = join ( '_' , $PKG_NAME , $PKG_VERSION ) . '.tar.gz';
166
                        Message ("Processing: $tarName");
167
                        System("tar --transform 's,^\\.,$PKG_NAME/$PKG_VERSION,' --exclude='./lcov' --exclude='./utfResults' -rf $baseTar -C $srcDir .");
168
                    }
169
                    elsif ( ! -d "$pkgDir" )
170
                    {
171
                        # if srcDir and pkgDir dont exist then package is not in dpkg_archive so display message
172
                        Warning("Skipping Package $PKG_NAME/$PKG_VERSION as it does not exist in dpkg_archive");
173
                    }
174
                    else
175
                    {
176
                        # However if srcDir does not exist but pkgDir does exist then the package version is missing which maybe an issue
177
                        Warning("Missing Version $PKG_VERSION for Package $PKG_NAME in dpkg_archive");
178
                    }
179
                }
180
 
181
                Message ("Compressing the result");
182
                System ("gzip $baseTar");
183
            }
184
            else
185
            {
186
                Error("No Packages for rtagid: $opt_rtagid");
187
            }
188
            $sth->finish();
189
        }
190
        else
191
        {
192
            Error("Execute failure", $sth->errstr(), $m_sqlstr );
193
        }
194
    }
195
    else
196
    {
197
        Error("Prepare failure", $sth->errstr(), $m_sqlstr );
198
    }
199
}
200
 
201
#-------------------------------------------------------------------------------
202
#   Documentation
203
#
204
 
205
=pod
206
 
207
=for htmltoc    DEPLOY::jats_extract_packages
208
 
209
=head1 NAME
210
 
211
jats_extract_packages - Generate a tarzip for all packages in a release
212
 
213
=head1 SYNOPSIS
214
 
215
  jats jats_extract_packages [options]
216
 
217
 Options:
218
    -help                   - Brief help message
219
    -help -help             - Detailed help message
220
    -man                    - Full documentation
221
    -rtagid=xxx             - Specify the Release Manager RtagId to process
222
    -rootdir=xxx            - Specifies the root of the releases directory
223
 
224
    -test                   - Just log actions without copying files.
225
    -verbose                - Enable verbose output
226
 
227
=head1 OPTIONS
228
 
229
=over 8
230
 
231
=item B<-help>
232
 
233
Print a brief help message and exits.
234
 
235
=item B<-help -help>
236
 
237
Print a detailed help message with an explanation for each option.
238
 
239
=item B<-man>
240
 
241
Prints the manual page and exits.
242
 
243
=item B<-rtagid=xxx>
244
 
245
This option specifies one or more RTAG_ID's to use as the source of packages that will be copied.
246
The ID will be used to get a unique list of package/versions that can be copied from dpkg_archive.
247
 
248
This option is Mandatory, for non-filter command.
249
 
250
=item B<-rootdir=xxx>
251
 
252
This option specifies the root directory where the packages will be copied to.
253
 
254
The specified directory must exist.
255
 
256
The default value is the current directory.
257
 
258
=item B<-test>
259
 
260
This option will display what would be copied without actually copying anything
261
 
262
=item B<-verbose>
263
 
264
This option will display progress information as the program executes.
265
 
266
=back
267
 
268
=head1 DESCRIPTION
269
 
270
This program is a temp kludge to keep the IT developers happy.
271
 
272
It will create a tar.gz file of all the packages in a specified release in a dpkg_archive structure.
273
 
274
=cut
275