| 1 | package Arepa::Web::Dashboard; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use base 'Arepa::Web::Base'; | ||
| 7 | |||
| 8 | use Parse::Debian::PackageDesc; | ||
| 9 | use Arepa::Config; | ||
| 10 | use Arepa::Repository; | ||
| 11 | use Arepa::BuilderFarm; | ||
| 12 | |||
| 13 | sub index { | ||
| 14 | my ($self) = @_; | ||
| 15 | |||
| 16 | # For backwards compatibility with old RSS URLs | ||
| 17 | if ($self->param('rm') && $self->param('rm') eq 'public_rss') { | ||
| 18 | return $self->redirect_to(controller => 'public', action => 'rss'); | ||
| 19 | } | ||
| 20 | |||
| 21 | # Compilation queue ------------------------------------------------------ | ||
| 22 | my $packagedb = | ||
| 23 | Arepa::PackageDb->new($self->config->get_key('package_db')); | ||
| 24 | my @compilation_queue = $packagedb-> | ||
| 25 | get_compilation_queue(status => 'pending', | ||
| 26 | limit => 10); | ||
| 27 | my @pending_compilations = (); | ||
| 28 | foreach my $comp (@compilation_queue) { | ||
| 29 | my %source_pkg_attrs = | ||
| 30 | $packagedb->get_source_package_by_id($comp->{source_package_id}); | ||
| 31 | push @pending_compilations, { | ||
| 32 | %$comp, | ||
| 33 | package => { %source_pkg_attrs }, | ||
| 34 | }; | ||
| 35 | } | ||
| 36 | |||
| 37 | # Packages pending approval ---------------------------------------------- | ||
| 38 | my @packages = (); | ||
| 39 | if (opendir D, $self->config->get_key('upload_queue:path')) { | ||
| 40 | @packages = grep /\.changes$/, readdir D; | ||
| 41 | closedir D; | ||
| 42 | } | ||
| 43 | my (@readable_packages, @unreadable_packages, %source_package_info); | ||
| 44 | my $gpg_dir = $self->config->get_key('web_ui:gpg_homedir'); | ||
| 45 | my $repository = Arepa::Repository->new($self->config_path); | ||
| 46 | foreach my $package (@packages) { | ||
| 47 | my $package_path = | ||
| 48 | $self->config->get_key('upload_queue:path')."/".$package; | ||
| 49 | my $obj = undef; | ||
| 50 | eval { | ||
| 51 | $obj = Parse::Debian::PackageDesc->new($package_path, | ||
| 52 | gpg_homedir => $gpg_dir); | ||
| 53 | }; | ||
| 54 | if ($obj) { | ||
| 55 | push @readable_packages, $obj; | ||
| 56 | |||
| 57 | # Fetch some extra information from already existing packages | ||
| 58 | my $pkg = $obj->source; | ||
| 59 | $source_package_info{$pkg} = {}; | ||
| 60 | my $id = $packagedb->get_source_package_id($pkg, '*latest*'); | ||
| 61 | if ($id) { | ||
| 62 | my %source_pkg = $packagedb->get_source_package_by_id($id); | ||
| 63 | $source_package_info{$pkg}->{comments} = $source_pkg{comments}; | ||
| 64 | } | ||
| 65 | my $builder_farm = Arepa::BuilderFarm->new($self->config_path); | ||
| 66 | my ($arch) = grep { $_ ne 'source' } $obj->architecture; | ||
| 67 | my $canonical_distro = | ||
| 68 | $builder_farm->canonical_distribution($arch, | ||
| 69 | $obj->distribution); | ||
| 70 | my %source_props = | ||
| 71 | $repository->get_source_package_information($pkg, $canonical_distro); | ||
| 72 | if (%source_props) { | ||
| 73 | foreach (qw(priority section)) { | ||
| 74 | $source_package_info{$pkg}->{$_} = $source_props{$_}; | ||
| 75 | } | ||
| 76 | } | ||
| 77 | } | ||
| 78 | else { | ||
| 79 | push @unreadable_packages, $package; | ||
| 80 | } | ||
| 81 | } | ||
| 82 | |||
| 83 | # Builder status --------------------------------------------------------- | ||
| 84 | # Get the builder information and find out which package is being compiled | ||
| 85 | # by each builder, if any | ||
| 86 | my @builder_list = (); | ||
| 87 | my @compiling_packages = $packagedb-> | ||
| 88 | get_compilation_queue(status => 'compiling', | ||
| 89 | limit => 10); | ||
| 90 | foreach my $builder_name ($self->config->get_builders) { | ||
| 91 | my %extra_attrs = (status => 'idle'); | ||
| 92 | foreach my $pkg (@compiling_packages) { | ||
| 93 | if ($pkg->{builder} eq $builder_name) { | ||
| 94 | my %source_pkg_attrs = $packagedb->get_source_package_by_id($pkg->{source_package_id}); | ||
| 95 | $extra_attrs{status} = 'compiling'; | ||
| 96 | $extra_attrs{package} = { %source_pkg_attrs }; | ||
| 97 | $extra_attrs{since} = $pkg->{compilation_started_at}; | ||
| 98 | } | ||
| 99 | } | ||
| 100 | push @builder_list, | ||
| 101 | { $self->config->get_builder_config($builder_name), | ||
| 102 | %extra_attrs }; | ||
| 103 | } | ||
| 104 | |||
| 105 | # Latest compilation failures -------------------------------------------- | ||
| 106 | my @failed_compilations = (); | ||
| 107 | my @failed_compilation_queue = $packagedb-> | ||
| 108 | get_compilation_queue(status => 'compilationfailed', | ||
| 109 | order => "compilation_completed_at DESC", | ||
| 110 | limit => 10); | ||
| 111 | foreach my $comp (@failed_compilation_queue) { | ||
| 112 | my %source_pkg_attrs = | ||
| 113 | $packagedb->get_source_package_by_id($comp->{source_package_id}); | ||
| 114 | push @failed_compilations, { | ||
| 115 | %$comp, | ||
| 116 | package => { %source_pkg_attrs }, | ||
| 117 | }; | ||
| 118 | } | ||
| 119 | |||
| 120 | # Latest compiled packages ----------------------------------------------- | ||
| 121 | my @latest_compilations = (); | ||
| 122 | my @latest_compilation_queue = $packagedb-> | ||
| 123 | get_compilation_queue(status => 'compiled', | ||
| 124 | order => "compilation_completed_at DESC", | ||
| 125 | limit => 10); | ||
| 126 | foreach my $comp (@latest_compilation_queue) { | ||
| 127 | my %source_pkg_attrs = | ||
| 128 | $packagedb->get_source_package_by_id($comp->{source_package_id}); | ||
| 129 | push @latest_compilations, { | ||
| 130 | %$comp, | ||
| 131 | package => { %source_pkg_attrs }, | ||
| 132 | }; | ||
| 133 | } | ||
| 134 | |||
| 135 | my $is_synced; | ||
| 136 | my $remote_repo_path; | ||
| 137 | if ($self->config->key_exists('web_ui:check_remote_repo') && | ||
| 138 | $self->config->get_key('web_ui:check_remote_repo') && | ||
| 139 | $self->config->key_exists('repository:remote_path')) { | ||
| 140 | my $r = system("sudo -H -u arepa-master arepa issynced >/dev/null"); | ||
| 141 | $is_synced = ($r == 0); | ||
| 142 | $remote_repo_path = $self->config->get_key('repository:remote_path'); | ||
| 143 | } | ||
| 144 | |||
| 145 | # Print everything ------------------------------------------------------- | ||
| 146 | $self->vars(config => $self->config, | ||
| 147 | packages => \@readable_packages, | ||
| 148 | source_package_info => \%source_package_info, | ||
| 149 | unreadable_packages => \@unreadable_packages, | ||
| 150 | compilation_queue => \@pending_compilations, | ||
| 151 | builders => \@builder_list, | ||
| 152 | failed_compilations => \@failed_compilations, | ||
| 153 | latest_compilations => \@latest_compilations, | ||
| 154 | is_synced => $is_synced, | ||
| 155 | remote_repo_path => $remote_repo_path); | ||
| 156 | |||
| 157 | $self->render(layout => 'default'); | ||
| 158 | } | ||
| 159 | |||
| 160 | 1; |