Changeset 1115


Ignore:
Timestamp:
03/20/10 16:49:35 (2 years ago)
Author:
victorsb
Message:

Wrote a script to add a \n to all grader test files that
currently don't end with one and modified the attachment
code to auto-check for \n at upload time.

REVIEW URL http://reviewboard.infoarena.ro/r/139/

Location:
trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/common/attachment.php

    r1018 r1115  
    118118} 
    119119 
     120function is_grader_testfile($file_name) { 
     121    $pattern = '/^grader_test(\d)*\.(ok|in)$/'; 
     122    if (preg_match($pattern, $file_name) == false) { 
     123        return false; 
     124    } else { 
     125        return true; 
     126    } 
     127} 
     128 
     129function is_problem_page($page_name) { 
     130    $pattern = '/^problema\/' . IA_RE_TASK_ID . '$/'; 
     131    if (preg_match($pattern, $page_name) == false) { 
     132        return false; 
     133    } else { 
     134        return true; 
     135    } 
     136} 
     137 
     138function add_ending_newline($file_path) { 
     139    $content = file_get_contents($file_path); 
     140    if ($content[strlen($content) - 1] != "\n") { 
     141        $content .= "\n"; 
     142        file_put_contents($file_path, $content); 
     143        return true; 
     144    } 
     145    return false; 
     146} 
     147 
    120148?> 
  • trunk/www/controllers/attachment.php

    r1086 r1115  
    175175            if (is_textfile($file_att['type'])) { 
    176176                dos_to_unix($file_att['disk_name']); 
     177                if (is_grader_testfile($file_att['name']) && 
     178                    is_problem_page($page_name)) { 
     179                    add_ending_newline($file_att['disk_name']); 
     180                } 
    177181                $file_att['size'] = filesize($file_att['disk_name']); 
    178182            } 
Note: See TracChangeset for help on using the changeset viewer.