source: gs2-extensions/parallel-building/trunk/src/bin/script/manifestinator.pl@ 27587

Last change on this file since 27587 was 26930, checked in by jmt12, 11 years ago

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

  • Property svn:executable set to *
File size: 1.4 KB
RevLine 
[24677]1#!/usr/bin/perl
2
3use strict;
[26930]4use warnings;
[24677]5
[26930]6use List::Util 'shuffle';
7
[24677]8if (!defined $ARGV[0] || !-d $ARGV[0])
9{
[26930]10 print "usage: manifestinator.pl <import directory> [<max number of documents>]\n";
[24677]11 exit(0);
12}
13
[26930]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');
[24677]26print XMLOUT "<Manifest>\n";
27print XMLOUT " <Index>\n";
28
[26930]29&manifestify($ARGV[0], '', $max_docs, 0);
[24677]30
31print XMLOUT " </Index>\n";
32print XMLOUT "</Manifest>\n";
33
34close(XMLOUT);
35exit;
[24848]36
37sub manifestify
38{
[26930]39 my ($dir, $prefix, $max_docs, $current_count) = @_;
40 if ($max_docs > 0 && $current_count >= $max_docs)
41 {
42 return $current_count;
43 }
[24848]44 if (!opendir(DH, $dir))
45 {
46 die ("Failed to open import directory for reading!\n");
47 }
48 my @files = readdir(DH);
49 closedir(DH);
[26930]50 foreach my $file (shuffle @files)
[24848]51 {
52 if ($file =~ /^\./)
53 {
54 next;
55 }
56 my $path = $dir . '/' . $file;
57 if (-d $path)
58 {
59 my $new_prefix = $prefix . $file . '/';
[26930]60 $current_count = &manifestify($path, $new_prefix, $max_docs, $current_count);
[24848]61 }
62 else
63 {
64 print XMLOUT " <Filename>" . $prefix . $file . "</Filename>\n";
[26930]65 $current_count++;
[24848]66 }
[26930]67 if ($max_docs > 0 && $current_count >= $max_docs)
68 {
69 return $current_count;
70 }
[24848]71 }
[26930]72 return $current_count;
[24848]73}
Note: See TracBrowser for help on using the repository browser.