Changeset 26930 for gs2-extensions


Ignore:
Timestamp:
2013-02-26T09:49:36+13:00 (11 years ago)
Author:
jmt12
Message:

Randomized order of files, and added the ability to specify a maximum number of documents in the manifest

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gs2-extensions/parallel-building/trunk/src/bin/script/manifestinator.pl

    r24848 r26930  
    22
    33use strict;
     4use warnings;
     5
     6use List::Util 'shuffle';
    47
    58if (!defined $ARGV[0] || !-d $ARGV[0])
    69{
    7   print "usage: manifestinator.pl <import directory>\n";
     10  print "usage: manifestinator.pl <import directory> [<max number of documents>]\n";
    811  exit(0);
    912}
    1013
    11 open(XMLOUT, '>:utf8', 'manifest.xml');
     14my $max_docs = 0;
     15if (defined $ARGV[1] && $ARGV[1] =~ /^\d+$/)
     16{
     17  $max_docs = $ARGV[1];
     18}
     19
     20my $manifest_filename = 'manifest';
     21if ($max_docs > 0)
     22{
     23  $manifest_filename .= '-' . $max_docs;
     24}
     25open(XMLOUT, '>:utf8', $manifest_filename . '.xml');
    1226print XMLOUT "<Manifest>\n";
    1327print XMLOUT "  <Index>\n";
    1428
    15 &manifestify($ARGV[0], '');
     29&manifestify($ARGV[0], '', $max_docs, 0);
    1630
    1731print XMLOUT "  </Index>\n";
     
    2337sub manifestify
    2438{
    25   my ($dir, $prefix) = @_;
     39  my ($dir, $prefix, $max_docs, $current_count) = @_;
     40  if ($max_docs > 0 && $current_count >= $max_docs)
     41  {
     42    return $current_count;
     43  }
    2644  if (!opendir(DH, $dir))
    2745  {
     
    3048  my @files = readdir(DH);
    3149  closedir(DH);
    32   foreach my $file (sort @files)
     50  foreach my $file (shuffle @files)
    3351  {
    3452    if ($file =~ /^\./)
     
    4058    {
    4159      my $new_prefix = $prefix . $file . '/';
    42       &manifestify($path, $new_prefix);
     60      $current_count = &manifestify($path, $new_prefix, $max_docs, $current_count);
    4361    }
    4462    else
    4563    {
    4664      print XMLOUT "    <Filename>" . $prefix . $file . "</Filename>\n";
     65      $current_count++;
     66    }
     67    if ($max_docs > 0 && $current_count >= $max_docs)
     68    {
     69      return $current_count;
    4770    }
    4871  }
     72  return $current_count;
    4973}
Note: See TracChangeset for help on using the changeset viewer.