Changeset 155


Ignore:
Timestamp:
12/21/10 03:27:55 (13 years ago)
Author:
nanardon
Message:
  • the bot report when requested distrib/rpm does not exists
File:
1 edited

Legend:

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

    r148 r155  
    4545    if ($needpaste) { 
    4646        my $id = $c->forward('/chat/paste', [ 'Bot paste', join("\n", @backup) ]); 
    47         push(@{ $message->{message} }, 'All results availlable here: ' . $c->uri_for('/chat', $id)); 
     47        if ($id) { 
     48            push(@{ $message->{message} }, 'All results availlable here: ' . $c->uri_for('/chat', $id)); 
     49        } 
    4850    } 
    4951 
     
    7577 
    7678sub _fmt_location : Private { 
    77     my ($self, $c, $pkgid) = @_; 
     79    my ($self, $c, $searchspec, $pkgid) = @_; 
    7880 
    7981    my @loc; 
     
    8890    } 
    8991    return join(', ', @loc); 
     92} 
     93 
     94sub _find_rpm_elsewhere : Private { 
     95    my ($self, $c, $searchspec, $name) = @_; 
     96    if ($searchspec->{distribution}) { 
     97        my $rpmlist = $c->forward('/search/rpm/byname', [  
     98                { 
     99                    distribution => $searchspec->{distribution}, 
     100                    rows => 1, 
     101                }, $name ]); 
     102        if (@{$rpmlist}) { 
     103            return $c->forward('_fmt_location', [ {  
     104                        distribution => $searchspec->{distribution} 
     105                    }, $rpmlist->[0] ]); 
     106        } 
     107    } 
     108    my $rpmlist = $c->forward('/search/rpm/byname', [ {}, $name ]); 
     109    my %dist; 
     110    foreach(@$rpmlist) { 
     111        foreach (@{ $c->forward('/rpms/location', [ $_ ]) }) { 
     112            $dist{$_->{dist} || $_->{distribution}} = 1; 
     113        } 
     114    } 
     115    if (keys %dist) { 
     116        return join(', ', sort keys %dist); 
     117    } 
     118    return; 
    90119} 
    91120 
     
    154183        }, @args ]) }; 
    155184 
     185    if (!$c->forward('/distrib/exists', [ $reqspec ])) { 
     186        return $c->stash->{xmlrpc} = { 
     187            message => [ "I don't have such distribution" ] 
     188        }; 
     189    } 
     190 
    156191    my $rpmlist = $c->forward('/search/rpm/byname', [ $reqspec, $args[0] ]); 
     192    if (!@{ $rpmlist }) { 
     193        my $else = $c->forward('_find_rpm_elsewhere', [ $reqspec, $args[0] ]); 
     194        if ($else) { 
     195            return $c->stash->{xmlrpc} = { 
     196                message => [  
     197                    "The rpm named `$args[0]' has not been found but found in " . $else 
     198                ], 
     199            } 
     200        } else { 
     201            return $c->stash->{xmlrpc} = { 
     202                message => [ "The rpm named `$args[0]' has not been found" ], 
     203            } 
     204        } 
     205    } 
    157206    foreach (@{ $rpmlist }) { 
    158207        my $info = $c->forward('/rpms/basicinfo', [ $_ ]); 
    159208        push @message, $info->{evr} . ' // ' . 
    160             $c->forward('_fmt_location', [ $_ ]); 
     209            $c->forward('_fmt_location', [ $reqspec, $_ ]); 
    161210    } 
    162211    return $c->stash->{xmlrpc} = { 
     
    333382        }, @args ]) }; 
    334383 
     384    if (!$c->forward('/distrib/exists', [ $reqspec ])) { 
     385        return $c->stash->{xmlrpc} = { 
     386            message => [ "I don't have such distribution" ] 
     387        }; 
     388    } 
     389 
    335390    my $rpmlist = $c->forward('/search/rpm/byname', [ $reqspec, $args[0] ]); 
     391    if (!@{ $rpmlist }) { 
     392        my $else = $c->forward('_find_rpm_elsewhere', [ $reqspec, $args[0] ]); 
     393        if ($else) { 
     394            return $c->stash->{xmlrpc} = { 
     395                message => [  
     396                    "The rpm named `$args[0]' has not been found but found in " . $else 
     397                ], 
     398            } 
     399        } else { 
     400            return $c->stash->{xmlrpc} = { 
     401                message => [ "The rpm named `$args[0]' has not been found" ], 
     402            } 
     403        } 
     404    } 
    336405    foreach (@{ $rpmlist }) { 
    337406        my $info = $c->forward('/rpms/queryformat', [ $_, $args[1] ]); 
    338407        push @message, $info . ' // ' . 
    339             $c->forward('_fmt_location', [ $_ ]); 
     408            $c->forward('_fmt_location', [ $reqspec, $_ ]); 
    340409    } 
    341410    return $c->stash->{xmlrpc} = { 
     
    363432        }, @args ]) }; 
    364433 
     434    if (!$c->forward('/distrib/exists', [ $reqspec ])) { 
     435        return $c->stash->{xmlrpc} = { 
     436            message => [ "I don't have such distribution" ] 
     437        }; 
     438    } 
     439 
    365440    my $rpmlist = $c->forward('/search/rpm/byname', [ $reqspec, $args[0] ]); 
     441    if (!@{ $rpmlist }) { 
     442        my $else = $c->forward('_find_rpm_elsewhere', [ $reqspec, $args[0] ]); 
     443        if ($else) { 
     444            return $c->stash->{xmlrpc} = { 
     445                message => [  
     446                    "The rpm named `$args[0]' has not been found but found in " . $else 
     447                ], 
     448            } 
     449        } else { 
     450            return $c->stash->{xmlrpc} = { 
     451                message => [ "The rpm named `$args[0]' has not been found" ], 
     452            } 
     453        } 
     454    } 
    366455    foreach (@{ $rpmlist }) { 
    367456        push @message, $c->uri_for('/rpms', $_) . ' // ' . 
    368             $c->forward('_fmt_location', [ $_ ]); 
     457            $c->forward('_fmt_location', [ $reqspec, $_ ]); 
    369458    } 
    370459    return $c->stash->{xmlrpc} = { 
     
    389478            'a=s' => \$reqspec->{arch}, 
    390479        }, @args ]) }; 
     480    if (!$c->forward('/distrib/exists', [ $reqspec ])) { 
     481        return $c->stash->{xmlrpc} = { 
     482            message => [ "I don't have such distribution" ] 
     483        }; 
     484    } 
    391485    my $rpmlist = $c->forward('/search/rpm/byname', [ $reqspec, $args[0] ]); 
     486    if (!@{ $rpmlist }) { 
     487        my $else = $c->forward('_find_rpm_elsewhere', [ $reqspec, $args[0] ]); 
     488        if ($else) { 
     489            return $c->stash->{xmlrpc} = { 
     490                message => [  
     491                    "The rpm named `$args[0]' has not been found but found in " . $else 
     492                ], 
     493            } 
     494        } else { 
     495            return $c->stash->{xmlrpc} = { 
     496                message => [ "The rpm named `$args[0]' has not been found" ], 
     497            } 
     498        } 
     499    } 
    392500    foreach (@{ $rpmlist }) { 
    393501        my $res = $c->forward('/rpms/binaries', [ $_ ]); 
Note: See TracChangeset for help on using the changeset viewer.