From 16acb2754c6a5cd8cd7d82b9d3f7a32042f7ef09 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 25 Feb 2009 10:52:41 +0000 Subject: [PATCH] * Put actions related to builds under /build (e.g. /log/ becomes /build//log). --- src/Hydra/lib/Hydra/Controller/Root.pm | 105 +++++++++++++------------ src/Hydra/root/build.tt | 7 +- src/Hydra/root/error.tt | 2 +- src/Hydra/root/product-list.tt | 19 +++-- 4 files changed, 70 insertions(+), 63 deletions(-) diff --git a/src/Hydra/lib/Hydra/Controller/Root.pm b/src/Hydra/lib/Hydra/Controller/Root.pm index cf54bcae..15269e6d 100644 --- a/src/Hydra/lib/Hydra/Controller/Root.pm +++ b/src/Hydra/lib/Hydra/Controller/Root.pm @@ -5,10 +5,8 @@ use warnings; use parent 'Catalyst::Controller'; use Hydra::Helper::Nix; -# -# Sets the actions in this controller to be registered with no prefix -# so they function identically to actions created in MyApp.pm -# + +# Put this controller at top-level. __PACKAGE__->config->{namespace} = ''; @@ -26,9 +24,8 @@ sub begin :Private { sub error { my ($c, $msg) = @_; - $c->stash->{template} = 'error.tt'; - $c->stash->{error} = $msg; - $c->response->status(404); + $c->error($msg); + $c->detach; } @@ -572,23 +569,34 @@ sub job :Local { sub default :Path { my ($self, $c) = @_; error($c, "Page not found."); + $c->response->status(404); } -sub build :Local { +sub build : Chained('/') PathPart CaptureArgs(1) { my ($self, $c, $id) = @_; - - my $build = getBuild($c, $id); - return error($c, "Build with ID $id doesn't exist.") if !defined $build; - - $c->stash->{curProject} = $build->project; - - $c->stash->{template} = 'build.tt'; - $c->stash->{build} = $build; + $c->stash->{id} = $id; + + $c->stash->{build} = getBuild($c, $id); + + if (!defined $c->stash->{build}) { + error($c, "Build with ID $id doesn't exist."); + $c->response->status(404); + return; + } + $c->stash->{curProject} = $c->stash->{build}->project; +} + + +sub view_build : Chained('build') PathPart('') Args(0) { + my ($self, $c) = @_; + + my $build = $c->stash->{build}; + + $c->stash->{template} = 'build.tt'; $c->stash->{curTime} = time; - $c->stash->{available} = isValidPath $build->outpath; if (!$build->finished && $build->schedulingInfo->busy) { @@ -598,35 +606,13 @@ sub build :Local { } -sub log :Local { - my ($self, $c, $id) = @_; +sub view_nixlog : Chained('build') PathPart('nixlog') Args(1) { + my ($self, $c, $stepnr) = @_; - my $build = getBuild($c, $id); - return error($c, "Build $id doesn't exist.") if !defined $build; - - return error($c, "Build $id didn't produce a log.") if !defined $build->resultInfo->logfile; + my $step = $c->stash->{build}->buildsteps->find({stepnr => $stepnr}); + return error($c, "Build doesn't have a build step $stepnr.") if !defined $step; $c->stash->{template} = 'log.tt'; - $c->stash->{build} = $build; - - # !!! should be done in the view (as a TT plugin). - $c->stash->{logtext} = loadLog($c, $build->resultInfo->logfile); -} - - -sub nixlog :Local { - my ($self, $c, $id, $stepnr) = @_; - - my $build = getBuild($c, $id); - return error($c, "Build with ID $id doesn't exist.") if !defined $build; - - my $step = $build->buildsteps->find({stepnr => $stepnr}); - return error($c, "Build $id doesn't have a build step $stepnr.") if !defined $step; - - return error($c, "Build step $stepnr of build $id does not have a log file.") if $step->logfile eq ""; - - $c->stash->{template} = 'log.tt'; - $c->stash->{build} = $build; $c->stash->{step} = $step; # !!! should be done in the view (as a TT plugin). @@ -634,6 +620,18 @@ sub nixlog :Local { } +sub view_log : Chained('build') PathPart('log') Args(0) { + my ($self, $c) = @_; + + return error($c, "Build didn't produce a log.") if !defined $c->stash->{build}->resultInfo->logfile; + + $c->stash->{template} = 'log.tt'; + + # !!! should be done in the view (as a TT plugin). + $c->stash->{logtext} = loadLog($c, $c->stash->{build}->resultInfo->logfile); +} + + sub loadLog { my ($c, $path) = @_; @@ -648,14 +646,11 @@ sub loadLog { } -sub download :Local { - my ($self, $c, $id, $productnr, $filename, @path) = @_; +sub download : Chained('build') PathPart('download') { + my ($self, $c, $productnr, $filename, @path) = @_; - my $build = getBuild($c, $id); - return error($c, "Build with ID $id doesn't exist.") if !defined $build; - - my $product = $build->buildproducts->find({productnr => $productnr}); - return error($c, "Build $id doesn't have a product $productnr.") if !defined $product; + my $product = $c->stash->{build}->buildproducts->find({productnr => $productnr}); + return error($c, "Build doesn't have a product $productnr.") if !defined $product; return error($c, "Product " . $product->path . " has disappeared.") unless -e $product->path; @@ -748,7 +743,15 @@ sub nar :Local { } -sub end : ActionClass('RenderView') {} +sub end : ActionClass('RenderView') { + my ($self, $c) = @_; + + if (scalar @{$c->error}) { + $c->stash->{template} = 'error.tt'; + $c->stash->{errors} = $c->error; + $c->clear_errors; + } +} 1; diff --git a/src/Hydra/root/build.tt b/src/Hydra/root/build.tt index 49b6c043..ad98f2bb 100644 --- a/src/Hydra/root/build.tt +++ b/src/Hydra/root/build.tt @@ -121,7 +121,7 @@ Logfile: - Available + Available [% END %] @@ -178,8 +178,9 @@ [% FOREACH step IN build.buildsteps -%] + [% log = c.uri_for('build' build.id 'nixlog' step.stepnr) %] + [% IF step.logfile %] onclick="window.location = '[% log %]'" [% END %]> [% step.stepnr %] [% IF step.type == 0 %] @@ -212,7 +213,7 @@ Failed: [% HTML.escape(step.errormsg) %] [% END %] [% IF step.logfile %] - (log) + (log) [% END %] diff --git a/src/Hydra/root/error.tt b/src/Hydra/root/error.tt index 63b858f7..12d51798 100644 --- a/src/Hydra/root/error.tt +++ b/src/Hydra/root/error.tt @@ -3,6 +3,6 @@

Error

-

I'm very sorry, but an error occurred: [% HTML.escape(error) %]

+

I'm very sorry, but an error occurred: [% FOREACH error IN errors %] [% HTML.escape(error) %] [% END %]

[% END %] diff --git a/src/Hydra/root/product-list.tt b/src/Hydra/root/product-list.tt index 04bd8591..2a7ff3a1 100644 --- a/src/Hydra/root/product-list.tt +++ b/src/Hydra/root/product-list.tt @@ -5,13 +5,16 @@