#!/usr/bin/env perl ## ## $Id: nmi_meta_create.pl,v 1.1 2005/10/03 19:32:10 pavlo Exp $ ## ## Takes in an NMI submission file and splits out lists of ## prereqs to create meta-submission files ## ## Example: ## The original submit file contains the following list of prereqs: ## prereqs = {java-1.2.1, java-1.4.2_05}, byacc-1.9, {gcc-3.0.1, gcc-3.0.2} ## ## When this file is submitted to this program it will create multiple copies ## of the submit file, one for each of the permutations of this the prereqs ## Each of these files will contain a different combination of the prereqs ## ## metatest.submit.000 > prereqs = byacc-1.9, java-1.4.2_05, gcc-3.0.2 ## metatest.submit.001 > prereqs = byacc-1.9, java-1.4.2_05, gcc-3.0.1 ## metatest.submit.002 > prereqs = byacc-1.9, java-1.2.1, gcc-3.0.2 ## metatest.submit.003 > prereqs = byacc-1.9, java-1.2.1, gcc-3.0.1 ## use strict; use warnings; use lib $ENV{'NMI_LIB'} || "/nmi/lib"; use NmiTools; ## ## We need an NMI submit file to parse ## my $cmdfile = $ARGV[0] or die(usage()); ## ## What to separate the prereq packages with ## my $DELIMITER = ","; ## ## Parse input file and stash its attr/value pairs in %cmdfile ## my %cmdfile = NmiTools::parse_cmdfile($cmdfile); ## ## Check the prereqs for lists of packages ## my $single_prereqs = ""; my @prereqs_list = (); my $add = ""; foreach (split(/\}/, $cmdfile{'prereqs'})) { my ($single, $multi) = /(.*)\{(.*)$/; push(@prereqs_list, [ split(/,/, $multi) ] ); ## ## Clean up the single prereqs ## foreach (split(/,/, $single)) { s/ //g; if (length($_) > 0) { $single_prereqs .= $add.$_; $add = $DELIMITER; } } # FOREACH } # FOREACH ## ## Build the lists of prereqs ## my @complete_prereqs = (); buildPrereqs(0, $single_prereqs); ## ## Now dump out the various command files with the new prereqs ## my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); my $timestamp = sprintf("%4d-%02d-%02d %02d:%02d:%02d", $year+1900,$mon+1,$mday,$hour,$min,$sec); for my $ctr ( 0 ... $#complete_prereqs) { ## ## Create the new file ## my $curFile = $cmdfile.".".sprintf("%03d", $ctr); open(FILE, "> $curFile") or die("ERROR: Unable to open '$curFile' for writing"); print FILE "#######################################\n"; print FILE "# $curFile\n"; print FILE "# Created By: $0\n"; print FILE "# Date: $timestamp\n"; print FILE "# Original File: $cmdfile\n"; print FILE "#######################################\n"; foreach (sort keys %cmdfile) { print FILE "$_\t= ".("$_" eq "prereqs" ? $complete_prereqs[$ctr] : $cmdfile{$_})."\n"; } # FOREACH close(FILE); print "Created $curFile\n"; } # FOREACH exit; ####################################################### ## buildPrereqs() ## Recursive call to build complete_prereqs list ####################################################### sub buildPrereqs { my $ctr = shift(@_); my $prereqs = shift(@_); foreach (@{$prereqs_list[$ctr]}) { s/ //g; ## ## First add the new prereq to the list ## my $temp = $prereqs.$DELIMITER.$_; ## ## Now check whether we're reached the bottom of the stack ## if ($ctr == $#prereqs_list) { ## ## We have! So we'll add this new prereq to the list ## unshift(@complete_prereqs, $temp); ## ## Otherwise call for the next prereq set to add themselves ## } else { buildPrereqs($ctr + 1, $temp); } } # FOREACH } # SUB ####################################################### ## usage() ## Print the command-line args for this program ####################################################### sub usage { my $usage = "Usage: $0 submit.file\n"; $usage; } # SUB