source: server/trunk/web/lib/Sophie/Controller/Distrib.pm @ 114

Last change on this file since 114 was 114, checked in by nanardon, 13 years ago
  • add some bot functions
File size: 10.2 KB
Line 
1package Sophie::Controller::Distrib;
2use Moose;
3use namespace::autoclean;
4
5BEGIN {extends 'Catalyst::Controller'; }
6
7=head1 NAME
8
9Sophie::Controller::Distrib - Catalyst Controller
10
11=head1 DESCRIPTION
12
13Catalyst Controller.
14
15=head1 METHODS
16
17=cut
18
19sub list :XMLRPC {
20    my ( $self, $c, $distrib, $release, $arch ) = @_;
21
22    my $distribution;
23    if (ref $distrib) {
24        ($distribution, $release, $arch) = (
25            $distrib->{distribution},
26            $distrib->{release},
27            $distrib->{arch},
28        );
29    } else {
30        $distribution = $distrib;
31    }
32
33    my $rs = $c->model('Base')->resultset('Distribution');
34    if (!$distribution) {
35        return $c->stash->{xmlrpc} = [ map { $_->name }
36            $rs->search(undef, { order_by => ['name'] })->all ];
37    }
38    $rs = $rs->search(name => $distribution)->search_related('Release');
39    if (!$release) {
40        return $c->stash->{xmlrpc} = [ map { $_->version }
41            $rs->search(undef, { order_by => ['version'] })->all ];
42    }
43    $rs = $rs->search(version => $release)->search_related('Arch');
44    if (!$arch) {
45        return $c->stash->{xmlrpc} = [ map { $_->arch } 
46            $rs->search(undef, { order_by => ['arch'] })->all ];
47    }
48    $rs = $rs->search(arch => $arch)->search_related('Medias');
49    return $c->stash->{xmlrpc} = [ map { $_->label }
50        $rs->search(undef, { order_by => ['label'] })->all ];
51}
52
53sub struct :XMLRPC {
54    my ( $self, $c, $distribution, $release, $arch ) = @_;
55
56    if (!ref $distribution) {
57        $distribution = {
58            distribution => $distribution,
59            release => $release,
60            arch => $arch,
61        }
62    }
63
64    my $rs = $c->forward('distrib_rs', [ $distribution ])
65        ->search({}, { order_by => 'label' });
66    $c->stash->{xmlrpc} = [ map { 
67        { 
68            label => $_->label,
69            group_label => $_->group_label,
70        } 
71    } $rs->all ];
72}
73
74sub distrib_rs : Private {
75    my ( $self, $c, $distrib, $asfilter ) = @_;
76    if ($asfilter && !(
77            $distrib->{distribution} ||
78            $distrib->{release} ||
79            $distrib->{arch} ||
80            $distrib->{media} ||
81            $distrib->{media_group})) {
82        return;
83    }
84
85    return $c->model('Base')->resultset('Distribution')
86        ->search(
87            {
88                $distrib->{distribution}
89                    ? (name => $distrib->{distribution})
90                    : ()
91            },
92            {
93                select => [ qw(name shortname) ],
94            }
95        )->search_related('Release',
96            {
97                $distrib->{release}
98                    ? (version => $distrib->{release})
99                    : ()
100            },
101            {
102                select => [ qw(version) ],
103            }
104        )->search_related('Arch',
105            {
106                $distrib->{arch}
107                    ? (arch => $distrib->{arch})
108                    : ()
109            },
110            {
111                select => [ qw(arch) ],
112            }
113        )->search_related('Medias',
114            {
115                ($distrib->{media} ? (label => $distrib->{media}) : ()),
116                ($distrib->{media_group}
117                    ? (group_label => $distrib->{media_group})
118                    : ()),
119            },
120            {
121                select => [ qw(label group_label) ],
122            }
123        );
124}
125
126
127sub exists : XMLRPC {
128    my ( $self, $c, $d ) = @_;
129
130    my $rs = $c->forward('distrib_rs', [ $d ]);
131
132    if ($rs->search({}, { rows => 1 })->next) {
133        $c->stash->{xmlrpc} = 1;
134    } else {
135        $c->stash->{xmlrpc} = 0;
136    }
137}
138
139=head2 index
140
141=cut
142
143sub index :Path :Chained :Args(0)  {
144    my ( $self, $c ) = @_;
145
146    $c->forward('list');
147}
148
149=head release
150
151=cut
152
153sub list_release :Path :Args(1) {
154    my ( $self, $c, $distribution ) = @_;
155    $c->stash->{dist}{distribution} = $distribution;
156    if (!$c->forward('exists', [ $c->stash->{dist} ])) {
157        $c->go('/404/index');
158    }
159    $c->forward('list', [ $c->stash->{dist} ] );
160}
161
162sub list_arch :Path :Args(2) {
163    my ( $self, $c, $distribution, $release ) = @_;
164    $c->stash->{dist}{distribution} = $distribution;
165    $c->stash->{dist}{release} = $release;
166    $c->forward('list', [ $c->stash->{dist} ] );
167}
168
169
170sub distrib_view :PathPrefix :Chained :CaptureArgs(3) {
171    my ( $self, $c, $distribution, $release, $arch ) = @_;
172    $c->stash->{dist}{distribution} = $distribution;
173    $c->stash->{dist}{release} = $release;
174    $c->stash->{dist}{arch} = $arch;
175    $c->stash->{distrib} = $c->stash->{dist};
176}
177
178sub distrib :Chained('distrib_view') PathPart('') :Args(0) {
179    my ( $self, $c ) = @_;
180    $c->forward('list', [ $c->stash->{dist} ]);
181    # TODO store properly results
182    # No call from json here
183}
184
185sub media :Chained('/distrib/distrib_view') PathPart('media') :Args(0) {
186    my ( $self, $c ) = @_;
187    $c->forward('struct', [ $c->stash->{dist} ]);
188}
189
190sub anyrpms :XMLRPC {
191    my ( $self, $c, $distribution, $release, $arch ) = @_;
192
193    if (!ref $distribution) {
194        $distribution = {
195            distribution => $distribution,
196            release => $release,
197            arch => $arch,
198        }
199    }
200
201    @{$c->stash->{rpm}} = map {
202            { 
203              pkgid => $_->pkgid,
204              filename => $_->filename,
205            }
206        }
207        $c->forward('distrib_rs', [ $distribution ])
208        ->search_related('MediasPaths')
209        ->search_related('Paths')
210        ->search_related('Rpmfiles')
211        ->all;
212
213    $c->stash->{xmlrpc} = $c->stash->{rpm};
214}
215
216sub rpms :XMLRPC {
217    my ( $self, $c, $distribution, $release, $arch ) = @_;
218
219    if (!ref $distribution) {
220        $distribution = {
221            distribution => $distribution,
222            release => $release,
223            arch => $arch,
224        }
225    }
226
227    $c->stash->{rpm} = [ map {
228            { 
229              pkgid => $_->pkgid,
230              filename => $_->filename,
231            }
232        }
233        $c->forward('distrib_rs', [ $distribution ])
234        ->search_related('MediasPaths')
235        ->search_related('Paths')
236        ->search_related('Rpmfiles', {
237            pkgid => {
238                IN => $c->model('Base')->resultset('Rpms')
239                ->search({ issrc => 'false' })->get_column('pkgid') ->as_query }
240        } )->all ];
241
242    $c->stash->{xmlrpc} = $c->stash->{rpm};
243}
244
245sub srpms :XMLRPC {
246    my ( $self, $c, $distribution, $release, $arch ) = @_;
247
248    if (!ref $distribution) {
249        $distribution = {
250            distribution => $distribution,
251            release => $release,
252            arch => $arch,
253        }
254    }
255
256    @{$c->stash->{rpm}} = map {
257            { 
258              pkgid => $_->pkgid,
259              filename => $_->filename,
260            }
261        }
262        $c->forward('distrib_rs', [ $distribution ])
263        ->search_related('MediasPaths')
264        ->search_related('Paths')
265        ->search_related('Rpmfiles', {
266            pkgid => {
267                IN => $c->model('Base')->resultset('Rpms')
268                ->search({ issrc => 'true' })->get_column('pkgid') ->as_query }
269        } )->all;
270
271    $c->stash->{xmlrpc} = $c->stash->{rpm};
272}
273
274sub rpms_name :XMLRPC {
275    my ( $self, $c, $distribution, $release, $arch ) = @_;
276
277    if (!ref $distribution) {
278        $distribution = {
279            distribution => $distribution,
280            release => $release,
281            arch => $arch,
282        }
283    }
284
285    $c->stash->{xmlrpc} = [
286        $c->model('Base')->resultset('Rpms')->search(
287            { pkgid => {
288                IN =>
289        $c->forward('distrib_rs', [ $distribution ])
290        ->search_related('MediasPaths')
291        ->search_related('Paths')
292        ->search_related('Rpmfiles')->get_column('pkgid')->as_query
293        } },
294        { group_by => [ qw(name) ], order_by => [ qw(name) ] }
295        )->get_column('name')->all ];
296}
297
298sub list_rpms :Chained('distrib_view') PathPart('rpms') Args(0) {
299    my ( $self, $c ) = @_;
300    $c->forward('rpms', $c->stash->{dist});
301}
302
303sub list_srpms :Chained('distrib_view') PathPart('srpms') Args(0) {
304    my ( $self, $c ) = @_;
305    $c->forward('srpms', $c->stash->{dist});
306}
307
308sub srpm_by_name :Chained('distrib_view') PathPart('srpms') {
309    my ($self, $c, $name, @subpart) = @_;
310    $c->stash->{dist}{src} = 1;
311    ($c->stash->{pkgid}) = @{ $c->forward('/search/bytag',
312        [ $c->stash->{dist}, 'name', $name ])->{results} };
313    $c->go('/404/index') unless ($c->stash->{pkgid});
314    $c->go('/rpms/rpms', [ $c->stash->{pkgid}, @subpart ]);
315}
316
317sub rpm_by_name :Chained('distrib_view') PathPart('rpms') {
318    my ($self, $c, $name, @subpart) = @_;
319    $c->stash->{dist}{src} = 0;
320    ($c->stash->{pkgid}) = @{ $c->forward('/search/bytag',
321        [ $c->stash->{dist}, 'name', $name ])->{results} };
322    $c->go('/404/index') unless ($c->stash->{pkgid});
323    $c->go('/rpms/rpms', [ $c->stash->{pkgid}, @subpart ]);
324}
325
326sub rpm_bypkgid :Chained('distrib_view') PathPart('by-pkgid') {
327    my ( $self, $c, $pkgid, @subpart ) = @_;
328    if ($pkgid) {
329        if (@{ $c->forward('/search/bypkgid',
330            [ $c->stash->{dist}, $pkgid ])->{results} } ) {
331            $c->go('/rpms/rpms', [ $pkgid, @subpart ]);
332        } else {
333            $c->go('/404/index');
334        }
335    } else {
336        $c->forward('anyrpms', [ $c->stash->{dist} ]);
337    }
338}
339
340sub _media_list_rpms :Chained('distrib_view') PathPart('media') CaptureArgs(1) {
341    my ( $self, $c, $media ) = @_;
342    $c->stash->{dist}{media} = $media;
343}
344
345sub media_list_rpms :Chained('_media_list_rpms') PathPart('') :Args(0) {
346    my ( $self, $c ) = @_;
347    $c->forward('anyrpms', [ $c->stash->{dist} ]);
348}
349
350sub media_rpm_byname :Chained('_media_list_rpms') PathPart('rpms') {
351    my ( $self, $c, $name ) = @_;
352}
353sub media_srpm_byname :Chained('_media_list_rpms') PathPart('srpms') {
354    my ( $self, $c, $name ) = @_;
355}
356
357sub media_rpm_bypkgid :Chained('_media_list_rpms') PathPart('by-pkgid') {
358    my ( $self, $c, $pkgid, @part ) = @_;
359    if ($pkgid) {
360        if (@{ $c->forward('/search/bypkgid', [ $c->stash->{dist}, $pkgid
361            ])->{results} } ) {
362            $c->stash->{pkgid} = $pkgid;
363            $c->go('/rpms/rpms', [ $pkgid, @part ]);
364        } else {
365            $c->go('/404/index');
366        }
367    } else {
368        $c->forward('anyrpms', [ $c->stash->{dist} ]);
369    }
370}
371
372=head1 AUTHOR
373
374Olivier Thauvin
375
376=head1 LICENSE
377
378This library is free software. You can redistribute it and/or modify
379it under the same terms as Perl itself.
380
381=cut
382
383__PACKAGE__->meta->make_immutable;
384
3851;
Note: See TracBrowser for help on using the repository browser.