Subversion Repositories DevTools

Rev

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

Rev 6148 Rev 6320
Line 20... Line 20...
20
use File::Basename;
20
use File::Basename;
21
use Data::Dumper;
21
use Data::Dumper;
22
use File::Spec::Functions;
22
use File::Spec::Functions;
23
use POSIX ":sys_wait_h";
23
use POSIX ":sys_wait_h";
24
use File::Temp qw/tempfile/;
24
use File::Temp qw/tempfile/;
-
 
25
use Digest::MD5;
25
 
26
 
26
use FindBin;                                    # Determine the current directory
27
use FindBin;                                    # Determine the current directory
27
use lib "$FindBin::Bin/lib";                    # Allow local libraries
28
use lib "$FindBin::Bin/lib";                    # Allow local libraries
28
 
29
 
29
use Utils;
30
use Utils;
Line 59... Line 60...
59
my $excludePkgs;
60
my $excludePkgs;
60
my %releaseData;
61
my %releaseData;
61
my $comError = 0;
62
my $comError = 0;
62
my $yday = -1;
63
my $yday = -1;
63
my $RemotePkgList = {};
64
my $RemotePkgList = {};
-
 
65
my $targetBinDir = "$FindBin::Bin/targetBin";
64
 
66
 
65
#
67
#
66
#   Contain statisics maintained while operating
68
#   Contain statisics maintained while operating
67
#       Can be dumped with a kill -USR2
69
#       Can be dumped with a kill -USR2
68
#       List here for documentation
70
#       List here for documentation
Line 337... Line 339...
337
    #   Get list of packages from Remote site
339
    #   Get list of packages from Remote site
338
    #   Invoke a program on the remote site and parse the results
340
    #   Invoke a program on the remote site and parse the results
339
    #
341
    #
340
    #   Returned data looks like:
342
    #   Returned data looks like:
341
    #       Metadata avail="140100452"
343
    #       Metadata avail="140100452"
-
 
344
    #       BlatBin MD5="9e2c6e45af600a20a01dbcb7570da1f1" file="stat.pl"
342
    #       time="1497586865" GMT="Fri Jun 16 04:21:05 2017" pname="ERGissaccounts" pver="1.0.7169.mas"
345
    #       time="1497586865" GMT="Fri Jun 16 04:21:05 2017" pname="ERGissaccounts" pver="1.0.7169.mas"
343
    #       time="1497954104" GMT="Tue Jun 20 10:21:44 2017" pname="ERGissaccounts" pver="1.0.7178.mas" deleted="0"
346
    #       time="1497954104" GMT="Tue Jun 20 10:21:44 2017" pname="ERGissaccounts" pver="1.0.7178.mas" deleted="0"
344
    #
347
    #
345
    my $remotePkgList;
348
    my $remotePkgList;
346
    my $remoteData;
349
    my $remoteData;
-
 
350
    my $blatBinData;
347
    my $ph;
351
    my $ph;
348
    my $tgt_cmd = "$conf->{'bindir'}/get_plist.pl";
352
    my $tgt_cmd = "$conf->{'bindir'}/get_plist.pl";
349
    my $ssh_cmd = sshCmd($tgt_cmd);
353
    my $ssh_cmd = sshCmd($tgt_cmd);
350
 
354
 
351
    $logger->verbose2("processReleaseList:ssh_cmd:$ssh_cmd");
355
    $logger->verbose2("processReleaseList:ssh_cmd:$ssh_cmd");
Line 353... Line 357...
353
    while ( <$ph> )
357
    while ( <$ph> )
354
    {
358
    {
355
        chomp;
359
        chomp;
356
        if ($_ =~ m~^Metadata\s+~)
360
        if ($_ =~ m~^Metadata\s+~)
357
        {
361
        {
358
            parsePkgMetaData($_, \%{$remoteData})
362
            parsePkgMetaData($_, \%{$remoteData});
-
 
363
        }
-
 
364
        elsif ($_ =~ m~^BlatBin\s+~)
-
 
365
        {
-
 
366
            parseBlatBinData($_, \%{$blatBinData})
359
        }
367
        }
360
        else
368
        else
361
        {
369
        {
362
            if ( parsePkgList($_, \%{$remotePkgList} ) )
370
            if ( parsePkgList($_, \%{$remotePkgList} ) )
363
            {
371
            {
Line 380... Line 388...
380
        $statistics{state} = 'No Remote Package List';
388
        $statistics{state} = 'No Remote Package List';
381
        return;
389
        return;
382
    }
390
    }
383
 
391
 
384
#Utils::DebugDumpData ("remotePkgList", $remotePkgList);
392
#Utils::DebugDumpData ("remotePkgList", $remotePkgList);
-
 
393
#Utils::DebugDumpData ("blatBinData", $blatBinData);
-
 
394
 
-
 
395
    #
-
 
396
    #   Determine the Blat Bin packages that need to be transferred
-
 
397
    #   Transfer Blats Bin files before attempting to transfer packages
-
 
398
    #   
-
 
399
    my $blatBinList = getBlatBin();
-
 
400
    foreach my $file ( keys %{$blatBinList} )
-
 
401
    {
-
 
402
        if (exists $blatBinData->{$file}) {
-
 
403
            if ($blatBinData->{$file} eq $blatBinList->{$file}) {
-
 
404
                delete $blatBinList->{$file};
-
 
405
            }
-
 
406
        }
-
 
407
    }
-
 
408
#Utils::DebugDumpData ("blatBinList", $blatBinList);
-
 
409
    transferBlatBin($blatBinList);
385
   
410
    
386
    #
411
    #
387
    #   Determine the set of packages in the releases to be transferred
412
    #   Determine the set of packages in the releases to be transferred
388
    # 
413
    # 
389
    my $pkgList;
414
    my $pkgList;
390
    if ( $conf->{'allArchive'} )
415
    if ( $conf->{'allArchive'} )
Line 1052... Line 1077...
1052
 
1077
 
1053
    return \%archiveList;
1078
    return \%archiveList;
1054
}
1079
}
1055
 
1080
 
1056
#-------------------------------------------------------------------------------
1081
#-------------------------------------------------------------------------------
-
 
1082
# Function        : getBlatBin  
-
 
1083
#
-
 
1084
# Description     : Get the list of files that should be in the targetbin directory
-
 
1085
#
-
 
1086
# Inputs          : Nothing 
-
 
1087
#
-
 
1088
# Returns         : A hash of data 
-
 
1089
#
-
 
1090
sub getBlatBin
-
 
1091
{
-
 
1092
    my $data;
-
 
1093
    $logger->verbose("getBlatBin: $targetBinDir");
-
 
1094
    if (opendir(DIR, $targetBinDir ) ) {
-
 
1095
        my @vlist = readdir(DIR);
-
 
1096
        closedir DIR;
-
 
1097
 
-
 
1098
        foreach my $vname ( sort @vlist )
-
 
1099
        {
-
 
1100
            next if ( $vname eq '.' );
-
 
1101
            next if ( $vname eq '..' );
-
 
1102
            next unless ( -f "$targetBinDir/$vname" );
-
 
1103
 
-
 
1104
            if (open FILE, "$targetBinDir/$vname") {
-
 
1105
                $data->{$vname} = Digest::MD5->new->addfile(*FILE)->hexdigest;
-
 
1106
                close (FILE);
-
 
1107
            }
-
 
1108
        }
-
 
1109
    } else {
-
 
1110
        $logger->warn("BlatBin Not Found: $targetBinDir");
-
 
1111
    }
-
 
1112
    return $data;
-
 
1113
}
-
 
1114
 
-
 
1115
 
-
 
1116
#-------------------------------------------------------------------------------
1057
# Function        : maintainTagList
1117
# Function        : maintainTagList
1058
#
1118
#
1059
# Description     : Maintain a data structure for the maintenance of the
1119
# Description     : Maintain a data structure for the maintenance of the
1060
#                   tags directory
1120
#                   tags directory
1061
#
1121
#
Line 1193... Line 1253...
1193
    }
1253
    }
1194
    $statistics{tagCount} = $tagCount;
1254
    $statistics{tagCount} = $tagCount;
1195
}
1255
}
1196
 
1256
 
1197
#-------------------------------------------------------------------------------
1257
#-------------------------------------------------------------------------------
-
 
1258
# Function        : transferBlatBin 
-
 
1259
#
-
 
1260
# Description     : Transfer any of the Blat Bin files that are out of date
-
 
1261
#                   on the target
-
 
1262
#
-
 
1263
# Inputs          : $fileHash       - A hash whose files are those that need
-
 
1264
#                                     to be updated 
-
 
1265
#
-
 
1266
# Returns         : 
-
 
1267
#
-
 
1268
sub transferBlatBin
-
 
1269
{
-
 
1270
    my ($hash) = @_;
-
 
1271
    $logger->verbose("transferBlatBin");
-
 
1272
    foreach my $file ( sort keys %{$hash})
-
 
1273
    {
-
 
1274
        $logger->logmsg("transferBlatBin: $file");
-
 
1275
 
-
 
1276
        #
-
 
1277
        #   Transfer one file using only 'ssh'
-
 
1278
        #   Create the target directory on the fly
-
 
1279
        #   Manipulate file permissions
-
 
1280
        #   Report errors
-
 
1281
 
-
 
1282
        my $tar_cmd = "cat \"$targetBinDir/$file\"";
-
 
1283
        my $tgt_cmd = "mkdir -p ~/bin && chmod +x+w \"~/bin/$file\" && cat > \"~/bin/$file\" && chmod +x-w \"~/bin/$file\" || exit 1";
-
 
1284
        my $ssh_cmd = sshCmd($tgt_cmd);
-
 
1285
        my $cat_cmd = 
-
 
1286
 
-
 
1287
        $logger->verbose2("transferBlatBin:tar_cmd:$tar_cmd");
-
 
1288
        $logger->verbose2("transferBlatBin:tgt_cmd:$tgt_cmd");
-
 
1289
        $logger->verbose2("transferBlatBin:ssh_cmd:$ssh_cmd");
-
 
1290
 
-
 
1291
        my $ph;
-
 
1292
        open ($ph, "$tar_cmd | $ssh_cmd |");
-
 
1293
        while ( <$ph> )
-
 
1294
        {
-
 
1295
            chomp;
-
 
1296
            $logger->verbose2("transferBlatBin:Data: $_");
-
 
1297
        }
-
 
1298
        close ($ph);
-
 
1299
        $logger->verbose("transferBlatBin:End: $?");
-
 
1300
 
-
 
1301
        if ( $? != 0 )
-
 
1302
        {
-
 
1303
            $logger->warn("transferBlatBin:Transfer Error: $file, $?");
-
 
1304
        }
-
 
1305
        LogTxError ($?);
-
 
1306
    }
-
 
1307
}
-
 
1308
 
-
 
1309
 
-
 
1310
#-------------------------------------------------------------------------------
1198
# Function        : transferPackage
1311
# Function        : transferPackage
1199
#
1312
#
1200
# Description     : Transfer specified package to target system
1313
# Description     : Transfer specified package to target system
1201
#
1314
#
1202
# Inputs          : $pname          - Name of the package
1315
# Inputs          : $pname          - Name of the package
Line 1244... Line 1357...
1244
    #       It may have been transferred in this cycle
1357
    #       It may have been transferred in this cycle
1245
    #       It may have been in the archive anyway
1358
    #       It may have been in the archive anyway
1246
    #
1359
    #
1247
    if ( exists($RemotePkgList->{$pname}) && exists ($RemotePkgList->{$pname}{$pver})) {
1360
    if ( exists($RemotePkgList->{$pname}) && exists ($RemotePkgList->{$pname}{$pver})) {
1248
        $logger->verbose("transferPackage: Already in archive");
1361
        $logger->verbose("transferPackage: Already in archive");
1249
	#$logger->logmsg("transferPackage: $pname, $pver : Already in archive");
1362
        #$logger->logmsg("transferPackage: $pname, $pver : Already in archive");
1250
        return 1;
1363
        return 1;
1251
    }
1364
    }
1252
 
1365
 
1253
    my $sfile = catfile( $conf->{'dpkg_archive'} , $pname, $pver );
1366
    my $sfile = catfile( $conf->{'dpkg_archive'} , $pname, $pver );
1254
    unless ( -d $sfile )
1367
    unless ( -d $sfile )
Line 1443... Line 1556...
1443
 
1556
 
1444
        $logger->verbose2("parsePkgMetaData: $1 = $2");
1557
        $logger->verbose2("parsePkgMetaData: $1 = $2");
1445
    }
1558
    }
1446
}
1559
}
1447
 
1560
 
-
 
1561
#-------------------------------------------------------------------------------
-
 
1562
# Function        : parseBlatBinData
-
 
1563
#
-
 
1564
# Description     : Parse one line of Blat Bin data from a pkgList
-
 
1565
#                   Lines are of the form:
-
 
1566
#                   BlatBin MD5="dbc4507f4db5b41f7358b28bce65a15d" file="ddp-gtar"
-
 
1567
#
-
 
1568
# Inputs          : $line                   - Line of data
-
 
1569
#                   $hashp                  - Ref to hash to populate
-
 
1570
#
-
 
1571
# Returns         : Nothing
-
 
1572
#
-
 
1573
sub parseBlatBinData
-
 
1574
{
-
 
1575
    my ($line, $hashp) = @_;
-
 
1576
 
-
 
1577
    my $rv;
-
 
1578
    $line =~ s~^\S+~~;
-
 
1579
    while ( $line =~ m~\s*(.+?)="(.+?)"~ )
-
 
1580
    {
-
 
1581
        $rv->{$1} = $2;
-
 
1582
        $line = $';
-
 
1583
    }
-
 
1584
#Utils::DebugDumpData ("parseBlatBinData", $rv);
-
 
1585
 
-
 
1586
    my $fname = $rv->{file};
-
 
1587
    my $md5 =  $rv->{MD5};
-
 
1588
    return undef unless ( $fname && $md5 );
-
 
1589
 
-
 
1590
    $logger->verbose2("parseBlatBinData: $fname : $md5");
-
 
1591
    $hashp->{$fname} = $md5;
-
 
1592
}
1448
 
1593
 
1449
#-------------------------------------------------------------------------------
1594
#-------------------------------------------------------------------------------
1450
# Function        : resetDailyStatistics 
1595
# Function        : resetDailyStatistics 
1451
#
1596
#
1452
# Description     : Called periodically to reset the daily statistics
1597
# Description     : Called periodically to reset the daily statistics