X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=Takfile;h=618f348e4d5677f10f7f8256f5c4b547024934ad;hb=ad0ce551a06a7d61065e4a6ccbc4908ac0e298e1;hp=62b8135a23802729539195f07476ccaec141e713;hpb=241e3dd6574abfe291f56471c1a448b0ebbb3b69;p=scpubgit%2FTak.git diff --git a/Takfile b/Takfile index 62b8135..618f348 100644 --- a/Takfile +++ b/Takfile @@ -1,57 +1,15 @@ package Tak::MyScript; use Tak::Takfile; +use Tak::ObjectClient; -sub every_exec (stream|s) { - my ($self, $remotes, $options, @command) = @_; - - my @requests; - - $_->ensure(command_service => 'Tak::CommandService') for @$remotes; - - foreach my $remote (@$remotes) { - if ($options->{stream}) { - my $stdout = $self->stdout; - my $host = $remote->host; - push @requests, $remote->start( - { - on_result => sub { $self->print_exec_result($remote, @_) }, - on_progress => sub { - $stdout->print($host.' '.$_[0].': '.$_[1]); - $stdout->print("\n") unless $_[1] =~ /\n\Z/; - } - }, - command_service => stream_exec => \@command - ); - } else { - push @requests, $remote->start( - { on_result => sub { $self->print_exec_result($remote, @_) } }, - command_service => exec => \@command - ); - } - } - Tak->await_all(@requests); -} - -sub print_exec_result { - my ($self, $remote, $result) = @_; - - my $res = eval { $result->get } - or do { - $self->stderr->print("Host ${\$remote->host}: Error: $@\n"); - return; - }; - - my $code = $res->{exit_code}; +sub each_get_homedir { + my ($self, $remote) = @_; + my $oc = Tak::ObjectClient->new(remote => $remote); + my $home = $oc->new_object('Path::Class::Dir')->absolute->stringify; $self->stdout->print( - "Host ${\$remote->host}: ".($code ? "NOT OK ${code}" : "OK")."\n" + $remote->host.': '.$home."\n" ); - if ($res->{stderr}) { - $self->stdout->print("Stderr:\n${\$res->{stderr}}\n"); - } - if ($res->{stdout}) { - $self->stdout->print("Stdout:\n${\$res->{stdout}}\n"); - } } 1;