| 1 | package Arepa::Web::Repository; | ||
| 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 | my $repository = Arepa::Repository->new($self->config_path); | ||
| 17 | my $pdb = Arepa::PackageDb->new($self->config->get_key('package_db')); | ||
| 18 | |||
| 19 | my %packages = $repository->get_package_list; | ||
| 20 | my %comments = (); | ||
| 21 | foreach my $pkg (keys %packages) { | ||
| 22 | foreach my $comp (keys %{$packages{$pkg}}) { | ||
| 23 | foreach my $version (keys %{$packages{$pkg}->{$comp}}) { | ||
| 24 | if (grep { $_ eq 'source' } | ||
| 25 | @{$packages{$pkg}->{$comp}->{$version}}) { | ||
| 26 | my $id = $pdb->get_source_package_id($pkg, $version); | ||
| 27 | my %source_pkg = $pdb->get_source_package_by_id($id); | ||
| 28 | $comments{$pkg}->{$version} = $source_pkg{comments}; | ||
| 29 | } | ||
| 30 | } | ||
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | $self->show_view({ packages => \%packages, | ||
| 35 | comments => \%comments }); | ||
| 36 | } | ||
| 37 | |||
| 38 | sub view { | ||
| 39 | my ($self) = @_; | ||
| 40 | |||
| 41 | if ($self->config->key_exists('repository:url')) { | ||
| 42 | my $repo_url = $self->config->get_key('repository:url'); | ||
| 43 | my @url_parts = @{$self->tx->req->url->path->parts}; | ||
| 44 | my $package_name = $url_parts[$#url_parts]; | ||
| 45 | my $package_dir = ($package_name =~ /^lib/) ? | ||
| 46 | substr($package_name, 0, 4) : | ||
| 47 | substr($package_name, 0, 1); | ||
| 48 | my $package_in_repo_url = $repo_url . "/pool/main/" . $package_dir . | ||
| 49 | "/" . $package_name; | ||
| 50 | $self->redirect_to($package_in_repo_url); | ||
| 51 | } | ||
| 52 | else { | ||
| 53 | $self->_add_error("No 'repository:url' configuration key found. Please make it point to your repository URL to use this feature"); | ||
| 54 | $self->vars(errors => [$self->_error_list]); | ||
| 55 | $self->render('error'); | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | sub sync { | ||
| 60 | my ($self) = @_; | ||
| 61 | |||
| 62 | $self->_only_if_admin(sub { | ||
| 63 | if ($self->config->key_exists('repository:remote_path')) { | ||
| 64 | my $cmd = "sudo -H -u arepa-master arepa sync"; | ||
| 65 | if (system("$cmd >/dev/null") != 0) { | ||
| 66 | $self->_add_error("Couldn't synchronize the repository with the command '$cmd'"); | ||
| 67 | } | ||
| 68 | } | ||
| 69 | if ($self->_error_list) { | ||
| 70 | $self->vars(errors => [$self->_error_list]); | ||
| 71 | $self->render('error'); | ||
| 72 | } | ||
| 73 | else { | ||
| 74 | $self->redirect_to('home'); | ||
| 75 | } | ||
| 76 | }); | ||
| 77 | } | ||
| 78 | |||
| 79 | 1; |