Changeset 30687

Show
Ignore:
Timestamp:
05.08.2016 20:43:47 (3 years ago)
Author:
ak19
Message:

Workaround for Kathy's recent introduction of the colon in the key portion of properties files (where the colon is escaped with a backslash in front). This was not supported, nor was the escaping method recognised, and had broken GTI commits to the GS3 interface.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/bin/script/gti.pl

    r30681 r30687  
    678678    # Check that the translations are valid 
    679679    foreach my $chunk_key (keys(%source_file_key_to_submission_mapping)) { 
     680 
     681    # Kathy introduced escaped colons ("\:") into chunk keys in properties files (greenstone3/metadata_names), 
     682    # but they're not escaped in the submitted XML versions. So have to carefully compare for submissions: 
     683    my $escaped_chunk_key = $chunk_key; 
     684    $escaped_chunk_key =~ s/:/\\:/g; 
     685 
    680686        # Make sure the submitted chunk still exists in the source file 
    681         if (!defined($source_file_key_to_text_mapping{$chunk_key})) { 
     687        if (!defined($source_file_key_to_text_mapping{$escaped_chunk_key})) { 
    682688            &log_message("Warning: Source chunk $chunk_key no longer exists (ignoring submission)."); 
    683689            delete $source_file_key_to_submission_mapping{$chunk_key}; 
     
    687693         
    688694        # Make sure the submitted source chunk matches the source file chunk 
    689         if ($source_file_key_to_submission_mapping{$chunk_key} ne &unmake_text_xml_safe($source_file_key_to_text_mapping{$chunk_key})) { 
     695        if ($source_file_key_to_submission_mapping{$chunk_key} ne &unmake_text_xml_safe($source_file_key_to_text_mapping{$escaped_chunk_key})) { 
    690696        #if (&unmake_text_xml_safe($source_file_key_to_submission_mapping{$chunk_key}) ne &unmake_text_xml_safe($source_file_key_to_text_mapping{$chunk_key})) { 
    691697                    #print STDERR "**** $source_file_key_to_submission_mapping{$chunk_key}\n"; 
    692698                #print STDERR "**** " . &unmake_text_xml_safe($source_file_key_to_text_mapping{$chunk_key}) ."\n"; 
    693699 
    694             &log_message("Warning: Source chunk $chunk_key has changed (ignoring submission)."); 
    695             &log_message("Submission source: $source_file_key_to_submission_mapping{$chunk_key}"); 
    696             &log_message("      Source text: $source_file_key_to_text_mapping{$chunk_key}"); 
     700            &log_message("Warning: Source chunk $escaped_chunk_key has changed (ignoring submission)."); 
     701            &log_message("Submission source: |$source_file_key_to_submission_mapping{$chunk_key}|"); 
     702            &log_message("      Source text: |$source_file_key_to_text_mapping{$escaped_chunk_key}|"); 
    697703            delete $source_file_key_to_submission_mapping{$chunk_key}; 
    698704            delete $target_file_key_to_submission_mapping{$chunk_key}; 
     
    704710    foreach my $chunk_key (keys(%target_file_key_to_submission_mapping)) { 
    705711        # Only apply the submission if it is a change, unless -force_submission has been specified 
    706         if ($force_submission_flag || !defined($target_file_key_to_text_mapping{$chunk_key}) || $target_file_key_to_submission_mapping{$chunk_key} ne $target_file_key_to_text_mapping{$chunk_key}) { 
    707             $target_file_key_to_text_mapping{$chunk_key} = $target_file_key_to_submission_mapping{$chunk_key}; 
    708             $target_file_key_to_gti_comment_mapping{$chunk_key} = "Updated $submission_date by $submitter_username"; 
     712    my $escaped_chunk_key = $chunk_key; 
     713    $escaped_chunk_key =~ s/:/\\:/g; 
     714        if ($force_submission_flag || !defined($target_file_key_to_text_mapping{$escaped_chunk_key}) || $target_file_key_to_submission_mapping{$chunk_key} ne $target_file_key_to_text_mapping{$escaped_chunk_key}) { 
     715            $target_file_key_to_text_mapping{$escaped_chunk_key} = $target_file_key_to_submission_mapping{$chunk_key}; 
     716            $target_file_key_to_gti_comment_mapping{$escaped_chunk_key} = "Updated $submission_date by $submitter_username"; 
    709717        } 
    710718    } 
     
    917925{ 
    918926    my ($file_lines, $key_to_line_mapping, $translation_file_type) = @_; 
    919  
    920         &log_message("@@@ HELLO WORLD"); 
    921  
    922927     
    923928    my %key_to_text_mapping = (); 
     
    16161621        $line =~ s/(\s*)$//;  # Remove any nasty whitespace, carriage returns etc. 
    16171622         
     1623        $line =~ s/\\:/ESCAPEDCOLONTEMP/g; # an escaped colon "\:" should only occur in the chunk_key portion of the line 
     1624 
    16181625        # Line contains a dictionary string 
    1619         if ($line =~ /^(\S+)[:|=](.*)$/) { 
     1626        if ($line =~ /^(\S+?)[:|=](.*)$/) { 
    16201627            $chunk_key = $1; 
     1628 
     1629            # an escaped colon "\:" should only occur in the chunk_key portion of the line, put it back in, escaped as before 
     1630            if($chunk_key =~ m/ESCAPEDCOLONTEMP/) { 
     1631            $chunk_key =~ s/ESCAPEDCOLONTEMP/\\:/g; 
     1632            } 
     1633             
    16211634            $startindex = $i; 
    16221635        }        
     
    16301643            $chunk_key = ""; 
    16311644            } 
    1632         }                
     1645        }        
    16331646    } 
    16341647     
     
    16411654    my ($chunk_text) = @_; 
    16421655     
    1643     # Simple: just remove string key 
    1644     $chunk_text =~ s/^(\S+)[:|=](\s*)//s; 
     1656    $chunk_text =~ s/\\:/ESCAPEDCOLONTEMP/g; # an escaped colon "\:" should only occur in the chunk_key portion of the line 
     1657 
     1658    # Simple: just remove string key     
     1659    $chunk_text =~ s/^(\S+?)[:|=](\s*)//s; 
    16451660    $chunk_text =~ s/(\s*)$//s;  # Remove any nasty whitespace, carriage returns etc. 
    16461661    $chunk_text =~ s/(\s*)\#\s+Updated\s+(\d?\d-\D\D\D-\d\d\d\d.*)\s*$//is;