Changeset 16968


Ignore:
Timestamp:
2008-08-22T15:07:29+12:00 (16 years ago)
Author:
kjdon
Message:

added two options - collection, used to set gsdlcollectdir if specified, so that collection specific files can be used; plugin_options, used to add options to pass to the plugin (eg metadata_mapping_file for MARCPlugin. Also fixed two bugs found with documents_directory being empty for every record except for when a new directory is created, and misnamed function call

File:
1 edited

Legend:

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

    r16790 r16968  
    1515use printusage;
    1616use parse2;
     17use colcfg;
     18
    1719use FileHandle;
    1820
     
    8082    'deft' => "100",
    8183    'reqd' => "no" },
     84      { 'name' => "plugin_options",
     85    'desc' => "options for the plugin",
     86    'type' => "string",
     87    'reqd' => "no",
     88    'modegli' => "3"},
     89      { 'name' => "collection",
     90    'desc' => "collection for file",
     91    'type' => "string",
     92    'reqd' => "no",
     93    'modegli' => "3"},
    8294      { 'name' => "verbosity",
    8395    'desc' => "{import.verbosity}",
     
    103115{
    104116    my ($language, $input_encoding, $metadata_set, $plugin,
    105     $document_field, $document_prefix, $document_suffix, $records_per_folder, $verbosity);
     117    $document_field, $document_prefix, $document_suffix, $records_per_folder, $plugin_options, $collection, $verbosity);
    106118
    107119    my $xml = 0;
     
    169181    $metadata_set = "";
    170182    }
    171 
     183    if (defined $collection && $collection =~ /\w/) {
     184    if (($collection = &colcfg::use_collection("", $collection, "")) eq "") {
     185        print STDERR "Collection $collection does not exist\n";
     186        die "\n";
     187    }
     188    }
     189   
    172190    my $plugobj;
    173191    require "$plugin.pm";
    174     eval ("\$plugobj = new $plugin()");
    175     die "$@" if $@;
    176 
     192
     193    if (defined $plugin_options && $plugin_options =~ /\w/) {
     194    my @options = split(/\s/, $plugin_options);
     195    map { $_ = "\"$_\"" unless $_ =~ /^\"/; } @options;
     196    $plugin_options = join (",", @options);
     197    eval ("\$plugobj = new $plugin([], [$plugin_options])");
     198    die "$@" if $@;
     199    } else {
     200    eval ("\$plugobj = new $plugin()");
     201    die "$@" if $@;
     202    }
    177203    # ...and initialize it
    178     $plugobj->init(1, "STDERR", "STDERR");
    179    
     204    $plugobj->init($verbosity, "STDERR", "STDERR");
     205
    180206    if ($input_encoding eq "auto") {
    181207    ($language, $input_encoding) = $plugobj->textcat_get_language_encoding ($filename);
    182     }
     208    }       
    183209
    184210    # Create a directory to store the document files...
     
    205231    # Write the metadata from each record to the metadata.xml file
    206232    my $record_number = 1;
     233    my $documents_directory;
    207234    foreach my $record_text (@metadata_records) {
    208235       
    209236        # Check if we need to start a new directory for these records
    210         my $documents_directory;
    211237        check_need_new_directory($exploded_base_dir,$record_number,$records_per_folder,
    212238                     \@metadata_records,\$documents_directory);
    213        
    214239        # Use the plugin's process function to avoid duplicating code
    215240        my $doc_obj = new doc($filename, "nonindexed_doc");
     
    219244        # Try to get a doc to attach the metadata to
    220245        # If no match found, create a dummy .nul file
    221         attach_metadata_or_nul_doc($document_field, $doc_obj, $record_number,
     246        attach_metadata_or_make_nul_doc($document_field, $doc_obj, $record_number,
    222247                       $documents_directory, $orig_base_dir,
    223248                       $document_prefix, $document_suffix, $metadata_set, $verbosity);
     
    356381        $document_file = "doc.nul";
    357382    }
    358 
    359383    open(DUMMY_FILE, ">$documents_directory/$document_file");
    360384    close(DUMMY_FILE);
Note: See TracChangeset for help on using the changeset viewer.