[Bio] / FigKernelPackages / ServerThing.pm Repository:
ViewVC logotype

Diff of /FigKernelPackages/ServerThing.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7, Wed Sep 9 15:20:54 2009 UTC revision 1.8, Wed Sep 30 15:34:28 2009 UTC
# Line 7  Line 7 
7      use YAML;      use YAML;
8      use ERDB;      use ERDB;
9      use TestUtils;      use TestUtils;
     use DocUtils;  
10      use Time::HiRes;      use Time::HiRes;
11      use ErrorDocument;      use ErrorDocument;
12      use CGI;      use CGI;
# Line 109  Line 108 
108          # Protect from errors.          # Protect from errors.
109          eval {          eval {
110              # We'll format the HTML text in here.              # We'll format the HTML text in here.
111                require DocUtils;
112              my $html = DocUtils::ShowPod($module, $docURL);              my $html = DocUtils::ShowPod($module, $docURL);
113              # Output the POD HTML.              # Output the POD HTML.
114              print $html;              print $html;
# Line 233  Line 233 
233  }  }
234    
235    
236    =head3 RunTool
237    
238        ServerThing::RunTool($name => $cmd);
239    
240    Run a command-line tool. A non-zero return value from the tool will cause
241    a fatal error, and the tool's error log will be traced.
242    
243    =over 4
244    
245    =item name
246    
247    Name to give to the tool in the error output.
248    
249    =item cmd
250    
251    Command to use for running the tool. This should be the complete command line.
252    The command should not contain any fancy piping, though it may redirect the
253    standard input and output. The command will be modified by this method to
254    redirect the error output to a temporary file.
255    
256    =back
257    
258    =cut
259    
260    sub RunTool {
261        # Get the parameters.
262        my ($name, $cmd) = @_;
263        # Compute the log file name.
264        my $errorLog = "$FIG_Config::temp/errors$$.log";
265        # Execute the command.
266        Trace("Executing command: $cmd") if T(3);
267        my $res = system("$cmd 2> $errorLog");
268        Trace("Return from $name tool is $res.") if T(3);
269        # Check the result code.
270        if ($res != 0) {
271            # We have an error. If tracing is on, trace it.
272            if (T(1)) {
273                TraceErrorLog($name, $errorLog);
274            }
275            # Delete the error log.
276            unlink $errorLog;
277            # Confess the error.
278            Confess("500 $name command failed with error code $res.");
279        } else {
280            # Everything worked. Trace the error log if necessary.
281            if (T(3) && -s $errorLog) {
282                TraceErrorLog($name, $errorLog);
283            }
284            # Delete the error log if there is one.
285            unlink $errorLog;
286        }
287    }
288    
289    =head3 TraceErrorLog
290    
291        ServerThing::TraceErrorLog($name, $errorLog);
292    
293    Trace the specified error log file. This is a very dinky routine that
294    performs a task required by L</RunTool> in multiple places.
295    
296    =over 4
297    
298    =item name
299    
300    Name of the tool relevant to the log file.
301    
302    =item errorLog
303    
304    Name of the log file.
305    
306    =back
307    
308    =cut
309    
310    sub TraceErrorLog {
311        my ($name, $errorLog) = @_;
312        my $errorData = Tracer::GetFile($errorLog);
313        Trace("$name error log:\n$errorData");
314    }
315    
316    
317  1;  1;

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3