/[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.10 by joko, Tue May 13 07:56:12 2003 UTC
# Line 2  Line 2 
2  ##  $Id$  ##  $Id$
3  ## ----------------------------------------------------------------------  ## ----------------------------------------------------------------------
4  ##  $Log$  ##  $Log$
5    ##  Revision 1.10  2003/05/13 07:56:12  joko
6    ##  enhanced: *hierarchical* containers for context handling
7    ##  fixes: some pre-flight checks
8    ##  new: propagate "end-tag" event to e.g. close containers
9    ##
10    ##  Revision 1.9  2003/04/04 17:23:11  joko
11    ##  minor update: debugging output
12    ##
13    ##  Revision 1.8  2003/03/29 07:11:54  joko
14    ##  modified: sub run_executable
15    ##  new: sub run_script
16    ##
17  ##  Revision 1.7  2003/03/28 07:02:56  joko  ##  Revision 1.7  2003/03/28 07:02:56  joko
18  ##  modified structure around '$wrapper_program'  ##  modified structure around '$wrapper_program'
19  ##  ##
# Line 41  use Iterate; Line 53  use Iterate;
53    
54  use shortcuts qw( run_cmd );  use shortcuts qw( run_cmd );
55  use Data::Mungle::Code::Ref qw( ref_slot );  use Data::Mungle::Code::Ref qw( ref_slot );
56  use Data::Mungle::Transform::Deep qw( expand );  use Data::Mungle::Transform::Deep qw( expand deep_copy );
57    use File::Temp qw/ tempfile tempdir /;
58    
59    
60  sub performTarget {  sub performTarget {
# Line 54  sub perform_target { Line 67  sub perform_target {
67    my $self = shift;    my $self = shift;
68    my $targetname = shift;    my $targetname = shift;
69    
70      # pre-flight checks
71      if (!$targetname) {
72        $self->log("Target name empty. Please try to specify (e.g.) on the command line.", 'critical');
73        return;
74      }
75    
76    my $header = ("- " x 12) . "   " . $targetname . "   " . ("- " x 6);    my $header = ("- " x 12) . "   " . $targetname . "   " . ("- " x 6);
77        
78      # V1
79    #$self->log("- " x 35, 'notice');    #$self->log("- " x 35, 'notice');
80    #$self->log("Performing Target '$targetname'.", 'notice');    #$self->log("Performing Target '$targetname'.", 'notice');
81    
82    $self->log($header, 'notice');    # V2
83      #$self->log($header, 'notice');
84    
85      # V3
86      $self->log("- " x 20, 'info');
87      $self->log("Performing Target '$targetname'.", 'notice');
88    
89    #exit;    #exit;
90    
# Line 71  sub perform_target { Line 96  sub perform_target {
96            
97    $self->perform_dependencies($target);    $self->perform_dependencies($target);
98    $self->perform_details($target);    $self->perform_details($target);
99      
100      return 1;
101    
102  }  }
103    
# Line 102  sub perform_details { Line 129  sub perform_details {
129    foreach my $entry (@{$target->{content}}) {    foreach my $entry (@{$target->{content}}) {
130      my $command = $entry->{name};      my $command = $entry->{name};
131      my $args = $entry->{attrib};      my $args = $entry->{attrib};
132      $self->perform_command($command, $args);      my $content = $entry->{content};
133        $self->perform_command($command, $args, $content, { warn => 1 } );
134      # check recursiveness      # check recursiveness
135      if ($entry->{content} && ref $entry->{content}) {      # new condition: don't recurse if node is flagged to have inline-args (2004-04-17)
136        my $has_inline_args = ($entry->{attrib}->{_args} && $entry->{attrib}->{_args} eq 'inline');
137        if ($entry->{content} && ref $entry->{content} && !$has_inline_args) {
138        $self->perform_details($entry);        $self->perform_details($entry);
139      }      }
140        # new of 2003-05-08
141        $self->perform_command($command . '_end', undef, undef, { warn => 0 } );
142    }    }
143  }  }
144    
# Line 118  sub rc { Line 150  sub rc {
150  sub perform_command {  sub perform_command {
151    my $self = shift;    my $self = shift;
152    my $command = shift;    my $command = shift;
153      my $args_list = shift;
154      my $content = shift;
155      my $options = shift;
156    
157    if (!$command) {    if (!$command) {
158      $self->log("Command was empty!", 'debug');      $self->log("Command was empty!", 'debug');
# Line 127  sub perform_command { Line 162  sub perform_command {
162    # FIXME: make '__PACKAGE__' go one level deeper properly!    # FIXME: make '__PACKAGE__' go one level deeper properly!
163    $self->log( __PACKAGE__ . "->perform_command: " . $command, 'debug');    $self->log( __PACKAGE__ . "->perform_command: " . $command, 'debug');
164        
165    my $args_list = shift;    
166      # 1. make arguments from list of arguments(?)
167    
168    my $args = {};    my $args = {};
169    #print Dumper($args_list);    #print Dumper($args_list);
170    if ($args_list) {    if ($args_list) {
# Line 139  sub perform_command { Line 176  sub perform_command {
176        $args = $args_list;        $args = $args_list;
177      }      }
178    }    }
   $command = '_' . $command;  
179        
180        
181    # determine container    # 2. prepare command
182      
183      # default setting for internal rap commands
184      my $method_prefix_default = '_';
185      # setting from property database
186      my $method_prefix_setting = $self->get_property('core.method_prefix');
187      #print "setting: ", $method_prefix_setting, "\n";
188      my $prefix = $method_prefix_setting;
189      if (not defined $prefix) {
190        $prefix = $method_prefix_default;
191      }
192      $command = $prefix . $command;
193      
194      
195      # 3. determine container
196    my $container; # = $self->getInstance();    my $container; # = $self->getInstance();
197      #$container ||= $self->getInstance();
198    $container ||= $self;    $container ||= $self;
199        
200      # 4. run method
201    if ($container->can($command)) {    if ($container->can($command)) {
202      $container->$command($args);      $container->$command($args, $content);
203    } else {    } else {
204      $self->log("Command '$command' not implemented.", "warning");      my $level = "debug";
205        $level = "warning" if $options->{warn};
206        $self->log("Command '$command' not implemented.", $level);
207    }    }
208        
209  }  }
# Line 213  sub set_property { Line 267  sub set_property {
267    
268    $self->log("set-name: $name");    $self->log("set-name: $name");
269    
270      #print Dumper($name, $value, '.');
271    
272    # fill property slot with given value    # fill property slot with given value
273    if ($value) {    # fix (2003-04-17): always do fill if value is *defined*!!!
274      if (defined $value) {
275      ref_slot($self, $name, $value, '.');      ref_slot($self, $name, $value, '.');
276    }    }
277        
# Line 300  sub run_executable { Line 357  sub run_executable {
357    my $self = shift;    my $self = shift;
358    my $opts = shift;    my $opts = shift;
359    
360      my $meta = deep_copy($opts);
361    
362      delete $opts->{caption};
363      delete $opts->{async};
364    
365      #print Dumper($meta);
366    
367    if ($opts->{executable}) {    if ($opts->{executable}) {
368    
369      my $program = $opts->{executable};      my $program = $opts->{executable};
# Line 355  sub run_executable { Line 419  sub run_executable {
419        #run_cmd($cmd);        #run_cmd($cmd);
420    
421        # V1.b - enhanced: variable local method        # V1.b - enhanced: variable local method
422        my $evalstr = "run_cmd('$cmd', 'Some task...', { async => 1 });";        $meta->{caption} ||= '';
423          $meta->{async} ||= 0;
424          # new of 2003-05-08: USE_PATH!
425          $meta->{USE_PATH} ||= 0;
426          my $evalstr = "run_cmd('$cmd', '$meta->{caption}', { async => $meta->{async}, USE_PATH => $meta->{USE_PATH} });";
427        eval($evalstr);        eval($evalstr);
428        #my $res = do "$cmd";        #my $res = do "$cmd";
429        #print $res, "\n" if $res;        #print $res, "\n" if $res;
# Line 372  sub run_executable { Line 440  sub run_executable {
440  }  }
441    
442    
443    sub run_script {
444    
445      my $self = shift;
446      my $args = shift;
447      my $code = shift;
448    
449      if ($args->{language} eq 'msdos/bat') {
450        
451        #print "code: $code", "\n";
452        
453        # reporting
454        $self->log("Executing some arbitrary unsigned code (probably unsafe). [language=$args->{language}]", 'info');
455        $self->log("\n<code>\n$code\n</code>", 'info');
456        
457        # create temporary intermediate file to execute code
458        my $tmpdir = '/tmp/rap';
459        mkdir $tmpdir;
460        (my $fh, my $filename) = tempfile( DIR => $tmpdir, SUFFIX => '.bat' );
461        print $fh $code, "\n";
462        run_cmd( $filename, '', { async => 1 } );
463        
464        # FIXME: DELETE code inside temp-files as soon as possible!
465        #print $fh '';
466        
467        # TODO: delete FILE completely!
468        # required for this: wait until execution has finished, then unlink....
469        # but: "how to wait until execution is finished"?
470        # i believe the best is to spawn *another* process directly from here,
471        # let's call it 'watcher-agent'.
472        # This one should monitor a certain running process and delete its
473        # executable file after it has finished execution.
474        # Possible extensions could be:
475        #   keep track of all stuff sent to STDOUT or STDERR and
476        #   send that stuff to the task-owner indirectly (not via shell/console)
477        #   (e.g. via email, by posting report to a newsgroup or publishing on a specified web-page: use mod-dav!)
478        
479      } elsif ($args->{language} eq 'bash') {
480        $self->log("FIXME: - - - - - -- - - --  BASH -  - -    -  - -   -    --   - ", 'error');
481        
482      } else {
483        $self->log("FIXME: Script language '$args->{language}' not implemented.", 'error');
484        
485      }
486    
487    }
488    
489  1;  1;
490  __END__  __END__

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

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