Changeset 18918


Ignore:
Timestamp:
2009-04-08T14:18:44+12:00 (15 years ago)
Author:
kjdon
Message:

added -use_collection_plugin_options option. if set, will read in the collect.cfg file for specified collection, and use teh plugin options when loading the plugin for exploding

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gsdl/trunk/bin/script/explode_metadata_database.pl

    r18590 r18918  
    8282    'deft' => "100",
    8383    'reqd' => "no" },
     84      { 'name' => "collection",
     85    'desc' => "{explode.collection}",
     86    'type' => "string",
     87    'reqd' => "no",
     88    'hiddengli' => "yes"},
     89      { 'name' => "use_collection_plugin_options",
     90    'desc' => "{explode.use_collection_plugin_options}",
     91    'type' => "flag",
     92    'reqd' => "no",
     93    'hiddengli' => "yes"},
    8494      { 'name' => "plugin_options",
    8595    'desc' => "{explode.plugin_options}",
    86     'type' => "string",
    87     'reqd' => "no",
    88     'modegli' => "3"},
    89       { 'name' => "collection",
    90     'desc' => "{explode.collection}",
    9196    'type' => "string",
    9297    'reqd' => "no",
     
    115120{
    116121    my ($language, $input_encoding, $metadata_set, $plugin,
    117     $document_field, $document_prefix, $document_suffix, $records_per_folder, $plugin_options, $collection, $verbosity);
     122    $document_field, $document_prefix, $document_suffix, $records_per_folder, $plugin_options, $collection, $use_collection_plugin_options, $verbosity);
    118123
    119124    my $xml = 0;
     
    186191        die "\n";
    187192    }
    188     }
    189    
     193    } else {
     194    undef $collection;
     195    }
     196   
     197    if ($use_collection_plugin_options) {
     198    if (defined $plugin_options && $plugin_options =~ /\w/) {
     199        print STDERR "Error: you cannot have -use_collection_plugin_options and -plugin_options set at the same time\n";
     200        die "\n";
     201    }
     202    if (not defined $collection) {
     203        print STDERR "Error: you must specify a collection using -collection to use -use_collection_plugin_options\n";
     204        die "\n";
     205    }
     206    }
    190207    my $plugobj;
    191208    require "$plugin.pm";
    192209
    193     if (defined $plugin_options && $plugin_options =~ /\w/) {
     210    my $plugin_options_string = "";
     211    if ($use_collection_plugin_options) {
     212    # read in the collect.cfg file
     213    # Read in the collection configuration file.
     214    my ($configfilename, $gs_mode) = &colcfg::get_collect_cfg_name(STDERR);
     215    my $collectcfg;
     216    if ($gs_mode eq "gs2") {
     217        $collectcfg = &colcfg::read_collect_cfg ($configfilename);
     218    } elsif ($gs_mode eq "gs3") {
     219        $collectcfg = &colcfg::read_collection_cfg_xml ($configfilename);
     220    }
     221    $plugin_options_string = &get_plugin_options($collectcfg, $plugin);
     222    }
     223    elsif (defined $plugin_options && $plugin_options =~ /\w/) {
    194224    my @options = split(/\s/, $plugin_options);
    195225    map { $_ = "\"$_\"" unless $_ =~ /^\"/; } @options;
    196     $plugin_options = join (",", @options);
    197     eval ("\$plugobj = new $plugin([], [$plugin_options])");
     226    $plugin_options_string= join (",", @options);
     227    }
     228
     229    if ($plugin_options_string eq "") {
     230    eval ("\$plugobj = new $plugin()");
    198231    die "$@" if $@;
    199232    } else {
    200     eval ("\$plugobj = new $plugin()");
     233    eval ("\$plugobj = new $plugin([], [$plugin_options_string])");
    201234    die "$@" if $@;
    202     }
     235    }
     236   
    203237    # ...and initialize it
    204238    $plugobj->init($verbosity, "STDERR", "STDERR");
     
    558592}
    559593
     594sub get_plugin_options {
     595    my ($collectcfg, $plugin)  = @_;
     596   
     597    my $plugin_list = $collectcfg ->{'plugin'};
     598   
     599    foreach my $pluginoptions (@$plugin_list) {
     600    my $pluginname = shift @$pluginoptions;
     601    next unless $pluginname eq $plugin;
     602    map { $_ = "\"$_\""; } @$pluginoptions;
     603    my $options = join (",", @$pluginoptions);
     604    return $options;
     605    }
     606    return "";
     607}
     608
    560609&main(@ARGV);
    561610
Note: See TracChangeset for help on using the changeset viewer.