/[webpac2]/trunk/run.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/run.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 606 by dpavlin, Tue Aug 1 13:59:47 2006 UTC revision 611 by dpavlin, Wed Aug 23 10:04:08 2006 UTC
# Line 89  Force dump or input and marc record for Line 89  Force dump or input and marc record for
89  Run databases in parallel (aproximatly same as number of processors in  Run databases in parallel (aproximatly same as number of processors in
90  machine if you want to use full load)  machine if you want to use full load)
91    
92    =item --only-links
93    
94    Create just links
95    
96    =item --merge
97    
98    Create merged index of databases which have links
99    
100  =back  =back
101    
102  =cut  =cut
# Line 105  my $validate_path; Line 113  my $validate_path;
113  my ($marc_normalize, $marc_output);  my ($marc_normalize, $marc_output);
114  my $marc_lint = 1;  my $marc_lint = 1;
115  my $marc_dump = 0;  my $marc_dump = 0;
   
116  my $parallel = 0;  my $parallel = 0;
117    my $only_links = 0;
118    my $merge = 0;
119    
120    my $log = _new WebPAC::Common()->_get_logger();
121    
122    my $hostname = `hostname`;
123    chomp($hostname);
124    $hostname =~ s/\..+$//;
125    if (-e "conf/$hostname.yml") {
126            $config = "conf/$hostname.yml";
127            $log->info("using host configuration file: $config");
128    }
129    
130  GetOptions(  GetOptions(
131          "limit=i" => \$limit,          "limit=i" => \$limit,
# Line 123  GetOptions( Line 142  GetOptions(
142          "marc-lint!" => \$marc_lint,          "marc-lint!" => \$marc_lint,
143          "marc-dump!" => \$marc_dump,          "marc-dump!" => \$marc_dump,
144          "parallel=i" => \$parallel,          "parallel=i" => \$parallel,
145            "only-links!" => \$only_links,
146            "merge" => \$merge,
147  );  );
148    
149  $config = LoadFile($config);  $config = LoadFile($config);
150    
151  print "config = ",dump($config) if ($debug);  #print "config = ",dump($config) if ($debug);
152    
153  die "no databases in config file!\n" unless ($config->{databases});  die "no databases in config file!\n" unless ($config->{databases});
154    
 my $log = _new WebPAC::Common()->_get_logger();  
155  $log->info( "-" x 79 );  $log->info( "-" x 79 );
156    
157    
158    my $estcmd_fh;
159    my $estcmd_path = './estcmd-merge.sh';
160    if ($merge) {
161            open($estcmd_fh, '>', $estcmd_path) || $log->logdie("can't open $estcmd_path: $!");
162            print $estcmd_fh 'cd /data/estraier/_node/ || exit 1',$/;
163            print $estcmd_fh 'sudo /etc/init.d/hyperestraier stop',$/;
164            $log->info("created merge batch file $estcmd_path");
165    }
166    
167    
168  my $validate;  my $validate;
169  $validate = new WebPAC::Validate(  $validate = new WebPAC::Validate(
170          path => $validate_path,          path => $validate_path,
171  ) if ($validate_path);  ) if ($validate_path);
172    
173    
174  my $use_indexer = $config->{use_indexer} || 'hyperestraier';  my $use_indexer = $config->{use_indexer} || 'hyperestraier';
175  if ($stats) {  if ($stats) {
176          $log->debug("option --stats disables update of indexing engine...");          $log->debug("option --stats disables update of indexing engine...");
# Line 154  my $total_rows = 0; Line 186  my $total_rows = 0;
186  my $start_t = time();  my $start_t = time();
187    
188  my @links;  my @links;
 my $indexer;  
189    
190  if ($parallel) {  if ($parallel) {
191          $log->info("Using $parallel processes for speedup");          $log->info("Using $parallel processes for speedup");
# Line 175  while (my ($database, $db_config) = each Line 206  while (my ($database, $db_config) = each
206                  }                  }
207          }          }
208    
209            my $indexer;
210          if ($use_indexer) {          if ($use_indexer) {
211                  my $indexer_config = $config->{$use_indexer} || $log->logdie("can't find '$use_indexer' part in confguration");                  my $indexer_config = $config->{$use_indexer} || $log->logdie("can't find '$use_indexer' part in confguration");
212                  $indexer_config->{database} = $database;                  $indexer_config->{database} = $database;
213                  $indexer_config->{clean} = $clean;                  $indexer_config->{clean} = $clean;
214                  $indexer_config->{label} = $db_config->{name};                  $indexer_config->{label} = $db_config->{name};
215    
216                    # force clean if database has links
217                    $indexer_config->{clean} = 1 if ($db_config->{links});
218    
219                  if ($use_indexer eq 'hyperestraier') {                  if ($use_indexer eq 'hyperestraier') {
220    
221                          # open Hyper Estraier database                          # open Hyper Estraier database
# Line 203  while (my ($database, $db_config) = each Line 238  while (my ($database, $db_config) = each
238    
239    
240          #          #
241            # store Hyper Estraier links to other databases
242            #
243            if (ref($db_config->{links}) eq 'ARRAY' && $use_indexer) {
244                    foreach my $link (@{ $db_config->{links} }) {
245                            if ($use_indexer eq 'hyperestraier') {
246                                    if ($merge) {
247                                            print $estcmd_fh 'sudo -u www-data estcmd merge ' . $database . ' ' . $link->{to},$/;
248                                    } else {
249                                            $log->info("saving link $database -> $link->{to} [$link->{credit}]");
250                                            push @links, sub {
251                                                    $log->info("adding link $database -> $link->{to} [$link->{credit}]");
252                                                    $indexer->add_link(
253                                                            from => $database,
254                                                            to => $link->{to},
255                                                            credit => $link->{credit},
256                                                    );
257                                            };
258                                    }
259                            } else {
260                                    $log->warn("NOT IMPLEMENTED WITH $use_indexer: adding link $database -> $link->{to} [$link->{credit}]");
261                            }
262                    }
263            }
264            next if ($only_links);
265    
266    
267            #
268          # now WebPAC::Store          # now WebPAC::Store
269          #          #
270          my $abs_path = abs_path($0);          my $abs_path = abs_path($0);
# Line 397  while (my ($database, $db_config) = each Line 459  while (my ($database, $db_config) = each
459                  )                  )
460          );          );
461    
         #  
         # add Hyper Estraier links to other databases  
         #  
         if (ref($db_config->{links}) eq 'ARRAY' && $use_indexer) {  
                 foreach my $link (@{ $db_config->{links} }) {  
                         if ($use_indexer eq 'hyperestraier') {  
                                 $log->info("saving link $database -> $link->{to} [$link->{credit}]");  
                                 push @links, {  
                                         from => $database,  
                                         to => $link->{to},  
                                         credit => $link->{credit},  
                                 };  
                         } else {  
                                 $log->warn("NOT IMPLEMENTED WITH $use_indexer: adding link $database -> $link->{to} [$link->{credit}]");  
                         }  
                 }  
         }  
462    
463          # end forked process          # end forked process
464          if ($parallel) {          if ($parallel) {
# Line 429  if ($parallel) { Line 474  if ($parallel) {
474          $log->info("all parallel processes finished");          $log->info("all parallel processes finished");
475  }  }
476    
477  foreach my $link (@links) {  #
478          $log->info("adding link $link->{from} -> $link->{to} [$link->{credit}]");  # handle links or merge after indexing
479          $indexer->add_link( %{ $link } );  #
480    
481    if ($merge) {
482            print $estcmd_fh 'sudo /etc/init.d/hyperestraier start',$/;
483            close($estcmd_fh);
484            chmod 0700, $estcmd_path || $log->warn("can't chmod 0700 $estcmd_path: $!");
485            system $estcmd_path;
486    } else {
487            foreach my $link (@links) {
488                    $log->logdie("coderef in link ", Dumper($link), " is ", ref($link), " and not CODE") unless (ref($link) eq 'CODE');
489                    $link->();
490            }
491  }  }
   

Legend:
Removed from v.606  
changed lines
  Added in v.611

  ViewVC Help
Powered by ViewVC 1.1.26