From: Dobrica Pavlinusic Date: Sun, 24 Sep 2006 15:53:54 +0000 (+0000) Subject: r962@llin: dpavlin | 2006-09-24 17:51:45 +0200 X-Git-Url: http://git.rot13.org/?a=commitdiff_plain;h=5d7f1e351801804ae07a5b319f4c1c3841682ff5;p=webpac2 r962@llin: dpavlin | 2006-09-24 17:51:45 +0200 first cut at using WebPAC::Config git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@684 07558da8-63fa-0310-ba24-9fe276d99e06 --- diff --git a/run.pl b/run.pl index 20e631d..cb72b60 100755 --- a/run.pl +++ b/run.pl @@ -14,7 +14,7 @@ use WebPAC::Normalize 0.11; use WebPAC::Output::TT; use WebPAC::Validate 0.06; use WebPAC::Output::MARC; -use YAML qw/LoadFile/; +use WebPAC::Config; use Getopt::Long; use File::Path; use Time::HiRes qw/time/; @@ -105,7 +105,7 @@ my $offset; my $limit; my $clean = 0; -my $config = 'conf/config.yml'; +my $config_path; my $debug = 0; my $only_filter; my $stats = 0; @@ -119,21 +119,13 @@ my $merge = 0; my $log = _new WebPAC::Common()->_get_logger(); -my $hostname = `hostname`; -chomp($hostname); -$hostname =~ s/\..+$//; -if (-e "conf/$hostname.yml") { - $config = "conf/$hostname.yml"; - $log->info("using host configuration file: $config"); -} - GetOptions( "limit=i" => \$limit, "offset=i" => \$offset, "clean" => \$clean, "one=s" => \$only_filter, "only=s" => \$only_filter, - "config" => \$config, + "config" => \$config_path, "debug+" => \$debug, "stats" => \$stats, "validate=s" => \$validate_path, @@ -146,11 +138,11 @@ GetOptions( "merge" => \$merge, ); -$config = LoadFile($config); +my $config = new WebPAC::Config( path => $config_path ); #print "config = ",dump($config) if ($debug); -die "no databases in config file!\n" unless ($config->{databases}); +die "no databases in config file!\n" unless ($config->databases); $log->info( "-" x 79 ); @@ -171,7 +163,7 @@ $validate = new WebPAC::Validate( ) if ($validate_path); -my $use_indexer = $config->{use_indexer} || 'hyperestraier'; +my $use_indexer = $config->use_indexer; if ($stats) { $log->debug("option --stats disables update of indexing engine..."); $use_indexer = undef; @@ -192,7 +184,7 @@ if ($parallel) { Proc::Queue::size($parallel); } -while (my ($database, $db_config) = each %{ $config->{databases} }) { +while (my ($database, $db_config) = each %{ $config->databases }) { my ($only_database,$only_input) = split(m#/#, $only_filter) if ($only_filter); next if ($only_database && $database !~ m/$only_database/i); @@ -212,7 +204,7 @@ while (my ($database, $db_config) = each %{ $config->{databases} }) { my $cfg_name = $use_indexer; $cfg_name =~ s/\-.*$//; - my $indexer_config = $config->{$cfg_name} || $log->logdie("can't find '$cfg_name' part in confguration"); + my $indexer_config = $config->get( $cfg_name ) || $log->logdie("can't find '$cfg_name' part in confguration"); $indexer_config->{database} = $database; $indexer_config->{clean} = $clean; $indexer_config->{label} = $db_config->{name}; @@ -280,7 +272,7 @@ while (my ($database, $db_config) = each %{ $config->{databases} }) { my $abs_path = abs_path($0); $abs_path =~ s#/[^/]*$#/#; - my $db_path = $config->{webpac}->{db_path} . '/' . $database; + my $db_path = $config->get('webpac')->{db_path} . '/' . $database; if ($clean) { $log->info("creating new database '$database' in $db_path"); @@ -309,15 +301,13 @@ while (my ($database, $db_config) = each %{ $config->{databases} }) { $log->info("database $database doesn't have inputs defined"); } - my @supported_inputs = keys %{ $config->{webpac}->{inputs} }; - foreach my $input (@inputs) { next if ($only_input && ($input->{name} !~ m#$only_input#i && $input->{type} !~ m#$only_input#i)); my $type = lc($input->{type}); - die "I know only how to handle input types ", join(",", @supported_inputs), " not '$type'!\n" unless (grep(/$type/, @supported_inputs)); + die "I know only how to handle input types ", join(",", $config->webpac('inputs') ), " not '$type'!\n" unless (grep(/$type/, $config->webpac('inputs'))); my $lookup; if ($input->{lookup}) { @@ -327,7 +317,7 @@ while (my ($database, $db_config) = each %{ $config->{databases} }) { delete( $input->{lookup} ); } - my $input_module = $config->{webpac}->{inputs}->{$type}; + my $input_module = $config->webpac('inputs')->{$type}; $log->info("working on input '$input->{name}' in $input->{path} [type: $input->{type}] using $input_module", $input->{lookup} ? "lookup '$input->{lookup}'" : "" @@ -341,7 +331,7 @@ while (my ($database, $db_config) = each %{ $config->{databases} }) { my $input_db = new WebPAC::Input( module => $input_module, - encoding => $config->{webpac}->{webpac_encoding}, + encoding => $config->webpac('webpac_encoding'), limit => $limit || $input->{limit}, offset => $offset, lookup_coderef => sub { @@ -453,7 +443,7 @@ while (my ($database, $db_config) = each %{ $config->{databases} }) { $indexer->add( id => $input->{name} . "/" . $mfn, ds => $ds, - type => $config->{$indexer_config}->{type}, + type => $config->get($indexer_config)->{type}, ) if ($indexer && $ds); if ($marc) {