1 | package Sophie::Controller::Distrib; |
---|
2 | use Moose; |
---|
3 | use namespace::autoclean; |
---|
4 | |
---|
5 | BEGIN {extends 'Catalyst::Controller'; } |
---|
6 | |
---|
7 | =head1 NAME |
---|
8 | |
---|
9 | Sophie::Controller::Distrib - Catalyst Controller |
---|
10 | |
---|
11 | =head1 DESCRIPTION |
---|
12 | |
---|
13 | Catalyst Controller. |
---|
14 | |
---|
15 | =head1 METHODS |
---|
16 | |
---|
17 | =cut |
---|
18 | |
---|
19 | sub 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 | |
---|
53 | sub struct :XMLRPC { |
---|
54 | my ( $self, $c, $distrib, $release, $arch ) = @_; |
---|
55 | |
---|
56 | my $distribution; |
---|
57 | if (ref $distrib) { |
---|
58 | ($distribution, $release, $arch) = ( |
---|
59 | $distrib->{distribution}, |
---|
60 | $distrib->{release}, |
---|
61 | $distrib->{arch}, |
---|
62 | ); |
---|
63 | } else { |
---|
64 | $distribution = $distrib; |
---|
65 | } |
---|
66 | |
---|
67 | my $rs = $c->model('Base')->resultset('Distribution') |
---|
68 | ->search(name => $distribution) |
---|
69 | ->search_related('Release', { version => $release }) |
---|
70 | ->search_related('Arch', { arch => $arch }) |
---|
71 | ->search_related('Medias')->search({}, { order_by => 'label' }); |
---|
72 | $c->stash->{xmlrpc} = [ map { |
---|
73 | { |
---|
74 | label => $_->label, |
---|
75 | group_label => $_->group_label, |
---|
76 | } |
---|
77 | } $rs->all ]; |
---|
78 | } |
---|
79 | |
---|
80 | |
---|
81 | =head2 index |
---|
82 | |
---|
83 | =cut |
---|
84 | |
---|
85 | sub index :Path :Chained :Args(0) { |
---|
86 | my ( $self, $c ) = @_; |
---|
87 | |
---|
88 | $c->forward('list'); |
---|
89 | } |
---|
90 | |
---|
91 | =head release |
---|
92 | |
---|
93 | =cut |
---|
94 | |
---|
95 | sub list_release :Path :Args(1) { |
---|
96 | my ( $self, $c, $distribution ) = @_; |
---|
97 | $c->stash->{dist}{distribution} = $distribution; |
---|
98 | $c->forward('list', [ $c->stash->{dist} ] ); |
---|
99 | } |
---|
100 | |
---|
101 | sub list_arch :Path :Args(2) { |
---|
102 | my ( $self, $c, $distribution, $release ) = @_; |
---|
103 | $c->stash->{dist}{distribution} = $distribution; |
---|
104 | $c->stash->{dist}{release} = $release; |
---|
105 | $c->forward('list', [ $c->stash->{dist} ] ); |
---|
106 | } |
---|
107 | |
---|
108 | |
---|
109 | sub distrib_view :PathPrefix :Chained :CaptureArgs(3) { |
---|
110 | my ( $self, $c, $distribution, $release, $arch ) = @_; |
---|
111 | $c->stash->{dist}{distribution} = $distribution; |
---|
112 | $c->stash->{dist}{release} = $release; |
---|
113 | $c->stash->{dist}{arch} = $arch; |
---|
114 | $c->stash->{distrib} = $c->stash->{dist}; |
---|
115 | } |
---|
116 | |
---|
117 | sub distrib :Chained('distrib_view') PathPart('') { |
---|
118 | my ( $self, $c ) = @_; |
---|
119 | $c->forward('list', [ $c->stash->{dist} ]); |
---|
120 | # TODO store properly results |
---|
121 | # No call from json here |
---|
122 | } |
---|
123 | |
---|
124 | sub media :Chained('distrib_view') PathPart('media') { |
---|
125 | my ( $self, $c ) = @_; |
---|
126 | $c->forward('struct', [ $c->stash->{dist} ]); |
---|
127 | } |
---|
128 | |
---|
129 | sub rpms :XMLRPC { |
---|
130 | my ( $self, $c, $distribution, $release, $arch ) = @_; |
---|
131 | |
---|
132 | if (ref $distribution) { |
---|
133 | ($distribution, $release, $arch) = ( |
---|
134 | $distribution->{distribution}, |
---|
135 | $distribution->{release}, |
---|
136 | $distribution->{arch}, |
---|
137 | ); |
---|
138 | } |
---|
139 | |
---|
140 | @{$c->stash->{rpm}} = map { |
---|
141 | { |
---|
142 | pkgid => $_->pkgid, |
---|
143 | filename => $_->filename, |
---|
144 | } |
---|
145 | } |
---|
146 | $c->model('Base') |
---|
147 | ->resultset('Distribution')->search({ name => $distribution }) |
---|
148 | ->search_related('Release', { version => $release }) |
---|
149 | ->search_related('Arch', { arch => $arch }) |
---|
150 | ->search_related('Medias') |
---|
151 | ->search_related('MediasPaths') |
---|
152 | ->search_related('Paths') |
---|
153 | ->search_related('Rpmfiles', { |
---|
154 | pkgid => { |
---|
155 | IN => $c->model('Base')->resultset('Rpms') |
---|
156 | ->search({ issrc => 'false' })->get_column('pkgid') ->as_query } |
---|
157 | } )->all; |
---|
158 | |
---|
159 | $c->stash->{xmlrpc} = $c->stash->{rpm}; |
---|
160 | } |
---|
161 | |
---|
162 | sub srpms :XMLRPC { |
---|
163 | my ( $self, $c, $distribution, $release, $arch ) = @_; |
---|
164 | |
---|
165 | if (ref $distribution) { |
---|
166 | ($distribution, $release, $arch) = ( |
---|
167 | $distribution->{distribution}, |
---|
168 | $distribution->{release}, |
---|
169 | $distribution->{arch}, |
---|
170 | ); |
---|
171 | } |
---|
172 | |
---|
173 | @{$c->stash->{rpm}} = map { |
---|
174 | { |
---|
175 | pkgid => $_->pkgid, |
---|
176 | filename => $_->filename, |
---|
177 | } |
---|
178 | } |
---|
179 | $c->model('Base') |
---|
180 | ->resultset('Distribution')->search({ name => $distribution }) |
---|
181 | ->search_related('Release', { version => $release }) |
---|
182 | ->search_related('Arch', { arch => $arch }) |
---|
183 | ->search_related('Medias') |
---|
184 | ->search_related('MediasPaths') |
---|
185 | ->search_related('Paths') |
---|
186 | ->search_related('Rpmfiles', { |
---|
187 | pkgid => { |
---|
188 | IN => $c->model('Base')->resultset('Rpms') |
---|
189 | ->search({ issrc => 'true' })->get_column('pkgid') ->as_query } |
---|
190 | } )->all; |
---|
191 | |
---|
192 | $c->stash->{xmlrpc} = $c->stash->{rpm}; |
---|
193 | } |
---|
194 | |
---|
195 | sub list_rpms :Chained('distrib_view') PathPart('rpms') { |
---|
196 | my ( $self, $c ) = @_; |
---|
197 | $c->forward('rpms', $c->stash->{dist}); |
---|
198 | } |
---|
199 | |
---|
200 | sub list_srpms :Chained('distrib_view') PathPart('srpms') { |
---|
201 | my ( $self, $c ) = @_; |
---|
202 | $c->forward('srpms', $c->stash->{dist}); |
---|
203 | } |
---|
204 | |
---|
205 | sub srpm_by_name :Chained('distrib_view') PathPart('srpms/by-name') Args(1) { |
---|
206 | } |
---|
207 | sub rpm_by_name :Chained('distrib_view') PathPart('rpms/by-name') Args(1) { |
---|
208 | } |
---|
209 | sub rpm_by_pkid :Chained('distrib_view') PathPart('by-pkgid') Args(1) { |
---|
210 | } |
---|
211 | |
---|
212 | sub media_rpms : XMLRPC { |
---|
213 | my ( $self, $c, $distribution, $release, $arch, $media ) = @_; |
---|
214 | |
---|
215 | if (ref $distribution) { |
---|
216 | ($distribution, $release, $arch, $media) = ( |
---|
217 | $distribution->{distribution}, |
---|
218 | $distribution->{release}, |
---|
219 | $distribution->{arch}, |
---|
220 | $release, |
---|
221 | ); |
---|
222 | } |
---|
223 | |
---|
224 | @{$c->stash->{rpm}} = map { |
---|
225 | { |
---|
226 | pkgid => $_->pkgid, |
---|
227 | filename => $_->filename, |
---|
228 | } |
---|
229 | } |
---|
230 | $c->model('Base') |
---|
231 | ->resultset('Distribution')->search({ name => $distribution }) |
---|
232 | ->search_related('Release', { version => $release }) |
---|
233 | ->search_related('Arch', { arch => $arch }) |
---|
234 | ->search_related('Medias', { label => $media }) |
---|
235 | ->search_related('MediasPaths') |
---|
236 | ->search_related('Paths') |
---|
237 | ->search_related('Rpmfiles')->all; |
---|
238 | |
---|
239 | $c->stash->{xmlrpc} = $c->stash->{rpm}; |
---|
240 | } |
---|
241 | |
---|
242 | sub _media_list_rpms :Chained('distrib_view') PathPart('media') CaptureArgs(1) { |
---|
243 | my ( $self, $c, $media ) = @_; |
---|
244 | $c->stash->{media} = $media; |
---|
245 | } |
---|
246 | |
---|
247 | sub media_list_rpms :Chained('_media_list_rpms') PathPart('') { |
---|
248 | my ( $self, $c ) = @_; |
---|
249 | $c->forward('media_rpms', [ $c->stash->{dist}, $c->stash->{media} ]); |
---|
250 | } |
---|
251 | |
---|
252 | sub media_rpm_byname :Chained('_media_list_rpms') PathPart('rpms/by-name') { |
---|
253 | my ( $self, $c ) = @_; |
---|
254 | } |
---|
255 | sub media_srpm_byname :Chained('_media_list_rpms') PathPart('srpms/by-name') { |
---|
256 | my ( $self, $c ) = @_; |
---|
257 | } |
---|
258 | sub media_rpm_bypkgid :Chained('_media_list_rpms') PathPart('by-pkgid') { |
---|
259 | my ( $self, $c, $pkgid ) = @_; |
---|
260 | $c->forward('/rpms/rpms', [ $pkgid ]); |
---|
261 | } |
---|
262 | |
---|
263 | =head1 AUTHOR |
---|
264 | |
---|
265 | Olivier Thauvin |
---|
266 | |
---|
267 | =head1 LICENSE |
---|
268 | |
---|
269 | This library is free software. You can redistribute it and/or modify |
---|
270 | it under the same terms as Perl itself. |
---|
271 | |
---|
272 | =cut |
---|
273 | |
---|
274 | __PACKAGE__->meta->make_immutable; |
---|
275 | |
---|
276 | 1; |
---|