Changeset 14258


Ignore:
Timestamp:
2007-07-17T14:21:47+12:00 (17 years ago)
Author:
anna
Message:

Fixed bug in using svn annotate command, and bug in comparing dates different formats (svn date format and gti comment format).

File:
1 edited

Legend:

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

    r13948 r14258  
    3939
    4040
    41 my $anonymous_cvs_root = ":pserver:cvs_anon\@cvs.scms.waikato.ac.nz:2402/usr/local/global-cvs/gsdl-src";
     41#my $anonymous_cvs_root = ":pserver:cvs_anon\@cvs.scms.waikato.ac.nz:2402/usr/local/global-cvs/gsdl-src";
     42#my $anonymous_svn_root = "http://http://svn.greenstone.org/gsdl/trunk/";
    4243my $gsdl_root_directory = "$ENV{'GSDLHOME'}";
    4344my $gti_log_file = &util::filename_cat($gsdl_root_directory, "etc", "gti.log");
     
    7980    # 'target_file' => "gsdl-documentation/tutorials/xml-source/tutorial_{target_language_code}.xml" },
    8081
    81       # Greenstone.org
     82      # new Greenstone.org
    8283      { 'key' => "greenorg",
    83     'file_type' => "macrofile",
    84     'source_file' => "greenorg/macros/english.dm",
    85     'target_file' => "greenorg/macros/{iso_639_1_target_language_name}.dm" }
     84        'file_type' => "resource_bundle",
     85        'source_file' => "greenstoneorg/website/classes/Gsc.properties",
     86        'target_file' => "greenstoneorg/website/classes/Gsc_{iso_639_1_target_language_name}.properties"
     87    # 'file_type' => "macrofile",
     88    # 'source_file' => "greenorg/macros/english.dm",
     89    # 'target_file' => "greenorg/macros/{iso_639_1_target_language_name}.dm"
     90      }
    8691    ];
    8792
     
    111116    }
    112117    if ($gti_command =~ /^get-first-n-chunks-requiring-work$/i) {
    113     print &get_first_n_chunks_requiring_work(@gti_command_arguments);
     118    print &get_first_n_chunks_requiring_work(@gti_command_arguments);       
    114119    }
    115120    if ($gti_command =~ /^get-language-status$/i) {
    116     print &get_language_status(@gti_command_arguments);
     121    print &get_language_status(@gti_command_arguments);       
    117122    }
    118123    if ($gti_command =~ /^search-chunks$/i) {
     
    248253    my @source_file_lines = &read_file_lines($source_file_path);
    249254    my %source_file_key_to_line_mapping = &build_key_to_line_mapping(\@source_file_lines, $translation_file_type);
    250 
     255   
    251256    my $target_file_path = &util::filename_cat($gsdl_root_directory, $target_file);
    252257    my @target_file_lines = &read_file_lines($target_file_path);
     
    299304    my $source_file_chunk_date = $source_file_key_to_last_update_date_mapping{$chunk_key};
    300305    my $source_file_chunk_text = &make_text_xml_safe($source_file_key_to_text_mapping{$chunk_key});
    301 
     306   
     307    if(!defined $source_file_chunk_date){
     308        $source_file_chunk_date = "";
     309    }
     310   
    302311    $xml_response .= "    <Chunk key=\"" . &make_text_xml_safe($chunk_key) . "\">\n";
    303     $xml_response .= "      <SourceFileText date=\"$source_file_chunk_date\">$source_file_chunk_text</SourceFileText>\n";
     312    $xml_response .= "      <SourceFileText date=\"$source_file_chunk_date\">$source_file_chunk_text</SourceFileText>\n";   
    304313    $xml_response .= "      <TargetFileText></TargetFileText>\n";
    305314    $xml_response .= "    </Chunk>\n";
     
    325334    my $target_file_chunk_date = $target_file_key_to_last_update_date_mapping{$chunk_key};
    326335    my $target_file_chunk_text = &make_text_xml_safe($target_file_key_to_text_mapping{$chunk_key});
    327 
    328     $xml_response .= "    <Chunk key=\"" . &make_text_xml_safe($chunk_key) . "\">\n";
     336   
     337    if(!defined $source_file_chunk_date){
     338        $source_file_chunk_date = "";
     339    }
     340
     341    $xml_response .= "    <Chunk key=\"" . &make_text_xml_safe($chunk_key) . "\">\n";   
    329342    $xml_response .= "      <SourceFileText date=\"$source_file_chunk_date\">$source_file_chunk_text</SourceFileText>\n";
    330343    $xml_response .= "      <TargetFileText date=\"$target_file_chunk_date\">$target_file_chunk_text</TargetFileText>\n";
     
    636649    # The "2>/dev/null" is very important! If it is missing this will never return when run from the receptionist
    637650    # unless ($translation_file_is_not_in_cvs) {
    638     my $source_file_cvs_status = `cd $gsdl_root_directory; cvs -d $anonymous_cvs_root update $source_file 2>/dev/null`;
     651    #my $source_file_cvs_status = `cd $gsdl_root_directory; cvs -d $anonymous_cvs_root update $source_file 2>/dev/null`;
     652        my $source_file_cvs_status = `cd $gsdl_root_directory; svn status $source_file 2>/dev/null`;
    639653    if ($source_file_cvs_status =~ /^C /) {
    640654        &throw_fatal_error("Source file $source_file_path conflicts with the repository.");
     
    753767    my $chunk_cvs_date = $key_to_cvs_date_mapping{$chunk_key};
    754768    $key_to_last_update_date_mapping{$chunk_key} = $chunk_cvs_date;
    755 
     769               
    756770    # If a comment date exists and it is after the CVS date, use that instead
     771        # need to convert the comment date format to SVN format
    757772    my $chunk_gti_comment = $key_to_gti_comment_mapping{$chunk_key};
    758773    if (defined($chunk_gti_comment) && $chunk_gti_comment =~ /(\d?\d-\D\D\D-\d\d\d\d)/) {
    759         my $chunk_comment_date = $1;
     774        my $chunk_comment_date = $1;           
    760775        if ((!defined($chunk_cvs_date) || &is_date_after($chunk_comment_date, $chunk_cvs_date))) {
    761776        $key_to_last_update_date_mapping{$chunk_key} = $chunk_comment_date;
     
    774789    # Use CVS to annotate each line of the file with the date it was last edited
    775790    # The "2>/dev/null" is very important! If it is missing this will never return when run from the receptionist
    776     my $cvs_annotated_file = `cd $gsdl_root_directory; cvs -d $anonymous_cvs_root annotate -F $filename 2>/dev/null`;
     791    # my $cvs_annotated_file = `cd $gsdl_root_directory; cvs -d $anonymous_cvs_root annotate -F $filename 2>/dev/null`;   
     792    # my $cvs_annotated_file = `cd $gsdl_root_directory; export PATH=.:/research/lh92/programs/subversion/bin; svn annotate -v --force $filename`;
     793    my $cvs_annotated_file = `cd $gsdl_root_directory; svn annotate -v $filename`;
     794   
    777795    my @cvs_annotated_file_lines = split(/\n/, $cvs_annotated_file);
    778796
     
    780798    foreach my $cvs_annotated_file_line (@cvs_annotated_file_lines) {
    781799    # Extract the date from the CVS annotation at the front
    782     $cvs_annotated_file_line =~ s/^\S+\s+\(\S+\s+(\S+)\):\s//;
    783     push(@cvs_annotated_file_lines_date, $1);
    784     }
    785 
     800        # cvs format : 07-Jun-02
     801        # svn format : 2007-07-16
     802    # $cvs_annotated_file_line =~ s/^\S+\s+\(\S+\s+(\S+)\):\s//;
     803        $cvs_annotated_file_line =~ s/^\s+\S+\s+\S+\s(\S+)//;
     804       
     805        push(@cvs_annotated_file_lines_date, $1);
     806       
     807        # trim extra date information in svn annotation format
     808        # 15:42:49 +1200 (Wed, 21 Jun 2006)
     809        $cvs_annotated_file_line =~ s/^\s+\S+\s\S+\s\((.+?)\)\s//;
     810    }   
     811   
    786812    # Build a key to line mapping for the CVS annotated file, for matching the chunk key to the CVS date
    787813    my %key_to_line_mapping = &build_key_to_line_mapping(\@cvs_annotated_file_lines, $translation_file_type);
    788 
     814       
    789815    my %key_to_cvs_date_mapping = ();
    790816    foreach my $chunk_key (keys(%key_to_line_mapping)) {
    791817    my $chunk_starting_line = (split(/-/, $key_to_line_mapping{$chunk_key}))[0];
    792818    my $chunk_finishing_line = (split(/-/, $key_to_line_mapping{$chunk_key}))[1];
    793 
     819               
    794820    # Find the date this chunk was last edited, from the CVS annotation
    795     my $chunk_date = $cvs_annotated_file_lines_date[$chunk_starting_line];
     821    my $chunk_date = $cvs_annotated_file_lines_date[$chunk_starting_line];       
    796822    for (my $l = ($chunk_starting_line + 1); $l <= $chunk_finishing_line; $l++) {
    797823        if (&is_date_after($cvs_annotated_file_lines_date[$l], $chunk_date)) {
    798824        # This part of the chunk has been updated more recently
    799825        $chunk_date = $cvs_annotated_file_lines_date[$l];
     826       
    800827        }
    801828    }
     
    861888    my $source_chunk_last_update_date = $source_file_key_to_last_update_date_mapping->{$chunk_key};
    862889    my $target_chunk_last_update_date = $target_file_key_to_last_update_date_mapping->{$chunk_key};
    863     if (defined($target_chunk_last_update_date) && &is_date_after($source_chunk_last_update_date, $target_chunk_last_update_date)) {
     890       
     891        # print "key: $chunk_key\nsource date : $source_chunk_last_update_date\ntarget date : $target_chunk_last_update_date\nafter? ". &is_date_after($source_chunk_last_update_date, $target_chunk_last_update_date) . "\n\n";       
     892                   
     893        if (defined($target_chunk_last_update_date) && &is_date_after($source_chunk_last_update_date, $target_chunk_last_update_date)) {
    864894        # &log_message("Chunk with key $chunk_key needs updating.");
    865895        push(@target_file_keys_requiring_updating, $chunk_key);
     
    903933
    904934# Returns 1 if $date1 is after $date2, 0 otherwise
    905 sub is_date_after
     935sub is_date_after_cvs
    906936{
    907937    my ($date1, $date2) = @_;
     
    909939          "Jul", 7, "Aug", 8, "Sep", 9, "Oct", 10, "Nov", 11, "Dec", 12);
    910940
     941    if(!defined $date1) {
     942        return 1;
     943    }
     944
    911945    my @date1parts = split(/-/, $date1);
    912946    my @date2parts = split(/-/, $date2);
     
    915949    my $year1 = $date1parts[2];
    916950    if ($year1 < 80) {
    917     $year1 += 2000;
     951        $year1 += 2000;
    918952    }
    919953    my $year2 = $date2parts[2];
    920954    if ($year2 < 80) {
    921     $year2 += 2000;
     955        $year2 += 2000;
    922956    }
    923957
     
    939973    }
    940974
     975    return 0;
     976}
     977
     978sub is_date_after
     979{
     980    my ($date1, $date2) = @_;
     981   
     982    if(!defined $date1) {
     983      return 1;
     984    }
     985    if(!defined $date2) {
     986      return 0;
     987    }
     988   
     989    # 16-Aug-2006
     990    if($date1=~ /(\d+?)-(\S\S\S)-(\d\d\d\d)/){
     991       my %months = ("Jan", "01", "Feb", "02", "Mar", "03", "Apr",  "04", "May",  "05", "Jun",  "06",
     992          "Jul", "07", "Aug", "08", "Sep", "09", "Oct", "10", "Nov", "11", "Dec", "12");
     993       $date1=$3 . "-" . $months{$2} . "-" . $1;
     994       # print "** converted date1: $date1\n";
     995    }
     996    if($date2=~ /(\d+?)-(\S\S\S)-(\d\d\d\d)/){
     997       my %months = ("Jan", "01", "Feb", "02", "Mar", "03", "Apr",  "04", "May",  "05", "Jun",  "06",
     998          "Jul", "07", "Aug", "08", "Sep", "09", "Oct", "10", "Nov", "11", "Dec", "12");
     999       $date2=$3 . "-" . $months{$2} . "-" . $1;
     1000       # print "** converted date2: $date2\n";
     1001    }
     1002   
     1003   
     1004    # 2006-08-16
     1005    my @date1parts = split(/-/, $date1);
     1006    my @date2parts = split(/-/, $date2);
     1007   
     1008    # Compare year
     1009    if ($date1parts[0] > $date2parts[0]) {
     1010    return 1;
     1011    }
     1012    elsif ($date1parts[0] == $date2parts[0]) {
     1013    # Year is the same, so compare month
     1014    if ($date1parts[1] > $date2parts[1]) {
     1015        return 1;
     1016    }
     1017    elsif ($date1parts[1] == $date2parts[1]) {
     1018        # Month is the same, so compare day
     1019        if ($date1parts[2] > $date2parts[2]) {
     1020        return 1;
     1021        }
     1022    }
     1023    }   
     1024   
    9411025    return 0;
    9421026}
Note: See TracChangeset for help on using the changeset viewer.