/[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 608 by dpavlin, Tue Aug 1 16:47:40 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  GetOptions(  GetOptions(
121          "limit=i" => \$limit,          "limit=i" => \$limit,
# Line 123  GetOptions( Line 132  GetOptions(
132          "marc-lint!" => \$marc_lint,          "marc-lint!" => \$marc_lint,
133          "marc-dump!" => \$marc_dump,          "marc-dump!" => \$marc_dump,
134          "parallel=i" => \$parallel,          "parallel=i" => \$parallel,
135            "only-links!" => \$only_links,
136            "merge" => \$merge,
137  );  );
138    
139  $config = LoadFile($config);  $config = LoadFile($config);
# Line 134  die "no databases in config file!\n" unl Line 145  die "no databases in config file!\n" unl
145  my $log = _new WebPAC::Common()->_get_logger();  my $log = _new WebPAC::Common()->_get_logger();
146  $log->info( "-" x 79 );  $log->info( "-" x 79 );
147    
148    
149    my $estcmd_fh;
150    my $estcmd_path = './estcmd-merge.sh';
151    if ($merge) {
152            open($estcmd_fh, '>', $estcmd_path) || $log->logdie("can't open $estcmd_path: $!");
153            print $estcmd_fh 'cd /data/estraier/_node/ || exit 1',$/;
154            print $estcmd_fh 'sudo /etc/init.d/hyperestraier stop',$/;
155            $log->info("created merge batch file $estcmd_path");
156    }
157    
158    
159  my $validate;  my $validate;
160  $validate = new WebPAC::Validate(  $validate = new WebPAC::Validate(
161          path => $validate_path,          path => $validate_path,
162  ) if ($validate_path);  ) if ($validate_path);
163    
164    
165  my $use_indexer = $config->{use_indexer} || 'hyperestraier';  my $use_indexer = $config->{use_indexer} || 'hyperestraier';
166  if ($stats) {  if ($stats) {
167          $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 177  my $total_rows = 0;
177  my $start_t = time();  my $start_t = time();
178    
179  my @links;  my @links;
 my $indexer;  
180    
181  if ($parallel) {  if ($parallel) {
182          $log->info("Using $parallel processes for speedup");          $log->info("Using $parallel processes for speedup");
# Line 175  while (my ($database, $db_config) = each Line 197  while (my ($database, $db_config) = each
197                  }                  }
198          }          }
199    
200            my $indexer;
201          if ($use_indexer) {          if ($use_indexer) {
202                  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");
203                  $indexer_config->{database} = $database;                  $indexer_config->{database} = $database;
204                  $indexer_config->{clean} = $clean;                  $indexer_config->{clean} = $clean;
205                  $indexer_config->{label} = $db_config->{name};                  $indexer_config->{label} = $db_config->{name};
206    
207                    # force clean if database has links
208                    $indexer_config->{clean} = 1 if ($db_config->{links});
209    
210                  if ($use_indexer eq 'hyperestraier') {                  if ($use_indexer eq 'hyperestraier') {
211    
212                          # open Hyper Estraier database                          # open Hyper Estraier database
# Line 203  while (my ($database, $db_config) = each Line 229  while (my ($database, $db_config) = each
229    
230    
231          #          #
232            # store Hyper Estraier links to other databases
233            #
234            if (ref($db_config->{links}) eq 'ARRAY' && $use_indexer) {
235                    foreach my $link (@{ $db_config->{links} }) {
236                            if ($use_indexer eq 'hyperestraier') {
237                                    if ($merge) {
238                                            print $estcmd_fh 'sudo -u www-data estcmd merge ' . $database . ' ' . $link->{to},$/;
239                                    } else {
240                                            $log->info("saving link $database -> $link->{to} [$link->{credit}]");
241                                            push @links, sub {
242                                                    $log->info("adding link $database -> $link->{to} [$link->{credit}]");
243                                                    $indexer->add_link(
244                                                            from => $database,
245                                                            to => $link->{to},
246                                                            credit => $link->{credit},
247                                                    );
248                                            };
249                                    }
250                            } else {
251                                    $log->warn("NOT IMPLEMENTED WITH $use_indexer: adding link $database -> $link->{to} [$link->{credit}]");
252                            }
253                    }
254            }
255            next if ($only_links);
256    
257    
258            #
259          # now WebPAC::Store          # now WebPAC::Store
260          #          #
261          my $abs_path = abs_path($0);          my $abs_path = abs_path($0);
# Line 397  while (my ($database, $db_config) = each Line 450  while (my ($database, $db_config) = each
450                  )                  )
451          );          );
452    
         #  
         # 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}]");  
                         }  
                 }  
         }  
453    
454          # end forked process          # end forked process
455          if ($parallel) {          if ($parallel) {
# Line 429  if ($parallel) { Line 465  if ($parallel) {
465          $log->info("all parallel processes finished");          $log->info("all parallel processes finished");
466  }  }
467    
468  foreach my $link (@links) {  #
469          $log->info("adding link $link->{from} -> $link->{to} [$link->{credit}]");  # handle links or merge after indexing
470          $indexer->add_link( %{ $link } );  #
471    
472    if ($merge) {
473            print $estcmd_fh 'sudo /etc/init.d/hyperestraier start',$/;
474            close($estcmd_fh);
475            chmod 0700, $estcmd_path || $log->warn("can't chmod 0700 $estcmd_path: $!");
476            system $estcmd_path;
477    } else {
478            foreach my $link (@links) {
479                    $log->logdie("coderef in link ", Dumper($link), " is ", ref($link), " and not CODE") unless (ref($link) eq 'CODE');
480                    $link->();
481            }
482  }  }
   

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

  ViewVC Help
Powered by ViewVC 1.1.26