2 # Copyright (C) 2005 Stanislav Sinyagin
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
18 # $Id: ttproclist.in,v 1.1 2010-12-27 00:04:03 ivan Exp $
19 # Stanislav Sinyagin <ssinyagin@yahoo.com>
32 my $creator = "Torrus version @VERSION@\n" .
33 "This file was generated by command:\n" .
35 foreach my $arg ( @ARGV )
39 $creator .= ' ' . $arg . ' ';
43 $creator .= "\'" . $arg . "\'\\\n";
46 $creator .= "\nOn " . scalar(localtime(time));
49 my $ok = GetOptions( 'tmpl=s' => \$template,
51 'nodes=s' => \$nodelist,
52 'param=s' => \$parameters );
54 if( not $ok or not $template or not $outfile or not $nodelist)
56 print STDERR "Process a template with a nodelist\n\n";
58 print STDERR "Usage: $0 options...\n",
59 "Mandatory options:\n",
60 " --tmpl=filename template file name\n",
61 " --out=filename output file\n",
62 " --nodes=filename file with nodes\n",
64 " --param=NAME:VALUE,NAME:VALUE... parameters passed to template\n";
70 if( not open( NODES, $nodelist ) )
72 print STDERR "Cannot open $nodelist: $!\n";
79 push( @rawnodes, split( /\s+/ ) );
84 foreach my $node ( @rawnodes )
87 if( $node =~ /([^:]+):(.+)/ )
93 $nodes{$node} = $symname;
97 if( defined( $parameters ) )
99 foreach my $pair ( split( '\s*,\s*', $parameters ) )
101 my ($name, $val) = split( '\s*:\s*', $pair );
102 $params{$name} = $val;
106 my $tt = new Template( INCLUDE_PATH => '@tmpluserdir@',
115 'nodesfile' => $nodelist,
116 'creator' => $creator,
117 'lc' => sub{ return lc $_[0] },
118 'uc' => sub{ return uc $_[0] }
121 my $result = $tt->process($template, $vars, $outfile);
125 print STDERR "Error while processing template: ".$tt->error()."\n";
128 exit( $result ? 0:1 );
133 # indent-tabs-mode: nil
134 # perl-indent-level: 4