Changeset 26930 for gs2-extensions/parallel-building
- Timestamp:
- 2013-02-26T09:49:36+13:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gs2-extensions/parallel-building/trunk/src/bin/script/manifestinator.pl
r24848 r26930 2 2 3 3 use strict; 4 use warnings; 5 6 use List::Util 'shuffle'; 4 7 5 8 if (!defined $ARGV[0] || !-d $ARGV[0]) 6 9 { 7 print "usage: manifestinator.pl <import directory> \n";10 print "usage: manifestinator.pl <import directory> [<max number of documents>]\n"; 8 11 exit(0); 9 12 } 10 13 11 open(XMLOUT, '>:utf8', 'manifest.xml'); 14 my $max_docs = 0; 15 if (defined $ARGV[1] && $ARGV[1] =~ /^\d+$/) 16 { 17 $max_docs = $ARGV[1]; 18 } 19 20 my $manifest_filename = 'manifest'; 21 if ($max_docs > 0) 22 { 23 $manifest_filename .= '-' . $max_docs; 24 } 25 open(XMLOUT, '>:utf8', $manifest_filename . '.xml'); 12 26 print XMLOUT "<Manifest>\n"; 13 27 print XMLOUT " <Index>\n"; 14 28 15 &manifestify($ARGV[0], '' );29 &manifestify($ARGV[0], '', $max_docs, 0); 16 30 17 31 print XMLOUT " </Index>\n"; … … 23 37 sub manifestify 24 38 { 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 } 26 44 if (!opendir(DH, $dir)) 27 45 { … … 30 48 my @files = readdir(DH); 31 49 closedir(DH); 32 foreach my $file (s ort@files)50 foreach my $file (shuffle @files) 33 51 { 34 52 if ($file =~ /^\./) … … 40 58 { 41 59 my $new_prefix = $prefix . $file . '/'; 42 &manifestify($path, $new_prefix);60 $current_count = &manifestify($path, $new_prefix, $max_docs, $current_count); 43 61 } 44 62 else 45 63 { 46 64 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; 47 70 } 48 71 } 72 return $current_count; 49 73 }
Note:
See TracChangeset
for help on using the changeset viewer.