Subversion Repositories DevTools

Rev

Rev 1040 | Rev 4457 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1040 Rev 1044
Line 1... Line 1...
1
#! /usr/bin/perl
1
#! /usr/bin/perl
2
########################################################################
2
########################################################################
3
# Copyright (C) 2011 Vix-ERG Limited, All rights reserved
3
# Copyright (C) 1998-2011 Vix Technology, All rights reserved
4
#
4
#
5
# Module name   : blatPopulate
5
# Module name   : blatPopulate
6
# Compiler(s)   : Perl
6
# Compiler(s)   : Perl
7
#
7
#
8
# Description   : Populate the blat tags directories with RM data
8
# Description   : Populate the blat tags directories with RM data
-
 
9
#                 See POD at end of this file
9
#
10
#
10
#......................................................................#
11
#......................................................................#
11
 
12
 
12
require 5.008_002;
13
require 5.008_002;
13
use strict;
14
use strict;
Line 21... Line 22...
21
use FindBin;
22
use FindBin;
22
 
23
 
23
use FindBin;                                    # Determine the current directory
24
use FindBin;                                    # Determine the current directory
24
use lib "$FindBin::Bin/lib";                    # Allow local libraries
25
use lib "$FindBin::Bin/lib";                    # Allow local libraries
25
use Utils;
26
use Utils;
-
 
27
use StdLogger;                                  # Log to sdtout
26
use Logger;
28
use Logger;
27
 
29
 
28
use Data::Dumper;
30
use Data::Dumper;
29
 
31
 
30
#
32
#
Line 40... Line 42...
40
#
42
#
41
#   Options
43
#   Options
42
#
44
#
43
my $opt_help = 0;
45
my $opt_help = 0;
44
my $opt_verbose = 0;
46
my $opt_verbose = 0;
45
 
-
 
46
my $opt_pname;
-
 
47
my $opt_pver;
-
 
48
my $opt_rtag_id;
-
 
49
my $opt_pkg_id;
-
 
50
my $opt_pv_id;
-
 
51
my $opt_proj_id;
-
 
52
my $opt_tagdir = 'tags';
47
my $opt_tagdir = 'tags';
-
 
48
my $opt_nodaemonise;
-
 
49
 
-
 
50
my %pkginfo;
53
 
51
 
54
 
52
 
55
#
53
#
56
#   Describe config uration parameters
54
#   Describe configuration parameters
57
#
55
#
58
my %cdata = (
56
my %cdata = (
59
    'logfile'         => {'mandatory' => 1    , 'fmt' => 'vfile'},
57
    'logfile'         => {'mandatory' => 1    , 'fmt' => 'vfile'},
60
    'logfile.size'    => {'default' => '1M'   , 'fmt' => 'size'},
58
    'logfile.size'    => {'default' => '1M'   , 'fmt' => 'size'},
61
    'logfile.count'   => {'default' => 9      , 'fmt' => 'int'},
59
    'logfile.count'   => {'default' => 9      , 'fmt' => 'int'},
62
    'verbose'         => {'default' => 0      , 'fmt' => 'int'},
60
    'verbose'         => {'default' => 0      , 'fmt' => 'int'},
63
    'tagdir'          => {'mandatory' => 1    , 'fmt' => 'dir'},
61
    'tagdir'          => {'mandatory' => 1    , 'fmt' => 'dir'},
64
    'maxFileAge'      => {'default' => '1h'   , 'fmt' => 'period'},
62
    'maxFileAge'      => {'default' => '24h'  , 'fmt' => 'period'},
65
);
63
);
66
 
64
 
67
#-------------------------------------------------------------------------------
65
#-------------------------------------------------------------------------------
68
# Function        : Mainline Entry Point
66
# Function        : Mainline Entry Point
69
#
67
#
70
# Description     :
68
# Description     :
71
#
69
#
72
# Inputs          :
70
# Inputs          :
73
#
71
#
74
@args = @ARGV;
72
@args = @ARGV;
-
 
73
Getopt::Long::Configure('pass_through');
75
my $result = GetOptions (
74
my $result = GetOptions (
76
                "help|h:+"      => \$opt_help,
75
                "help|h:+"      => \$opt_help,
77
                "manual:3"      => \$opt_help,
76
                "manual:3"      => \$opt_help,
78
                "verbose:+"     => \$opt_verbose,
77
                "verbose:+"     => \$opt_verbose,
79
                "tagdir=s"      => \$opt_tagdir,
78
                "tagdir=s"      => \$opt_tagdir,
-
 
79
                "D"             => \$opt_nodaemonise,
80
                
80
                
81
                "pname=s"       => \$opt_pname,
-
 
82
                "pver=s"        => \$opt_pver,
-
 
83
                "rtag_id=s"     => \$opt_rtag_id,
-
 
84
                "pkg_id=s"      => \$opt_pkg_id,
-
 
85
                "pv_id=s"       => \$opt_pv_id,
-
 
86
                "proj_id=s"     => \$opt_proj_id,
-
 
87
 
-
 
88
                );
81
                );
89
 
82
 
90
                #
83
                #
91
                #   UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
84
                #   UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
92
                #
85
                #
93
 
86
 
94
#
87
#
95
#   Process help and manual options
88
#   Process help and manual options
96
#
89
#
97
pod2usage(-verbose => 0, -message => "blatPopulate") if ($opt_help == 1 || ! $result || $#ARGV >= 0);
90
pod2usage(-verbose => 0, -message => "blatPopulate") if ($opt_help == 1 || ! $result );
98
pod2usage(-verbose => 1) if ($opt_help == 2 );
91
pod2usage(-verbose => 1) if ($opt_help == 2 );
99
pod2usage(-verbose => 2) if ($opt_help > 2);
92
pod2usage(-verbose => 2) if ($opt_help > 2);
100
 
93
 
-
 
94
$logger = StdLogger->new();
-
 
95
 
101
#
96
#
102
#   Set the CWWD as the directory of the script
97
#   Set the CWD as the directory of the script
103
#   This simplifies configuration and use
98
#   This simplifies configuration and use
104
#
99
#
105
chdir ($rootDir) || die ("Cannot 'cd' to $rootDir: $!\n");
100
chdir ($rootDir) || die ("Cannot 'cd' to $rootDir: $!\n");
106
 
101
 
107
#
102
#
Line 113... Line 108...
113
    warn "$_\n" foreach (@{$errors});
108
    warn "$_\n" foreach (@{$errors});
114
    die ("Config contained errors\n");
109
    die ("Config contained errors\n");
115
}
110
}
116
 
111
 
117
$conf->{verbose} = $opt_verbose if ( $opt_verbose > 0 );
112
$conf->{verbose} = $opt_verbose if ( $opt_verbose > 0 );
-
 
113
unless ( $opt_nodaemonise )
-
 
114
{
118
$logger = Logger->new($conf);
115
    $logger = Logger->new($conf);
119
$conf->{logger} = $logger;
116
    $conf->{logger} = $logger;
-
 
117
}
120
$logger->verbose2("Args: @args");
118
$logger->verbose2("Args: @args");
121
 
119
 
122
#
120
#
-
 
121
#   Porcess command line
-
 
122
#   Aarguments are of the form aaaa=bbbbm
-
 
123
#
-
 
124
foreach ( @ARGV )
-
 
125
{
-
 
126
    next unless ( m~(.+)=(.+)~ );
-
 
127
    {
-
 
128
        my $tag = $1;
-
 
129
        my $value = $2;
-
 
130
        $value =~ s~^['"]~~;
-
 
131
        $value =~ s~['"]$~~;
-
 
132
        $pkginfo{$tag} = $value;
-
 
133
    }
-
 
134
}
-
 
135
 
-
 
136
#
123
#   Sanity Test
137
#   Sanity Test
-
 
138
#   Ensure required arguments have been presented
-
 
139
#
-
 
140
foreach  ( qw(pkg_name pkg_version rtag_id pkg_id pv_id proj_id mode_id) )
-
 
141
{
-
 
142
    $logger->err ("$_ not provided")    unless ( exists $pkginfo{$_} );
-
 
143
 
-
 
144
}
-
 
145
 
-
 
146
#
-
 
147
#   Not interested in package deletions
124
#
148
#
125
$logger->err ("pname not provided")    unless ( $opt_pname );
-
 
126
$logger->err ("pver not provided")     unless ( $opt_pver );
-
 
127
$logger->err ("rtag_id not provided")  unless ( $opt_rtag_id );
149
if ( $pkginfo{mode_id} == 2 )
-
 
150
{
128
$logger->err ("pkg_id not provided")   unless ( $opt_pkg_id );
151
    $logger->verbose3 ("Ignore package deletion: $pkginfo{pkg_name},$pkginfo{pkg_version}");
129
$logger->err ("pv_id not provided")    unless ( $opt_pv_id );
152
    exit 0;
130
$logger->err ("proj_id not provided")  unless ( $opt_proj_id );
-
 
-
 
153
}
131
 
154
 
132
#
155
#
133
#   Examine all the tag subdirectories
156
#   Examine all the tag subdirectories
134
#   They will have a configuration file in them that has been created by the
157
#   They will have a configuration file in them that has been created by the
135
#   consumer daemon.
158
#   consumer daemon.
Line 147... Line 170...
147
    #       Only process subdirs
170
    #       Only process subdirs
148
    #
171
    #
149
    while (my $tag = readdir($dh) )
172
    while (my $tag = readdir($dh) )
150
    {
173
    {
151
        next if ( $tag =~ m~^\.~ );
174
        next if ( $tag =~ m~^\.~ );
-
 
175
        $logger->verbose3 ("Processing: $tag");
152
        my $tagfile = catfile($opt_tagdir, $tag, '.config');
176
        my $tagfile = catfile($opt_tagdir, $tag, '.config');
153
        next unless ( -f $tagfile );
177
        next unless ( -f $tagfile );
154
        $logger->verbose2 ("Tag Dir: $tagfile");
178
        $logger->verbose3 ("Tag Dir: $tagfile");
155
 
179
 
156
        my ($mtime) = Utils::mtime($tagfile);
180
        my ($mtime) = Utils::mtime($tagfile);
157
        my $age = time() - $mtime;
181
        my $age = time() - $mtime;
158
        $logger->verbose3( "Config File Age: $age, $conf->{maxFileAge}");
182
        $logger->verbose3( "Config File Age: $age, $conf->{maxFileAge}");
159
        if ( $age > $conf->{maxFileAge} )
183
        if ( $age > $conf->{maxFileAge} )
Line 169... Line 193...
169
        #       project
193
        #       project
170
        #       release
194
        #       release
171
        #       pkg.Name
195
        #       pkg.Name
172
        #
196
        #
173
        my $data = ConfigReader::readConfig($tagfile);
197
        my $data = ConfigReader::readConfig($tagfile);
-
 
198
        if ( $conf->{verbose} > 2 )
-
 
199
        {
-
 
200
            $logger->verbose3 ("Config: " . Dumper($data));
-
 
201
        }
174
        if ( $data )
202
        if ( $data )
175
        {
203
        {
176
#print Dumper($data);
-
 
177
            if (   exists $data->{projects}{$opt_proj_id}
204
            if (   exists $data->{projects}{$pkginfo{proj_id}}
178
                || exists $data->{releases}{$opt_rtag_id}
205
                || exists $data->{releases}{$pkginfo{rtag_id}}
179
                || exists $data->{pkg}{$opt_pname} )
206
                || exists $data->{pkg}{$pkginfo{pkg_name}} )
180
                {
207
                {
181
                    TouchFile( catfile( $opt_tagdir, $tag, $opt_pname . '::' . $opt_pver ));
208
                    TouchFile( catfile( $opt_tagdir, $tag, $pkginfo{pkg_name} . '::' . $pkginfo{pkg_version} ));
182
                }
209
                }
183
        }
210
        }
184
    }
211
    }
185
    closedir $dh;
212
    closedir $dh;
186
 
213
 
Line 236... Line 263...
236
            unlink ( $path );
263
            unlink ( $path );
237
            open ($tfh, ">>", $path) || ($result = 1);
264
            open ($tfh, ">>", $path) || ($result = 1);
238
        }
265
        }
239
        close ($tfh);
266
        close ($tfh);
240
    }
267
    }
-
 
268
 
-
 
269
    #
-
 
270
    #   Ensure all can remove the file
-
 
271
    #   May be created by root and need to be deleted by the blatDaemon
-
 
272
    #
-
 
273
    chmod 0666, $path;
241
    return $result;
274
    return $result;
242
}
275
}
243
 
276
 
244
package ConfigReader;
277
package ConfigReader;
245
our %config;
278
our %config;
Line 273... Line 306...
273
 
306
 
274
blatPopulate - Populate Blats tags directory to provide fast-transfer of packages
307
blatPopulate - Populate Blats tags directory to provide fast-transfer of packages
275
 
308
 
276
=head1 SYNOPSIS
309
=head1 SYNOPSIS
277
 
310
 
278
blatPopulate ...
311
blatPopulate [options] pkg_data
279
 
312
 
280
 
313
 
281
 Options:
314
 Options:
282
    -help              - brief help message
315
    -help              - brief help message
283
    -help -help        - Detailed help message
316
    -help -help        - Detailed help message
284
    -man               - Full documentation
317
    -man               - Full documentation
285
    -verbose           - A little bit of logging
318
    -verbose           - A little bit of logging
286
    -tagdir=path       - Specify alternate tag base
319
    -tagdir=path       - Specify alternate tag base
-
 
320
 PkgData
287
    -...               - Package data
321
    tag=value          - A list of package information items
288
 
322
 
289
=head1 OPTIONS
323
=head1 OPTIONS
290
 
324
 
291
=over 8
325
=over 8
292
 
326
 
Line 305... Line 339...
305
=item B<-tagdir=path>
339
=item B<-tagdir=path>
306
 
340
 
307
This provides an alternate tag directory root. The default value is a 'tags'
341
This provides an alternate tag directory root. The default value is a 'tags'
308
directory located below the directory in which the program is located.
342
directory located below the directory in which the program is located.
309
 
343
 
-
 
344
=item B<-tagdir=path>
-
 
345
 
-
 
346
A list of package information items. These include:
-
 
347
 
-
 
348
=over 4
-
 
349
 
-
 
350
=item * archive
-
 
351
 
-
 
352
=item * pkg_name
-
 
353
 
-
 
354
=item * pkg_version
-
 
355
 
-
 
356
=item * rtag_id
-
 
357
 
-
 
358
=item * pkg_id
-
 
359
 
-
 
360
=item * pv_id
-
 
361
 
-
 
362
=item * proj_id
-
 
363
 
-
 
364
=item * mode_id
-
 
365
 
-
 
366
=back
-
 
367
 
310
=back
368
=back
311
 
369
 
312
=head1 DESCRIPTION
370
=head1 DESCRIPTION
313
 
371
 
314
This utility is designed to be invoked by Release Manager when a new package
372
This utility is designed to be invoked by Release Manager when a new package
Line 328... Line 386...
328
 
386
 
329
The .config file is created by the the consume BlatDaemon on a regular basis.
387
The .config file is created by the the consume BlatDaemon on a regular basis.
330
If the file is too old it will be deleted, on the assumption that the
388
If the file is too old it will be deleted, on the assumption that the
331
blatDaemon is dead.
389
blatDaemon is dead.
332
 
390
 
-
 
391
=head2 EXAMPLE
-
 
392
 
-
 
393
    blatPopulate.pl  archive=dpkg_archive
-
 
394
                     pkg_name='h400sdk'
-
 
395
                     pkg_version='1.1.13-4.1000.cots'
-
 
396
                     rtag_id=11083
-
 
397
                     pkg_id=32885
-
 
398
                     pv_id=270088
-
 
399
                     proj_id=341
-
 
400
                     mode_id=2
-
 
401
                     -verbose=3
-
 
402
 
333
=cut
403
=cut
334
 
404