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