Changeset 15167
- Timestamp:
- 2008-04-02T18:15:29+13:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gsdl/trunk/perllib/plugins/TEXTPlug.pm
r15150 r15167 150 150 = &File::Basename::fileparse($input_filename, "\\.[^\\.]+\$"); 151 151 152 # softlink to collection tmp dir 152 # Softlink to collection tmp dir 153 # First find a temporary directory to create the output file in 153 154 my $tmp_dirname = $dirname; 154 155 if(defined $ENV{'GSDLCOLLECTDIR'}) { … … 160 161 &util::mk_dir($tmp_dirname) if (!-e $tmp_dirname); 161 162 162 163 163 # convert to utf-8 otherwise we have problems with the doc.xml file 164 164 # later on 165 165 &unicode::ensure_utf8(\$tailname); # TODO: does this change the filename or not? 166 166 # need to test this out on a windows computer using a Greek filename 167 167 $suffix = lc($suffix); 168 168 my $tmp_filename = &util::filename_cat($tmp_dirname, "$tailname$suffix"); 169 &util::soft_link($input_filename, $tmp_filename); 170 # softlink symbolic link to or copy of original, so we don't accidentally damage it 171 172 #my $output_filename = $tailname$output_ext;#output_ext has to be html! 169 170 # Make sure we have the absolute path to the input file 171 # (If gsdl is remote, we're given relative path to input file, of the form import/tailname.suffix 172 # But we can't softlink to relative paths. Therefore, we need to ensure that 173 # the input_filename is the absolute path. 174 my $ensure_path_absolute = 1; # true 175 176 # Now make the softlink, so we don't accidentally damage the input file 177 # softlinking creates a symbolic link to (or, if that's not possible, it makes a copy of) the original 178 &util::soft_link($input_filename, $tmp_filename, $ensure_path_absolute); 179 180 my $verbosity = $self->{'verbosity'}; 181 if ($verbosity > 0) { 182 # need this output statement, as GShell.java's runRemote() sets status to CANCELLED 183 # if there is no output! (Therefore, it only had this adverse affect when running GSDL remotely) 184 print $outhandle "Converting $tailname$suffix to html\n"; 185 } 186 187 #my $output_filename = $tailname$output_ext; #output_ext has to be html! 173 188 my $output_filename = &util::filename_cat($tmp_dirname, $tailname.".html"); 174 189 175 # read contents of text file line by line into an array190 # Read contents of text file line by line into an array 176 191 # create an HTML file from the text file 177 192 # Recreate the original file for writing the updated contents 178 193 unless(open(TEXT, "<$tmp_filename")) { # open it as a new file for writing 179 print STDERR "TEXTPlug.pm: Unable to open and read from $ input_filename for converting to html...ERROR\n";194 print STDERR "TEXTPlug.pm: Unable to open and read from $tmp_filename for converting to html...ERROR: $!\n"; 180 195 return ""; # no file name 181 196 } 182 197 198 # Read the entire file at once 183 199 my $text; 184 200 { 185 local $/ = undef; # Read entire file at once. This is from http://perl.plover.com/local.html186 $text = <TEXT>; # Now file is read in as one single 'line'201 local $/ = undef; # Now can read the entire file at once. From http://perl.plover.com/local.html 202 $text = <TEXT>; # File is read in as one single 'line' 187 203 } 188 204 close(TEXT); # close the file … … 196 212 # try creating this new file writing and try opening it for writing, else exit with error value 197 213 unless(open(HTML, ">$output_filename")) { # open the new html file for writing 198 print STDERR "TEXTPlug.pm: Unable to create $output_filename for writing $tailname$suffix txt converted to html...ERROR \n";214 print STDERR "TEXTPlug.pm: Unable to create $output_filename for writing $tailname$suffix txt converted to html...ERROR: $!\n"; 199 215 return ""; # no filename 200 216 }
Note:
See TracChangeset
for help on using the changeset viewer.