Changeset 27858 for gs3-extensions/solr


Ignore:
Timestamp:
2013-07-15T19:51:31+12:00 (11 years ago)
Author:
davidb
Message:

Methods added to generate solr.xml.in from solr.xml and vice versa. Routines to help with installing Greenstone from a binary release, and having the solr.xml file just right (i.e. with the correct value of GSDL3HOME for the users install) so the solr-jdbm-demo collection.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gs3-extensions/solr/trunk/src/perllib/solrserver.pm

    r27847 r27858  
    209209}
    210210
     211sub filtered_copy
     212{
     213    my $self = shift @_;
     214    my ($src_file,$dst_file,$re_substitutions) = @_;
     215
     216    my $sep = shift @_ || "/";
     217    my $flags = shift @_ || "g";
     218
     219    # $re_substitutions is a hashmap of the form: [re_key] => subst_str
     220
     221    my $content = "";
     222
     223    if (open(FIN,'<:utf8',$src_file)) {
     224
     225    my $line;
     226    while (defined($line=<FIN>)) {
     227        $content .= $line;
     228    }
     229    }
     230
     231    close(FIN);
     232
     233    # perform RE string substitutions
     234    foreach my $re_key (keys %$re_substitutions) {
     235
     236    my $subst_str = $re_substitutions->{$re_key};
     237
     238    # Perform substitution of the form:
     239    #  $content =~ s/$re_key/$subst_str/g;
     240    # but allow allow separator char (default '/')
     241    # and flags (default 'g') to be parameterized
     242
     243    my $eval_str = "\$content =~ s$sep$re_key$sep$subst_str$sep$flags";
     244
     245    eval {
     246        $eval_str;
     247    };
     248    if ($@) {
     249        print STDERR "Warning: failed to evaluate\n   $eval_str\n$@\n";
     250    }
     251
     252    }
     253   
     254    if (open(FOUT, '>:utf8', $dst_file)) {
     255    print FOUT $content;
     256    close(FOUT);
     257    }
     258    else {
     259    print STDERR "Error: Failed to open file '$dst_file' for writing.\n$!\n";
     260    }   
     261}
     262
     263sub solr_xml_to_solr_xml_in
     264{
     265    my $self = shift @_;
     266
     267    my $gsdl3home = $ENV{'GSDL3HOME'};
     268    my $web_solr_ext_dir = &util::filename_cat($gsdl3home, "ext", "solr");
     269    my $web_solrxml_in = &util::filename_cat($web_solr_ext_dir, "solr.xml.in");
     270    my $web_solrxml = &util::filename_cat($web_solr_ext_dir, "solr.xml");
     271
     272    my $replacement_map = { "$gsdl3home" => "\\\@gsdl3home\\\@" };
     273 
     274    $self->filtered_copy($web_solrxml,$web_solrxml_in,$replacement_map, "^", "g");
     275}
     276
     277
     278sub solr_xml_in_to_solr_xml
     279{
     280    my $self = shift @_;
     281
     282    my $gsdl3home = $ENV{'GSDL3HOME'};
     283    my $web_solr_ext_dir = &util::filename_cat($gsdl3home, "ext", "solr");
     284    my $web_solrxml_in = &util::filename_cat($web_solr_ext_dir, "solr.xml.in");
     285    my $web_solrxml = &util::filename_cat($web_solr_ext_dir, "solr.xml");
     286   
     287    my $replacement_map = { "\\\@gsdl3home\\\@" => "$gsdl3home" };
     288 
     289    $self->filtered_copy($web_solrxml_in,$web_solrxml,$replacement_map, "^", "g");
     290}
     291
     292
    211293# Some of the Solr CoreAdmin API calls available.
    212294# See http://wiki.apache.org/solr/CoreAdmin
     
    219301
    220302    $self->_admin_service($cgi_get_args);
     303
     304    $self->solr_xml_to_solr_xml_in();
    221305}
    222306
     
    229313
    230314    $self->_admin_service($cgi_get_args);
     315
     316    $self->solr_xml_to_solr_xml_in();
    231317}
    232318
     
    239325
    240326    $self->_admin_service($cgi_get_args);
     327
     328    $self->solr_xml_to_solr_xml_in();
    241329}
    242330
     
    251339
    252340    $self->_admin_service($cgi_get_args);
     341
     342    $self->solr_xml_to_solr_xml_in();
    253343}
    254344
     
    275365
    276366    $self->_admin_service($cgi_get_args);
     367
     368    $self->solr_xml_to_solr_xml_in();
    277369}
    278370
     
    289381
    290382    $self->_admin_service($cgi_get_args);
     383
     384    $self->solr_xml_to_solr_xml_in();
    291385}
    292386
     
    295389    my $self = shift @_;
    296390
    297     my $ext_solrxml = &util::filename_cat($ENV{'GEXT_SOLR'}, "solr.xml");
    298     my $web_solrxml = &util::filename_cat($ENV{'GSDL3HOME'}, "ext", "solr", "solr.xml");
     391    my $ext_solrxml = &util::filename_cat($ENV{'GEXT_SOLR'}, "solr.xml.in");
     392    my $web_solrxml = &util::filename_cat($ENV{'GSDL3HOME'}, "ext", "solr", "solr.xml.in");
    299393
    300394    #print STDERR "@@@@ Copying $ext_solrxml to $web_solrxml...\n";
    301395
    302396    &FileUtils::copyFiles($ext_solrxml, $web_solrxml);
     397
     398    $self->solr_xml_in_to_solr_xml();
    303399}
    304400
Note: See TracChangeset for help on using the changeset viewer.