source: server/trunk/web/lib/Sophie/Controller/Chat/Cmd.pm @ 271

Last change on this file since 271 was 271, checked in by nanardon, 13 years ago
  • document whatis
  • Property svn:keywords set to Id Rev
File size: 21.0 KB
Line 
1package Sophie::Controller::Chat::Cmd;
2use Moose;
3use namespace::autoclean;
4use Getopt::Long;
5
6BEGIN {extends 'Catalyst::Controller'; }
7
8=head1 NAME
9
10Sophie::Controller::Chat::Cmd - Catalyst Controller
11
12=head1 DESCRIPTION
13
14Catalyst Controller.
15
16=head1 METHODS
17
18=cut
19
20
21=head2 index
22
23=cut
24
25=head2 end
26
27=cut
28
29sub end : Private {
30    my ($self, $c ) = @_;
31   
32    $c->forward('/chat/update_statistic', [ ($c->action =~ /([^\/]+)$/)[0] ]);
33
34    my $reqspec = $c->req->arguments->[0];
35    $reqspec->{max_line} ||= 4;
36    my $message =  $c->stash->{xmlrpc};
37
38    my @backup = @{ $message->{message} };
39    my $needpaste = 0;
40
41    if (@{ $message->{message} } > ($reqspec->{max_line})) {
42        @{ $message->{message} } = 
43            # -2 because line 0 and we remove one for paste url
44            @backup[0 .. $reqspec->{max_line} -2];
45        $needpaste = 1;
46    } 
47
48    if ($needpaste && !$reqspec->{nopaste}) {
49        my $cmd = ($c->action =~ /([^\/]+)$/)[0];
50        my (undef, undef, @args) = @{ $c->req->arguments };
51        my $title = join(' ', $cmd, @args); 
52        my $id = $c->forward('/chat/paste', [ $title, join("\n", @backup) ]);
53        if ($id) {
54            push(@{ $message->{message} }, 'All results available here: ' . $c->uri_for('/chat', $id));
55        }
56    }
57
58    $c->stash->{xmlrpc} = $message;
59
60    $c->forward('/end');
61}
62
63=head1 BOT COMMAND
64
65=head2 REPLY
66
67=cut
68
69sub _commands {
70    my ( $self, $c ) = @_;
71    [ grep { m/^[^_]/ } map { $_->name } $self->get_action_methods() ];
72}
73
74sub _getopt : Private {
75    my ( $self, $c, $options, @args) = @_;
76
77    local @ARGV = @args;
78
79    GetOptions(%{ $options || {} });
80
81    return \@ARGV;
82}
83
84sub _fmt_location : Private {
85    my ($self, $c, $searchspec, $pkgid) = @_;
86
87    my @loc;
88    foreach (@{ $c->forward('/rpms/location', [ $pkgid ]) }) {
89        push @loc, sprintf(
90            '%s (%s, %s, %s)',
91            $_->{media},
92            $_->{dist} || $_->{distribution},
93            $_->{release},
94            $_->{arch},
95        );
96    }
97    return join(', ', @loc);
98}
99
100sub _find_rpm_elsewhere : Private {
101    my ($self, $c, $searchspec, $name) = @_;
102    if ($searchspec->{distribution}) {
103        my $rpmlist = $c->forward('/search/rpm/byname', [ 
104                {
105                    distribution => $searchspec->{distribution},
106                    src => $searchspec->{src},
107                    rows => 1,
108                }, $name ]);
109        if (@{$rpmlist}) {
110            return $c->forward('_fmt_location', [ { 
111                        distribution => $searchspec->{distribution}
112                    }, $rpmlist->[0] ]);
113        }
114    }
115    my $rpmlist = $c->forward('/search/rpm/byname', [ { src =>
116                $searchspec->{src}}, $name ]);
117    my %dist;
118    foreach(@$rpmlist) {
119        foreach (@{ $c->forward('/rpms/location', [ $_ ]) }) {
120            $dist{$_->{dist} || $_->{distribution}} = 1;
121        }
122    }
123    if (keys %dist) {
124        return join(', ', sort keys %dist);
125    }
126    return;
127}
128
129=head1 AVAILABLE FUNCTIONS
130
131=cut
132
133=head2 help [cmd]
134
135Return help about command cmd or list available command.
136
137=cut
138
139sub help : XMLRPC {
140    my ( $self, $c, $reqspec, $cmd ) = @_;
141    if ($cmd) {
142        my @message = grep { /\S+/ } split(/\n/,
143            $c->model('Help::POD')->bot_help_text($cmd) || 'No help available');
144        return $c->{stash}->{xmlrpc} = {
145            private_reply => 1,
146            message => \@message,
147        };
148    } else {
149        return $c->{stash}->{xmlrpc} = {
150            private_reply => 1,
151            message => [
152                'available command:',
153                join(', ', sort grep { $_ !~ /^end$/ } @{ $self->_commands }),
154                'Find more at ' . $c->uri_for('/help/chat'),
155            ],
156        }
157    }
158}
159
160=head2 asv
161
162ASV means in french "age, sexe, ville" (age, sex and town).
163Return the version of the Chat module version.
164
165=cut
166
167sub asv : XMLRPC {
168    my ( $self, $c ) = @_;
169    return $c->stash->{xmlrpc} = {
170        message => [ 'Sophie: ' . $Sophie::VERSION . ', Chat ' . q$Rev$ ],
171    };
172}
173
174=head2 q REGEXP
175
176Search rpm name matching C<REGEXP>.
177
178NB: C<.>, C<*>, C<+> have special meaning
179and have to be escaped.
180
181=cut
182
183sub q : XMLRPC {
184    my ($self, $c, $reqspec, @args) = @_;
185
186    $reqspec->{src} = 0;
187
188    @args = @{ $c->forward('_getopt', [
189        {
190            'd=s' => \$reqspec->{distribution},
191            'v=s' => \$reqspec->{release},
192            'a=s' => \$reqspec->{arch},
193            's'   => sub { $reqspec->{src} = 1 },
194        }, @args ]) };
195
196    my $res = $c->forward('/search/tags/name_regexp', $reqspec, $args[0]);
197    warn join(' ', @{ $res });
198    if (!@{ $res }) {
199        return $c->stash->{xmlrpc} = {
200            message => [ 'Nothing match `' . $args[0] . '\'' ]
201        };
202    } else {
203        my @message = 'rpm name matching `' . $args[0] . '\':';
204        while (@{ $res }) {
205            my $str = '';
206            while (length($str) < 70) {
207                my $item = shift(@{ $res }) or last;
208                $str .= ', ' if ($str);
209                $str .= $item->{name};
210            }
211            push(@message, $str);
212        }
213        return $c->stash->{xmlrpc} = {
214            message => \@message,
215        };
216    }
217}
218
219=head2 whatis WORD [WORD2 [...]]
220
221Search rpm having description containing words given as arguments
222
223=cut
224
225sub whatis : XMLRPC {
226    my ($self, $c, $reqspec, @args) = @_;
227
228    $reqspec->{src} = 0;
229
230    @args = @{ $c->forward('_getopt', [
231        {
232            'd=s' => \$reqspec->{distribution},
233            'v=s' => \$reqspec->{release},
234            'a=s' => \$reqspec->{arch},
235            's'   => sub { $reqspec->{src} = 1 },
236        }, @args ]) };
237    my $res = $c->forward('/search/rpm/description', [ $reqspec, @args ]);
238
239    if (@{ $res }) {
240        if (@{ $res } > 100) {
241            return $c->stash->{xmlrpc} = {
242                message => [ 'I have ' . @{ $res } . ' results' ],
243            };
244        } else {
245            my @names = ();
246            foreach (@{ $res }) {
247                my $info = $c->forward('/rpms/basicinfo', [ $_ ]);
248                push(@names, $info->{name});
249            }
250            my @message = 'rpm name matching `' . $args[0] . '\':';
251            while (@names) {
252                my $str = '';
253                while (length($str) < 70) {
254                    my $item = shift(@names) or last;
255                    $str .= ', ' if ($str);
256                    $str .= $item;
257                }
258                push(@message, $str);
259            }
260            return $c->stash->{xmlrpc} = {
261                message => \@message,
262            };
263        }
264    } else {
265        return $c->stash->{xmlrpc} = {
266            message => [ 'No rpm description matches this keywords' ],
267        };
268    }
269}
270
271=head2 version [-s] NAME
272
273Show the version of package C<NAME>.
274
275=cut
276
277sub version : XMLRPC {
278    my ($self, $c, $reqspec, @args) = @_;
279
280    my @message;
281    $reqspec->{src} = 0;
282
283    @args = @{ $c->forward('_getopt', [
284        {
285            'd=s' => \$reqspec->{distribution},
286            'v=s' => \$reqspec->{release},
287            'a=s' => \$reqspec->{arch},
288            's'   => sub { $reqspec->{src} = 1 },
289        }, @args ]) };
290
291    if (!$c->forward('/distrib/exists', [ $reqspec ])) {
292        return $c->stash->{xmlrpc} = {
293            message => [ "I don't have such distribution" ]
294        };
295    }
296
297    my $rpmlist = $c->forward('/search/rpm/byname', [ $reqspec, $args[0] ]);
298    if (!@{ $rpmlist }) {
299        my $else = $c->forward('_find_rpm_elsewhere', [ $reqspec, $args[0] ]);
300        if ($else) {
301            return $c->stash->{xmlrpc} = {
302                message => [ 
303                    "There is no rpm named `$args[0]', but the word matches in " . $else
304                ],
305            }
306        } else {
307            return $c->stash->{xmlrpc} = {
308                message => [ "The rpm named `$args[0]' has not been found" ],
309            }
310        }
311    }
312    foreach (@{ $rpmlist }) {
313        my $info = $c->forward('/rpms/basicinfo', [ $_ ]);
314        push @message, $info->{evr} . ' // ' .
315            $c->forward('_fmt_location', [ $reqspec, $_ ]);
316    }
317    return $c->stash->{xmlrpc} = {
318        message => \@message,
319    }
320}
321
322=head2 v
323
324C<v> is an alias for L<version> command.
325
326=cut
327
328sub v : XMLRPC {
329    my ($self, $c, @args) = @_;
330    $c->forward('version', [ @args ]);
331}
332
333=head2 summary [-s] NAME
334
335Show the summary of package C<NAME>.
336
337=cut
338
339sub summary : XMLRPC {
340    my ($self, $c, $reqspec, @args) = @_;
341
342    $c->forward('qf', [ $reqspec, @args, '%{summary}' ]);
343}
344
345=head2 s
346
347Is an alias for C<summary> command.
348
349=cut
350
351sub s : XMLRPC {
352    my ($self, $c, @args) = @_;
353    $c->forward('summary', [ @args ]);
354}
355
356=head2 packager [-s] NAME
357
358Show the packager of package C<NAME>.
359
360=cut
361
362sub packager : XMLRPC {
363    my ($self, $c, $reqspec, @args) = @_;
364
365    $c->forward('qf', [ $reqspec, @args, '%{packager}' ]);
366}
367
368=head2 p
369
370Is an alias for C<packager> command.
371
372=cut
373
374sub p : XMLRPC {
375    my ($self, $c, @args) = @_;
376    $c->forward('packager', [ @args ]);
377}
378
379=head2 arch [-s] NAME
380
381Show the architecture of package C<NAME>.
382
383=cut 
384
385sub arch : XMLRPC {
386    my ($self, $c, $reqspec, @args) = @_;
387
388    $c->forward('qf', [ $reqspec, @args, '%{arch}' ]);
389}
390
391=head2 a
392
393Is an alias to C<arch> command.
394
395=cut 
396
397sub a : XMLRPC {
398    my ($self, $c, @args) = @_;
399    $c->forward('arch', [ @args ]);
400}
401
402=head2 url [-s] NAME
403
404Show the url of package C<NAME>.
405
406=cut 
407
408sub url : XMLRPC {
409    my ($self, $c, $reqspec, @args) = @_;
410
411    $c->forward('qf', [ $reqspec, @args, '%{url}' ]);
412}
413
414=head2 u
415
416Is an alias to C<url> command.
417
418=cut 
419
420sub u : XMLRPC {
421    my ($self, $c, @args) = @_;
422    $c->forward('url', [ @args ]);
423}
424
425=head2 group [-s] NAME
426
427Show the group of package C<NAME>.
428
429=cut 
430
431sub group : XMLRPC {
432    my ($self, $c, $reqspec, @args) = @_;
433
434    $c->forward('qf', [ $reqspec, @args, '%{group}' ]);
435}
436
437=head2 g
438
439Is an alias to C<group> command.
440
441=cut 
442
443sub g : XMLRPC {
444    my ($self, $c, @args) = @_;
445    $c->forward('group', [ @args ]);
446}
447
448=head2 license [-s] NAME
449
450Show the license of package C<NAME>.
451
452=cut 
453
454sub license : XMLRPC {
455    my ($self, $c, $reqspec, @args) = @_;
456
457    $c->forward('qf', [ $reqspec, @args, '%{license}' ]);
458}
459
460=head2 l
461
462Is an alias to C<license> command.
463
464=cut 
465
466sub l : XMLRPC {
467    my ($self, $c, @args) = @_;
468    $c->forward('license', [ @args ]);
469}
470
471=head2 buildtime [-s] NAME
472
473Show the build time of package C<NAME>.
474
475=cut
476
477sub buildtime : XMLRPC {
478    my ($self, $c, $reqspec, @args) = @_;
479
480    $c->forward('qf', [ $reqspec, @args, '%{buildtime:date}' ]);
481}
482
483=head2 builddate
484
485Is an alias for C<buildtime> command.
486
487=cut
488
489sub builddate : XMLRPC {
490    my ($self, $c, @args) = @_;
491    $c->forward('buildtime', [ @args ]);
492}
493
494=head2 builddate
495
496Is an alias for C<buildtime> command.
497
498=cut
499
500sub b : XMLRPC {
501    my ($self, $c, @args) = @_;
502    $c->forward('builddate', [ @args ]);
503}
504
505=head2 cookie [-s] NAME
506
507Show the C<cookie> tag of package C<NAME>.
508
509=cut
510
511sub cookie : XMLRPC {
512    my ($self, $c, $reqspec, @args) = @_;
513
514    $c->forward('qf', [ $reqspec, @args, '%{cookie}' ]);
515}
516
517=head2 sourcerpm NAME
518
519Show the C<sourcerpm> tag of package C<NAME>.
520
521=cut
522
523sub sourcerpm : XMLRPC {
524    my ($self, $c, $reqspec, @args) = @_;
525
526    $c->forward('qf', [ $reqspec, @args, '%{sourcerpm}' ]);
527}
528
529=head2 src NAME
530
531Is an alias for C<sourcerpm> command.
532
533=cut
534
535sub src : XMLRPC {
536    my ($self, $c, $reqspec, @args) = @_;
537
538    $c->forward('sourcerpm', [ $reqspec, @args ]);
539}
540
541=head2 rpmversion NAME
542
543Show the C<rpmversion> tag of package C<NAME>.
544
545=cut
546
547sub rpmversion : XMLRPC {
548    my ($self, $c, $reqspec, @args) = @_;
549
550    $c->forward('qf', [ $reqspec, @args, '%{rpmversion}' ]);
551}
552
553=head2 rpmbuildversion NAME
554
555Is an alias for C<rpmversion> command.
556
557=cut
558
559sub rpmbuildversion : XMLRPC {
560    my ($self, $c, $reqspec, @args) = @_;
561
562    $c->forward('rpmversion', [ $reqspec, @args ]);
563}
564
565
566=head2 buildhost NAME
567
568Show the C<buildhost> tag of package C<NAME>.
569
570=cut
571
572sub buildhost : XMLRPC {
573    my ($self, $c, $reqspec, @args) = @_;
574
575    $c->forward('qf', [ $reqspec, @args, '%{buildhost}' ]);
576}
577
578=head2 host NAME
579
580Is an alias for C<buildhost> command.
581
582=cut
583
584sub host : XMLRPC {
585    my ($self, $c, $reqspec, @args) = @_;
586
587    $c->forward('host', [ $reqspec, @args ]);
588}
589
590=head2 h NAME
591
592Is an alias for C<buildhost> command.
593
594=cut
595
596sub h : XMLRPC {
597    my ($self, $c, $reqspec, @args) = @_;
598
599    $c->forward('host', [ $reqspec, @args ]);
600}
601
602
603
604=head2 distribution NAME
605
606Show the C<distribution> tag of package C<NAME>.
607
608=cut
609
610sub distribution : XMLRPC {
611    my ($self, $c, $reqspec, @args) = @_;
612
613    $c->forward('qf', [ $reqspec, @args, '%{distribution}' ]);
614}
615
616=head2 distrib NAME
617
618Is an alias for C<distribution> command.
619
620=cut
621
622sub distrib : XMLRPC {
623    my ($self, $c, $reqspec, @args) = @_;
624
625    $c->forward('distribution', [ $reqspec, @args ]);
626}
627
628
629
630=head2 vendor NAME
631
632Show the C<vendor> tag of package C<NAME>.
633
634=cut
635
636sub vendor : XMLRPC {
637    my ($self, $c, $reqspec, @args) = @_;
638
639    $c->forward('qf', [ $reqspec, @args, '%{vendor}' ]);
640}
641
642
643
644sub qf : XMLRPC {
645    my ($self, $c, $reqspec, @args) = @_;
646    my @message;
647    $reqspec->{src} = 0;
648
649    @args = @{ $c->forward('_getopt', [
650        {
651            'd=s' => \$reqspec->{distribution},
652            'v=s' => \$reqspec->{release},
653            'a=s' => \$reqspec->{arch},
654            's'   => sub { $reqspec->{src} = 1 },
655        }, @args ]) };
656
657    @args == 2 or do {
658        $c->error('No argument given');
659        return;
660    };
661
662    if (!$c->forward('/distrib/exists', [ $reqspec ])) {
663        return $c->stash->{xmlrpc} = {
664            message => [ "I don't have such distribution" ]
665        };
666    }
667
668    my $rpmlist = $c->forward('/search/rpm/byname', [ $reqspec, $args[0] ]);
669    if (!@{ $rpmlist }) {
670        my $else = $c->forward('_find_rpm_elsewhere', [ $reqspec, $args[0] ]);
671        if ($else) {
672            return $c->stash->{xmlrpc} = {
673                message => [ 
674                    "There is no rpm named `$args[0]', but the word matches in " . $else
675                ],
676            }
677        } else {
678            return $c->stash->{xmlrpc} = {
679                message => [ "The rpm named `$args[0]' has not been found" ],
680            }
681        }
682    }
683    foreach (@{ $rpmlist }) {
684        my $info = $c->forward('/rpms/queryformat', [ $_, $args[1] ]);
685        push @message, $info . ' // ' .
686            $c->forward('_fmt_location', [ $reqspec, $_ ]);
687    }
688    return $c->stash->{xmlrpc} = {
689        message => \@message,
690    }
691}
692
693=head2 more NAME
694
695Show url where details about package named C<NAME> can be found
696
697=cut
698
699sub more : XMLRPC {
700    my ($self, $c, $reqspec, @args) = @_;
701    my @message;
702    $reqspec->{src} = 0;
703
704    @args = @{ $c->forward('_getopt', [
705        {
706            'd=s' => \$reqspec->{distribution},
707            'v=s' => \$reqspec->{release},
708            'a=s' => \$reqspec->{arch},
709            's'   => sub { $reqspec->{src} = 1 },
710        }, @args ]) };
711
712    if (!$c->forward('/distrib/exists', [ $reqspec ])) {
713        return $c->stash->{xmlrpc} = {
714            message => [ "I don't have such distribution" ]
715        };
716    }
717
718    my $rpmlist = $c->forward('/search/rpm/byname', [ $reqspec, $args[0] ]);
719    if (!@{ $rpmlist }) {
720        my $else = $c->forward('_find_rpm_elsewhere', [ $reqspec, $args[0] ]);
721        if ($else) {
722            return $c->stash->{xmlrpc} = {
723                message => [ 
724                    "There is no rpm named `$args[0]', but the word matches in " . $else
725                ],
726            }
727        } else {
728            return $c->stash->{xmlrpc} = {
729                message => [ "The rpm named `$args[0]' has not been found" ],
730            }
731        }
732    }
733    foreach (@{ $rpmlist }) {
734        push @message, $c->uri_for('/rpms', $_) . ' // ' .
735            $c->forward('_fmt_location', [ $reqspec, $_ ]);
736    }
737    return $c->stash->{xmlrpc} = {
738        message => \@message,
739    }
740}
741
742=head2 buildfrom NAME
743
744Return the list of package build from source package named C<NAME>
745
746=cut
747
748sub buildfrom : XMLRPC {
749    my ($self, $c, $reqspec, @args) = @_;
750    $reqspec->{src} = 1;
751    my @message;
752    @args = @{ $c->forward('_getopt', [
753        {
754            'd=s' => \$reqspec->{distribution},
755            'v=s' => \$reqspec->{release},
756            'a=s' => \$reqspec->{arch},
757        }, @args ]) };
758    if (!$c->forward('/distrib/exists', [ $reqspec ])) {
759        return $c->stash->{xmlrpc} = {
760            message => [ "I don't have such distribution" ]
761        };
762    }
763    my $rpmlist = $c->forward('/search/rpm/byname', [ $reqspec, $args[0] ]);
764    if (!@{ $rpmlist }) {
765        my $else = $c->forward('_find_rpm_elsewhere', [ $reqspec, $args[0] ]);
766        if ($else) {
767            return $c->stash->{xmlrpc} = {
768                message => [ 
769                    "There is no rpm named `$args[0]', but the word matches in " . $else
770                ],
771            }
772        } else {
773            return $c->stash->{xmlrpc} = {
774                message => [ "The rpm named `$args[0]' has not been found" ],
775            }
776        }
777    }
778    foreach (@{ $rpmlist }) {
779        my $res = $c->forward('/rpms/binaries', [ $_ ]);
780        my @name;
781        foreach (@$res) {
782            push(@name, $c->forward('/rpms/basicinfo', [ $_ ])->{name});
783        }
784        push(@message, join(', ', sort @name));
785    }
786    return $c->stash->{xmlrpc} = {
787        message => \@message,
788    }
789
790}
791
792=head2 findfile FILE
793
794Return the rpm owning the file C<FILE>.
795
796=cut
797
798sub findfile : XMLRPC {
799    my ($self, $c, $reqspec, @args) = @_;
800
801    my @message;
802    $reqspec->{src} = 0;
803
804    @args = @{ $c->forward('_getopt', [
805        {
806            'd=s' => \$reqspec->{distribution},
807            'v=s' => \$reqspec->{release},
808            'a=s' => \$reqspec->{arch},
809        }, @args ]) };
810
811    if (!$c->forward('/distrib/exists', [ $reqspec ])) {
812        return $c->stash->{xmlrpc} = {
813            message => [ "I don't have such distribution" ]
814        };
815    }
816
817    my $rpmlist = $c->forward('/search/rpm/byfile', [ $reqspec, $args[0] ]);
818    if (!@{ $rpmlist }) {
819        return $c->stash->{xmlrpc} = {
820            message => [ "Sorry, no file $args[0] found" ],
821        }
822    } elsif (@{ $rpmlist } > 20) {
823        foreach (@{ $rpmlist }) {
824            my $info = $c->forward('/rpms/basicinfo', [ $_ ]);
825            push @message, $info->{name} . ' // ' .
826                $c->forward('_fmt_location', [ $reqspec, $_ ]);
827        }
828        return $c->stash->{xmlrpc} = {
829            message => \@message,
830        }
831    } else {
832        my %list;
833        foreach (@{ $rpmlist }) {
834            my $info = $c->forward('/rpms/basicinfo', [ $_ ]);
835            $list{$info->{name}} = 1;
836        }
837        return $c->stash->{xmlrpc} = {
838            message => [ join(', ', sort keys %list) ],
839        };
840    }
841}
842
843sub what : XMLRPC {
844    my ($self, $c, $reqspec, @args) = @_;
845       
846    @args = @{ $c->forward('_getopt', [
847        {
848            'd=s' => \$reqspec->{distribution},
849            'v=s' => \$reqspec->{release},
850            'a=s' => \$reqspec->{arch},
851            's'   => \$reqspec->{src},
852        }, @args ]) };
853
854    my ($type, $depname, $sense, $evr) = @args;
855
856    my $deptype = uc(substr($type, 0, 1));
857    my $rpmlist = $c->forward('/search/rpm/bydep',
858        [ $reqspec, $deptype, $depname, $sense, $evr ]);
859
860    if (@{ $rpmlist } < 20) {
861        my @name;
862        foreach (@{ $rpmlist }) {
863            my $info = $c->forward('/rpms/basicinfo', [ $_ ]);
864            push @name, $info->{name} . '-' . $info->{evr};
865        }
866        return $c->stash->{xmlrpc} = {
867            message => [
868                "Package matching $depname" . ($evr ? " $sense $evr" : '') .
869                ':', 
870                join(' ', @name),
871            ],
872        }
873    } else {
874        return $c->stash->{xmlrpc} = {
875            message => [ 'Too many result' ],
876        };
877    }
878
879}
880
881=head2 maint RPMNAME
882
883Show the maintainers for the rpm named C<RPMNAME>.
884
885=cut
886
887sub maint : XMLRPC {
888    my ($self, $c, $reqspec, @args) = @_;
889    $reqspec->{src} = 0;
890    my @message;
891    @args = @{ $c->forward('_getopt', [
892        {
893            'd=s' => \$reqspec->{distribution},
894            'v=s' => \$reqspec->{release},
895            'a=s' => \$reqspec->{arch},
896        }, @args ]) };
897    if (!$c->forward('/distrib/exists', [ $reqspec ])) {
898        return $c->stash->{xmlrpc} = {
899            message => [ "I don't have such distribution" ]
900        };
901    }
902    my $rpmlist = $c->forward('/search/rpm/byname', [ $reqspec, $args[0] ]);
903    if (!@{ $rpmlist }) {
904        my $else = $c->forward('_find_rpm_elsewhere', [ $reqspec, $args[0] ]);
905        if ($else) {
906            return $c->stash->{xmlrpc} = {
907                message => [ 
908                    "There is no rpm named `$args[0]', but the word matches in " . $else
909                ],
910            }
911        } else {
912            return $c->stash->{xmlrpc} = {
913                message => [ "The rpm named `$args[0]' has not been found" ],
914            }
915        }
916    }
917    my %maint;
918    foreach (@{ $rpmlist }) {
919        my $res = $c->forward('/rpms/maintainers', [ $_ ]);
920        foreach (@$res) {
921            my $m = 'For ' . $_->{vendor} . ': ' . $_->{owner};
922            $maint{$m} = 1;
923        }
924    }
925    return $c->stash->{xmlrpc} = {
926        message => [ sort keys %maint ],
927    }
928}
929
930=head1 AUTHOR
931
932Olivier Thauvin
933
934=head1 LICENSE
935
936This library is free software. You can redistribute it and/or modify
937it under the same terms as Perl itself.
938
939=cut
940
941__PACKAGE__->meta->make_immutable;
942
9431;
Note: See TracBrowser for help on using the repository browser.