From f81b033210bf91cd464e88417a759dc7a06275fb Mon Sep 17 00:00:00 2001 From: Olivier Thauvin Date: Fri, 5 Nov 2010 20:33:33 +0000 Subject: - add support for mirror list --- lib/MGA/Mirrors/Controller/Api.pm | 79 +++++++++++++++++++++++++++++++++++++++ lib/MGA/Mirrors/DB.pm | 10 +++-- 2 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 lib/MGA/Mirrors/Controller/Api.pm (limited to 'lib/MGA') diff --git a/lib/MGA/Mirrors/Controller/Api.pm b/lib/MGA/Mirrors/Controller/Api.pm new file mode 100644 index 0000000..91846dc --- /dev/null +++ b/lib/MGA/Mirrors/Controller/Api.pm @@ -0,0 +1,79 @@ +package MGA::Mirrors::Controller::Api; +use Moose; +use namespace::autoclean; + +BEGIN {extends 'Catalyst::Controller'; } + +=head1 NAME + +MGA::Mirrors::Controller::Api - Catalyst Controller + +=head1 DESCRIPTION + +Catalyst Controller. + +=head1 METHODS + +=cut + + +=head2 index + +=cut + +sub index :Path :Args(0) { + my ( $self, $c ) = @_; + + $c->response->body('Matched MGA::Mirrors::Controller::Api in Api.'); +} + +sub list :Path :Args(1) { + my ( $self, $c, $arg ) = @_; + + my ($product, $version, $arch) = $arg =~ m/^([^\.]+)\.(.+)\.([^\.]+)\.list$/; + + $c->log->debug("$product, $version, $arch"); + + my $list = $c->model('Mirrors')->find_distributions( + { + version => $version, + arch => $arch, + exists => 1, + public => 1, + } + ); + + $c->stash->{current_view} = ''; + $c->response->body(join("\n", + map { + my @tags; + push(@tags, 'continent=' . $_->{ccode}) if ($_->{ccode}); + push(@tags, 'zone=' . $_->{code}) if ($_->{code}); + push(@tags, 'country=' . $_->{country}) if ($_->{country}); + push(@tags, 'city=' . $_->{city}) if ($_->{city}); + push(@tags, 'latitude=' . $_->{latitude}) if ($_->{latitude}); + push(@tags, 'longitude=' . $_->{longitude}) if ($_->{longitude}); + push(@tags, 'version=' . $version); + push(@tags, 'version=' . $arch); + push(@tags, 'type=' . 'distrib'); + push(@tags, 'url=' . $_->{url}) if ($_->{url}); + join(',', @tags); + } @$list + ) . "\n"); +} + + +=head1 AUTHOR + +Olivier Thauvin + +=head1 LICENSE + +This library is free software. You can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut + +__PACKAGE__->meta->make_immutable; + +1; diff --git a/lib/MGA/Mirrors/DB.pm b/lib/MGA/Mirrors/DB.pm index da0534a..f8d1ac2 100644 --- a/lib/MGA/Mirrors/DB.pm +++ b/lib/MGA/Mirrors/DB.pm @@ -397,10 +397,12 @@ sub _find_distributions { $filters->{$_} or next; my $field = { hostname => 'hosts.hostname', - protocol => 'topelvel_urls.protocol', - version => 'distributions.version', - arch => 'distributions.arch', - country => 'mirrors.country', + protocol => 'toplevel_urls.protocol', + version => 'distributions.version', + arch => 'distributions.arch', + country => 'hosts.country', + exists => 'distributions_validity.exists', + public => 'hosts.public', }->{$_} or next; push(@w, sprintf('%s = any(?)', $field)); -- cgit v1.2.1