Changeset 159


Ignore:
Timestamp:
12/21/10 03:51:17 (13 years ago)
Author:
nanardon
Message:
  • add Chat/findfile()
Location:
server/trunk/web
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • server/trunk/web/lib/Sophie/Controller/Chat/Cmd.pm

    r155 r159  
    512512} 
    513513 
     514=head2 findfile 
     515 
     516=cut 
     517 
     518sub findfile : XMLRPC { 
     519    my ($self, $c, $reqspec, @args) = @_; 
     520 
     521    my @message; 
     522    $reqspec->{src} = 0; 
     523 
     524    @args = @{ $c->forward('_getopt', [ 
     525        { 
     526            'd=s' => \$reqspec->{distribution}, 
     527            'v=s' => \$reqspec->{release}, 
     528            'a=s' => \$reqspec->{arch}, 
     529        }, @args ]) }; 
     530 
     531    if (!$c->forward('/distrib/exists', [ $reqspec ])) { 
     532        return $c->stash->{xmlrpc} = { 
     533            message => [ "I don't have such distribution" ] 
     534        }; 
     535    } 
     536 
     537    my $rpmlist = $c->forward('/search/rpm/byfile', [ $reqspec, $args[0] ]); 
     538    if (!@{ $rpmlist }) { 
     539        return $c->stash->{xmlrpc} = { 
     540            message => [ "Sorry, no file $args[0] found" ], 
     541        } 
     542    } elsif (@{ $rpmlist } > 20) { 
     543        foreach (@{ $rpmlist }) { 
     544            my $info = $c->forward('/rpms/basicinfo', [ $_ ]); 
     545            push @message, $info->{name} . ' // ' . 
     546                $c->forward('_fmt_location', [ $reqspec, $_ ]); 
     547        } 
     548        return $c->stash->{xmlrpc} = { 
     549            message => \@message, 
     550        } 
     551    } else { 
     552        my %list; 
     553        foreach (@{ $rpmlist }) { 
     554            my $info = $c->forward('/rpms/basicinfo', [ $_ ]); 
     555            $list{$info->{name}} = 1; 
     556        } 
     557        return $c->stash->{xmlrpc} = { 
     558            message => [ join(', ', sort keys %list) ], 
     559        }; 
     560    } 
     561} 
     562 
    514563=head1 AUTHOR 
    515564 
  • server/trunk/web/t/controller_Chat-Cmd.t

    r158 r159  
    1515} 
    1616 
     17ok( xmlrequest_ok("chat.cmd.findfile", {}, "/bin/rpm"), 
     18    "XML::RPC chat.cmd.findfile" 
     19); 
     20 
    1721done_testing(); 
Note: See TracChangeset for help on using the changeset viewer.