2 # Copyright (C) 2002 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: compilexml.in,v 1.1 2010-12-27 00:04:00 ivan Exp $
19 # Stanislav Sinyagin <ssinyagin@yahoo.com>
21 BEGIN { require '@torrus_config_pl@'; }
26 use Torrus::ConfigTree::XMLCompiler;
27 use Torrus::SiteConfig;
30 exit(1) if not Torrus::SiteConfig::verify();
42 my $ok = GetOptions ('tree=s' => \@trees,
45 'noval' => \$no_validation,
48 'verbose' => \$verbose,
49 'help' => \$help_needed);
51 if( not $ok or not (scalar(@trees) or $all_trees) or
52 $help_needed or scalar(@ARGV) > 0 )
54 print STDERR "Usage: $0 --tree=NAME [options...]\n",
56 " --tree=NAME tree name(s) to compile\n",
57 " --all compile all trees\n",
58 " --nods compile non-datasource configuration only\n",
59 " --noval disable parameter validation\n",
60 " --force force the compiler even if anoother " .
61 "compiler process is probably running\n",
62 " --debug set the log level to debug\n",
63 " --verbose set the log level to info\n",
64 " --help this help message\n";
70 @trees = Torrus::SiteConfig::listTreeNames();
75 Torrus::Log::setLevel('debug');
79 Torrus::Log::setLevel('verbose');
83 &Torrus::DB::setSafeSignalHandlers();
85 Verbose(sprintf('Torrus version %s', '@VERSION@'));
89 foreach my $tree ( @trees )
91 if( not Torrus::SiteConfig::treeExists( $tree ) )
93 Error("Tree named \"" . $tree . "\" does not exist");
97 &Torrus::DB::checkInterrupted();
99 Verbose("Compiling tree: $tree");
103 new Torrus::ConfigTree::XMLCompiler( -TreeName => $tree,
104 -NoDSRebuild => $no_ds,
105 -ForceWriter => $force );
106 if( not defined( $compiler ) )
108 Error('Cannot initialize compiler for tree ' . $tree . '. Exiting');
109 Error('If you are sure there are no other compiler processes ' .
110 'running, use the --force option');
115 my @xmlFiles = @Torrus::Global::xmlAlwaysIncludeFirst;
116 push( @xmlFiles, Torrus::SiteConfig::listXmlFiles( $tree ) );
117 push( @xmlFiles, @Torrus::Global::xmlAlwaysIncludeLast );
119 foreach my $xmlfile ( @xmlFiles )
121 if( not $compiler->compile( $xmlfile ) )
123 Error($xmlfile . ' compiled with errors'); $ok = 0;
129 Error("Errors found during XML compilation in the tree named \"" .
135 Verbose('Data post-processing...');
136 if( not $compiler->postProcess() )
138 Error('Errors found during post-processing');
144 Verbose('Skipping data validation...');
148 Verbose('Data validation...');
149 if( not $compiler->validate() )
151 Error('Errors found during validation process');
156 &Torrus::DB::checkInterrupted();
158 # Preserve the dynamic tokenset members
159 if( not $compiler->{'first_time_created'} )
161 my $oldConfig = new Torrus::ConfigTree( -TreeName => $tree );
162 if( defined( $oldConfig ) )
164 foreach my $ts ( $oldConfig->getTsets() )
166 if( $compiler->tsetExists( $ts ) )
168 foreach my $member ( $oldConfig->tsetMembers( $ts ) )
170 my $origin = $oldConfig->tsetMembers( $ts, $member );
171 if( defined( $origin ) and $origin ne 'static' )
173 my $path = $oldConfig->path($member);
174 if( $compiler->nodeExists( $path ) )
176 my $token = $compiler->token( $path );
177 $compiler->tsetAddMember
178 ( $ts, $token, $origin );
179 Verbose('Preserved dynamic tokenset member: ' .
180 $path . ' in ' . $ts);
191 &Torrus::DB::checkInterrupted();
193 $compiler->finalize( $ok );
195 &Torrus::DB::cleanupEnvironment();
197 $global_ok = $ok ? $global_ok:0;
200 exit($global_ok ? 0:1);
205 # indent-tabs-mode: nil
206 # perl-indent-level: 4