/[cvs]/nfo/perl/libs/Data/Rap/Engine.pm
ViewVC logotype

Diff of /nfo/perl/libs/Data/Rap/Engine.pm

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

revision 1.7 by joko, Fri Mar 28 07:02:56 2003 UTC revision 1.8 by joko, Sat Mar 29 07:11:54 2003 UTC
# Line 2  Line 2 
2  ##  $Id$  ##  $Id$
3  ## ----------------------------------------------------------------------  ## ----------------------------------------------------------------------
4  ##  $Log$  ##  $Log$
5    ##  Revision 1.8  2003/03/29 07:11:54  joko
6    ##  modified: sub run_executable
7    ##  new: sub run_script
8    ##
9  ##  Revision 1.7  2003/03/28 07:02:56  joko  ##  Revision 1.7  2003/03/28 07:02:56  joko
10  ##  modified structure around '$wrapper_program'  ##  modified structure around '$wrapper_program'
11  ##  ##
# Line 41  use Iterate; Line 45  use Iterate;
45    
46  use shortcuts qw( run_cmd );  use shortcuts qw( run_cmd );
47  use Data::Mungle::Code::Ref qw( ref_slot );  use Data::Mungle::Code::Ref qw( ref_slot );
48  use Data::Mungle::Transform::Deep qw( expand );  use Data::Mungle::Transform::Deep qw( expand deep_copy );
49    use File::Temp qw/ tempfile tempdir /;
50    
51    
52  sub performTarget {  sub performTarget {
# Line 56  sub perform_target { Line 61  sub perform_target {
61    
62    my $header = ("- " x 12) . "   " . $targetname . "   " . ("- " x 6);    my $header = ("- " x 12) . "   " . $targetname . "   " . ("- " x 6);
63        
64      # V1
65    #$self->log("- " x 35, 'notice');    #$self->log("- " x 35, 'notice');
66    #$self->log("Performing Target '$targetname'.", 'notice');    #$self->log("Performing Target '$targetname'.", 'notice');
67    
68    $self->log($header, 'notice');    # V2
69      #$self->log($header, 'notice');
70    
71      # V3
72      $self->log("- " x 35, 'info');
73      $self->log("Performing Target '$targetname'.", 'notice');
74    
75    #exit;    #exit;
76    
# Line 102  sub perform_details { Line 113  sub perform_details {
113    foreach my $entry (@{$target->{content}}) {    foreach my $entry (@{$target->{content}}) {
114      my $command = $entry->{name};      my $command = $entry->{name};
115      my $args = $entry->{attrib};      my $args = $entry->{attrib};
116      $self->perform_command($command, $args);      my $content = $entry->{content};
117        $self->perform_command($command, $args, $content);
118      # check recursiveness      # check recursiveness
119      if ($entry->{content} && ref $entry->{content}) {      if ($entry->{content} && ref $entry->{content}) {
120        $self->perform_details($entry);        $self->perform_details($entry);
# Line 118  sub rc { Line 130  sub rc {
130  sub perform_command {  sub perform_command {
131    my $self = shift;    my $self = shift;
132    my $command = shift;    my $command = shift;
133      my $args_list = shift;
134      my $content = shift;
135    
136    if (!$command) {    if (!$command) {
137      $self->log("Command was empty!", 'debug');      $self->log("Command was empty!", 'debug');
# Line 127  sub perform_command { Line 141  sub perform_command {
141    # FIXME: make '__PACKAGE__' go one level deeper properly!    # FIXME: make '__PACKAGE__' go one level deeper properly!
142    $self->log( __PACKAGE__ . "->perform_command: " . $command, 'debug');    $self->log( __PACKAGE__ . "->perform_command: " . $command, 'debug');
143        
   my $args_list = shift;  
144    my $args = {};    my $args = {};
145    #print Dumper($args_list);    #print Dumper($args_list);
146    if ($args_list) {    if ($args_list) {
# Line 147  sub perform_command { Line 160  sub perform_command {
160    $container ||= $self;    $container ||= $self;
161        
162    if ($container->can($command)) {    if ($container->can($command)) {
163      $container->$command($args);      $container->$command($args, $content);
164    } else {    } else {
165      $self->log("Command '$command' not implemented.", "warning");      $self->log("Command '$command' not implemented.", "warning");
166    }    }
# Line 300  sub run_executable { Line 313  sub run_executable {
313    my $self = shift;    my $self = shift;
314    my $opts = shift;    my $opts = shift;
315    
316      my $meta = deep_copy($opts);
317    
318      delete $opts->{caption};
319      delete $opts->{async};
320    
321      #print Dumper($meta);
322    
323    if ($opts->{executable}) {    if ($opts->{executable}) {
324    
325      my $program = $opts->{executable};      my $program = $opts->{executable};
# Line 355  sub run_executable { Line 375  sub run_executable {
375        #run_cmd($cmd);        #run_cmd($cmd);
376    
377        # V1.b - enhanced: variable local method        # V1.b - enhanced: variable local method
378        my $evalstr = "run_cmd('$cmd', 'Some task...', { async => 1 });";        $meta->{caption} ||= '';
379          $meta->{async} ||= 0;
380          my $evalstr = "run_cmd('$cmd', '$meta->{caption}', { async => $meta->{async} });";
381        eval($evalstr);        eval($evalstr);
382        #my $res = do "$cmd";        #my $res = do "$cmd";
383        #print $res, "\n" if $res;        #print $res, "\n" if $res;
# Line 372  sub run_executable { Line 394  sub run_executable {
394  }  }
395    
396    
397    sub run_script {
398    
399      my $self = shift;
400      my $args = shift;
401      my $code = shift;
402    
403      if ($args->{language} eq 'msdos/bat') {
404        
405        #print "code: $code", "\n";
406        
407        # reporting
408        $self->log("Executing some arbitrary unsigned code (probably unsafe). [language=$args->{language}]", 'info');
409        $self->log("\n<code>\n$code\n</code>", 'info');
410        
411        # create temporary intermediate file to execute code
412        my $tmpdir = '/tmp/rap';
413        mkdir $tmpdir;
414        (my $fh, my $filename) = tempfile( DIR => $tmpdir, SUFFIX => '.bat' );
415        print $fh $code, "\n";
416        run_cmd( $filename, '', { async => 1 } );
417        
418        # FIXME: DELETE code inside temp-files as soon as possible!
419        #print $fh '';
420        
421        # TODO: delete FILE completely!
422        # required for this: wait until execution has finished, then unlink....
423        # but: "how to wait until execution is finished"?
424        # i believe the best is to spawn *another* process directly from here,
425        # let's call it 'watcher-agent'.
426        # This one should monitor a certain running process and delete its
427        # executable file after it has finished execution.
428        # Possible extensions could be:
429        #   keep track of all stuff sent to STDOUT or STDERR and
430        #   send that stuff to the task-owner indirectly (not via shell/console)
431        #   (e.g. via email, by posting report to a newsgroup or publishing on a specified web-page: use mod-dav!)
432        
433      } elsif ($args->{language} eq 'bash') {
434        $self->log("FIXME: - - - - - -- - - --  BASH -  - -    -  - -   -    --   - ", 'error');
435        
436      } else {
437        $self->log("FIXME: Script language '$args->{language}' not implemented.", 'error');
438        
439      }
440    
441    }
442    
443  1;  1;
444  __END__  __END__

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

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed