1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594
|
package Grid::GPT::PackageFilelist::List;
$VERSION = 1.00;
use strict;
use vars qw( $AUTOLOAD @ISA @EXPORT ); # Keep 'use strict' happy
use Carp;
require Exporter;
require AutoLoader;
require Grid::GPT::GPTObject;
@ISA = qw(Exporter AutoLoader Grid::GPT::GPTObject);
# Items to export into callers namespace by default. Note: do not export
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.
@EXPORT = qw(
);
#
# include standard modules
#
require Grid::GPT::PackageFile;
#
# data internal to the class
#
my $_count = 0;
#
# Class methods
#
sub get_count
{
$_count;
}
sub _incr_count { ++$_count }
sub _decr_count { --$_count }
### new( $caller, %args )
#
# Object Constructor
#
sub new
{
my $caller = shift;
my(%args) = @_;
my $caller_is_obj = ref($caller);
my $class = $caller_is_obj || $caller;
#
# bless $self and up the ref count
#
my $self = bless {}, $class;
if ( scalar(@_) == 0 )
{
$self->_incr_count();
return $self;
}
#
# handle arguments
#
my $pkginfo = $args{'pkginfo'};
my $masterFilelist = $args{'masterFilelist'};
my $relativePath = $args{'relativePath'};
if ( defined($pkginfo) )
{
$self->{'pkginfo'} = $pkginfo;
}
#
# store our relativePath
#
$self->{'relativePath'} = $relativePath;
#
# store a reference to our master filelist
#
$self->setMasterFilelist( mf => $masterFilelist );
#
# create our internal filelist structure
#
$self->{'filelist'} = {};
$self->{'filelistOrder'} = [];
#
# increment refcount
#
$self->_incr_count();
return $self;
}
sub DESTROY
{
$_[0]->_decr_count();
}
sub AUTOLOAD
{
}
END { }
#
# Standard methods
#
### addToMasterFilelist( )
#
# add all of the files stored internally to the master filelist
#
sub addToMasterFilelist
{
my($self, %args) = @_;
if (defined($self->{'masterFilelist'}))
{
my $list = $self->getFilelistObjects();
for my $f (@$list)
{
$self->{'masterFilelist'}->addFile( file => $f );
}
}
}
### setMasterFilelist( mf => $masterFilelist )
#
# set the master filelist to which we should add files
#
sub setMasterFilelist
{
my($self, %args) = @_;
$self->{'masterFilelist'} = $args{'mf'};
}
### addFile( file => $file )
#
# add file to our internal filelist
#
sub addFile
{
my($self, %args) = @_;
#
# handle arguments
#
my $file = $args{'file'};
my $filePath = $file->getPath();
if ( !defined($file) )
{
die("ERROR: file object in package list is undefined");
}
if ( ! grep { $file->isEqual($_) } values %{$self->{'filelist'}} )
{
# add the file to our internal filelist
$self->{'filelist'}->{$filePath} = $file;
push(@{$self->{'filelistOrder'}}, $filePath);
if (defined($self->{'masterFilelist'}))
{
$self->{'masterFilelist'}->addFile( file => $file );
}
return 1;
}
# the file is in our internal list already, but lets check to see if this listing
# has any extra information
my $storedFile = $self->{'filelist'}->{$filePath};
if ( !$file->md5IsAllowed() )
{
$storedFile->turnOffMD5();
}
if ( $storedFile->groomMD5( file => $file ) )
{
return 1;
}
return 0;
}
### addFilePath( path => $path )
#
# add our file matching path to our internal filelist
#
sub addFilePath
{
my($self, %args) = @_;
#
# handle arguments
#
my $filePath = $args{'path'};
my $file = new Grid::GPT::PackageFile(
pkginfo => $self->{'pkginfo'},
relativePath => $self->{'relativePath'},
);
$file->setPath( path => $filePath );
return $self->addFile( file => $file );
}
### removeFile( file => $file )
#
# remove our file from our internal filelist
#
sub removeFile
{
my($self, %args) = @_;
#
# handle arguments
#
my $file = $args{'file'};
my $filePath = $file->getPath();
if ( !defined($file) )
{
die("ERROR: file object in package list is undefined");
}
if (defined($self->{'masterFilelist'}))
{
$self->{'masterFilelist'}->removeFile( file => $file );
}
if ( grep { $file->isEqual($_) } values %{$self->{'filelist'}} )
{
# add the file to our internal filelist
delete($self->{'filelist'}->{$filePath});
my @neworder = map { $_ }
grep
{
$_ ne $filePath;
} @{$self->{'filelistOrder'}};
$self->{'filelistOrder'} = \@neworder;
return 1;
}
return 0;
}
### removeFilePath( path => $path )
#
# remove our file matching path from our internal filelist
#
sub removeFilePath
{
my($self, %args) = @_;
#
# handle arguments
#
my $filePath = $args{'path'};
if ( defined($self->{'filelist'}->{$filePath}) )
{
$self->{'filelist'}->{$filePath}->active(0);
}
return 1;
}
sub cleanupList
{
my $self = shift;
#
# cleanup the filelist hash
#
if (defined($self->{'filelist'}))
{
map {
if ( defined($self->{'filelist'}->{$_}) and !$self->{'filelist'}->{$_}->isActive() )
{
delete($self->{'filelist'}->{$_});
}
} keys %{$self->{'filelist'}};
}
#
# cleanup the filelistOrder array
#
my @newOrder;
if (defined($self->{'filelistOrder'}))
{
@newOrder = map { $_; }
grep {
if ( defined($self->{'filelist'}->{$_}) and $self->{'filelist'}->{$_}->isActive() )
{
$_;
}
} @{$self->{'filelistOrder'}};
$self->{'filelistOrder'} = \@newOrder;
}
}
### getList( )
#
# return a reference to an array that contains all of the files in the
# current filelist
#
sub getList
{
my $self = shift;
$self->cleanupList();
#
# in order of the filelist order array, create a list of entries that contains
# each of the files in the internal filelist.
#
my @list = map { $self->{'filelist'}->{$_} } @{$self->{'filelistOrder'}};
return \@list;
}
sub sort
{
my $self = shift;
my @sorted = sort(keys %{$self->{'filelist'}});
$self->{'filelistOrder'} = \@sorted;
return 1;
}
### getFilelist( )
#
# return a reference to an array that contains all of the files in the
# current filelist
#
sub getFilelist
{
my $self = shift;
return $self->getList();
}
### stamp( type => $type )
#
# stamp each of the files in our list with their current md5 checksums
#
sub stamp
{
my $self = shift;
my(%args) = @_;
my $type = $args{'type'};
for my $f (values %{$self->{'filelist'}})
{
$f->stamp(type => $type);
}
return 1;
}
sub addMetadataFile
{
my $self = shift;
my(%args) = @_;
if ( !defined($self->{'metadataFiles'}) )
{
$self->{'metadataFiles'} = [];
}
my $file = $args{'file'};
if ( ! grep(/^$file$/, @{$self->{'metadataFiles'}}) )
{
push(@{$self->{'metadataFiles'}}, $file);
}
}
sub triageMetadataFiles
{
my $self = shift;
#
# add each of the entries in our metadata filelist to our internal filelist
#
my $metadataFiles = $self->{'metadataFiles'};
for my $f (@{$self->{'metadataFiles'}})
{
$self->addFilePath( path => $f );
}
#
# now we go through our internal filelist and turn off md5 checksums for each of the entries
#
my $list = $self->{'filelist'};
my @metadataKeys = map { $_ } grep { my $x = $_; grep(/^\Q$x\E$/, @$metadataFiles); } keys %$list;
for my $m (@metadataKeys)
{
$list->{$m}->turnOffMD5();
}
}
sub isEmpty
{
my $self = shift;
#
# pull our filelist array into our scope
#
my $filelist = $self->getList();
if ( scalar(@$filelist) eq 0 )
{
return 1;
}
else
{
return 0;
}
}
sub setFilelist
{
my $self = shift;
my(%args) = @_;
#
# read in the list of objects
#
my @list = @{$args{'list'}};
my $tmpFilelist = \@list;
#
# nuke the old filelist data
#
$self->{'filelist'} = {};
$self->{'filelistOrder'} = [];
for my $file (@$tmpFilelist)
{
my $tmpFile = $file->clone();
my $path = $tmpFile->getPath();
$tmpFile->setPkgNode( node => $self->{'pkginfo'} );
$self->{'filelist'}->{$path} = $tmpFile;
if ( !grep(/^$path$/, @{$self->{'filelistOrder'}}) )
{
push(@{$self->{'filelistOrder'}}, $path);
}
}
}
sub addFilelist
{
my $self = shift;
my(%args) = @_;
#
# read in the list of objects
#
my @list = @{$args{'list'}};
my $tmpFilelist = \@list;
for my $file (@$tmpFilelist)
{
my $tmpFile = $file->clone();
my $path = $tmpFile->getPath();
$tmpFile->setPkgNode( node => $self->{'pkginfo'} );
$self->{'filelist'}->{$path} = $tmpFile;
if ( !grep(/^$path$/, @{$self->{'filelistOrder'}}) )
{
push(@{$self->{'filelistOrder'}}, $path);
}
}
}
sub getFilelistFiles
{
my $self = shift;
if ( $self->isEmpty() )
{
return [];
}
my $tempList = $self->getList();
my @list = map { $_->getPath() } @$tempList;
return \@list;
}
sub getFilelistObjects
{
my $self = shift;
if ( $self->isEmpty() )
{
return [];
}
my $list = $self->getList();
return $list;
}
1; # Ensure that the module can be successfully use'd
__END__
=head1 NAME
Grid::GPT::PackageFilelist::List - Perl extension for storing internal file
object listings
=head1 SYNOPSIS
use Grid::GPT::PackageFilelist::List;
my $md5 = new Grid::GPT::PackageFilelist::List(
masterFilelist => $masterFilelist,
pkginfo => $pkginfo,
relativePath => $relativePath,
);
=head1 DESCRIPTION
I<Grid::GPT::PackageFilelist::List> is the internal list of file objects
that each of the filelist types add to via their ListInterface objects. This
List object also optionally stores a reference to the master filelist object
and will, if this master filelist is defined, add each file object to it
as well as adding it to its internal list.
=head1 AUTHOR
Chase Phillips <cphillip@ncsa.uiuc.edu>
=head1 SEE ALSO
perl(1) Grid::GPT::PackageFilelist(1) Grid::GPT::GPTFilelist(1)
=cut
|