From cf37152849b497fee9f032bef9bcf623f67a480f Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 25 Feb 2009 16:29:54 +0000 Subject: [PATCH] --- src/Hydra/lib/Hydra/Controller/Build.pm | 2 +- src/Hydra/lib/Hydra/Controller/Root.pm | 39 ++++++++++++++++++++----- src/Hydra/lib/Hydra/View/NixManifest.pm | 16 +++------- src/Hydra/root/error.tt | 2 +- 4 files changed, 38 insertions(+), 21 deletions(-) diff --git a/src/Hydra/lib/Hydra/Controller/Build.pm b/src/Hydra/lib/Hydra/Controller/Build.pm index 2cdb9773..0f6dc06f 100644 --- a/src/Hydra/lib/Hydra/Controller/Build.pm +++ b/src/Hydra/lib/Hydra/Controller/Build.pm @@ -122,8 +122,8 @@ sub nix : Chained('build') PathPart('nix') CaptureArgs(0) { error($c, "Path " . $build->outpath . " is no longer available.") unless isValidPath($build->outpath); - $c->stash->{name} = $build->nixname; $c->stash->{storePaths} = [$build->outpath]; + my $pkgName = $build->nixname . "-" . $build->system . ".nixpkg"; $c->stash->{nixPkgs} = {$pkgName => $build}; } diff --git a/src/Hydra/lib/Hydra/Controller/Root.pm b/src/Hydra/lib/Hydra/Controller/Root.pm index 5f6c46ac..8314bfd3 100644 --- a/src/Hydra/lib/Hydra/Controller/Root.pm +++ b/src/Hydra/lib/Hydra/Controller/Root.pm @@ -2,7 +2,7 @@ package Hydra::Controller::Root; use strict; use warnings; -use base 'Catalyst::Controller'; +use base 'Hydra::Base::Controller::Nix'; use Hydra::Helper::Nix; use Hydra::Helper::CatalystUtils; @@ -97,12 +97,10 @@ sub queue :Local { } -sub showJobStatus { +# Return the latest build for each job. +sub getLatestBuilds { my ($c, $builds) = @_; - $c->stash->{template} = 'jobstatus.tt'; - - # Get the latest finished build for each unique job. - $c->stash->{latestBuilds} = [$builds->search({}, + return $builds->search({}, { join => 'resultInfo' , where => { finished => { "!=", 0 }, @@ -111,7 +109,16 @@ sub showJobStatus { "where project == me.project and attrName == me.attrName and finished != 0 and system == me.system)"), } , order_by => "project, attrname, system" - })]; + }); +} + + +sub showJobStatus { + my ($c, $builds) = @_; + $c->stash->{template} = 'jobstatus.tt'; + + # Get the latest finished build for each unique job. + $c->stash->{latestBuilds} = [getLatestBuilds($c, $builds)]; } @@ -538,6 +545,20 @@ sub job :Local { } +sub nix : Chained('/') PathPart('nix') CaptureArgs(0) { + my ($self, $c) = @_; + + my @builds = getLatestBuilds($c, $c->model('DB::Builds')); + + my @storePaths = (); + foreach my $build (@builds) { + push @storePaths, $build->outpath if isValidPath($build->outpath); + }; + + $c->stash->{storePaths} = [@storePaths]; +} + + sub default :Path { my ($self, $c) = @_; notFound($c, "Page not found."); @@ -550,6 +571,10 @@ sub end : ActionClass('RenderView') { if (scalar @{$c->error}) { $c->stash->{template} = 'error.tt'; $c->stash->{errors} = $c->error; + if ($c->response->status >= 300) { + $c->stash->{httpStatus} = + $c->response->status . " " . HTTP::Status::status_message($c->response->status); + } $c->clear_errors; } } diff --git a/src/Hydra/lib/Hydra/View/NixManifest.pm b/src/Hydra/lib/Hydra/View/NixManifest.pm index 54ce673f..853decfb 100644 --- a/src/Hydra/lib/Hydra/View/NixManifest.pm +++ b/src/Hydra/lib/Hydra/View/NixManifest.pm @@ -3,15 +3,8 @@ package Hydra::View::NixManifest; use strict; use base qw/Catalyst::View/; use IO::Pipe; -use IPC::Run; use POSIX qw(dup2); -sub captureStdoutStderr { - my $stdin = ""; my $stdout; my $stderr; - my $res = IPC::Run::run(\@_, \$stdin, \$stdout, \$stderr); - return ($res, $stdout, $stderr); -} - sub process { my ($self, $c) = @_; @@ -20,8 +13,8 @@ sub process { $c->response->content_type('text/x-nix-manifest'); - my @paths = split '\n', `nix-store --query --requisites @storePaths` - or die "cannot query dependencies of path(s) @storePaths: $?"; + my @paths = split '\n', `nix-store --query --requisites @storePaths`; + die "cannot query dependencies of path(s) @storePaths: $?" if $? != 0; my $manifest = "version {\n" . @@ -29,9 +22,8 @@ sub process { "}\n"; foreach my $path (@paths) { - my ($res, $out, $err) = captureStdoutStderr(qw(nix-store --query --references), $path); - die "cannot query references of `$path':\n$err" unless $res; - my @refs = split '\n', $out; + my @refs = split '\n', `nix-store --query --references $path`; + die "cannot query references of `$path': $?" if $? != 0; my $hash = `nix-store --query --hash $path` or die "cannot query hash of `$path': $?"; diff --git a/src/Hydra/root/error.tt b/src/Hydra/root/error.tt index 12d51798..7b0e4049 100644 --- a/src/Hydra/root/error.tt +++ b/src/Hydra/root/error.tt @@ -1,7 +1,7 @@ [% WRAPPER layout.tt title="Error" %] [% USE HTML %] -

Error

+

[% IF httpStatus %][% httpStatus %][% ELSE %]Error[% END %]

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