source: tools/trunk/bin/sophie-rpm @ 411

Last change on this file since 411 was 405, checked in by nanardon, 13 years ago
  • cleanup the mess between tools and bot
File size: 3.4 KB
Line 
1#! /bin/env perl
2
3use strict;
4use warnings;
5use Sophie::Client;
6use Getopt::Long;
7use Pod::Usage;
8use Config::General;
9use File::Temp;
10
11=head1 NAME
12
13    sophie-rpm - Tools to check rpms over Sophie Website
14
15=cut
16
17=head1 SYNOPSYS
18
19    sophie-rpm [-c configfile] [--proxy proxy] RPM1 [RPM2 [...]]
20
21=cut 
22
23my $distrib  = {};
24my $searchsp = {};
25
26=head1 OPTIONS
27
28=over4
29
30=item -c configfile
31
32Use this config instead default one (C<~/.sophie.conf>)
33
34=item --proxy proxy
35
36Use this proxy to connect sophie's web site. The proxy must given as an url
37like C<http://proxy:8080/>
38
39=item -v
40
41Being verbose, show each required packages
42
43=item -s
44
45Search in database package matching unresolved dependencies
46
47=back
48
49=cut
50
51=item HEAD1 config file
52
53The configuration must look like something like this
54
55    # url http://sophie.zarb.org/rpc
56    # proxy http://nanardon.zarb.org:3128/
57    <distrib>
58    distribution Mandriva
59    release 2010.0
60    arch x86_64
61    </distrib>
62    <distrib>
63    distribution Mandriva
64    release cooker
65    arch x86_64
66    </distrib>
67
68=over 4
69
70=item proxy URL
71
72Optionnal proxy to use to connect to sophie website
73
74=item url URL
75
76The url of C<RPC> top method, default is C<http://sophie.zarb.org/rpc>.
77
78=item distrib
79
80The distribution for which rpms must be checked
81
82=over 4
83
84=item distribution
85
86The distribution name
87
88=item release
89
90The release provided by this distribution
91
92=item arch
93
94The architecture for this distribution/release
95
96=back
97
98=item search
99
100Works like distrib but is used to find not found dependencies when C<-s> is
101used.
102
103=back
104
105=cut 
106
107GetOptions(
108    'c=s'   => \my $configfile,
109    'u=s'   => \my $url,
110    'l=s'   => \my $login,
111    'p=s'   => \my $pass,
112    'v'     => \my $verbose,
113    's'     => \my $search,
114    'proxy' => \my $proxy,
115) or pod2usage;
116
117$configfile ||= "$ENV{HOME}/.sophie.conf";
118
119if (-f $configfile && (my $conf = Config::General->new($configfile))) {
120    my %config = $conf->getall;
121    $url         ||= $config{url};
122    $login       ||= $config{login};
123    $pass        ||= $config{pass};
124    $proxy       ||= $config{proxy};
125    $distrib     =   $config{distrib};
126    $searchsp    =   $config{search};
127}
128
129my $sc = Sophie::Client->new(
130    server => $url,
131    login => $login,
132    password => $pass,
133    proxy => $proxy,
134);
135
136$sc->login;
137
138my $ts = $sc->ts($distrib);
139
140foreach my $rpm (@ARGV) {
141    $ts->add_rpm($rpm) or die "Cannot add $rpm";
142}
143
144my $res = $ts->run(
145    verbose => $verbose,
146);
147$ts->summary if (@ARGV > 1);
148print "\nThis transaction would failed\n" if(!$res);
149if ($search) {
150    print "\nSearching depedencies in sophie\n";
151    foreach my $dep (@{ $ts->{unresolved}} ) {
152        my $res = $sc->send_request(
153            'search.rpm.bydep', $searchsp, 'P', split(' ', $dep)
154        );
155        if (ref $res && !$res->is_fault) {
156            print "$dep: " . $res->value->{total_entries} . " results\n";
157            foreach (@{ $res->value->{results} }) {
158                print "    " . $sc->send_request('rpms.basicinfo', $_)->value->{filename};
159                print "\n";
160            }
161        }
162    }
163}
164exit($res ? 0 : 1);
165
166=head1 AUTHOR
167
168Olivier Thauvin C<nanardon@nanardon.zarb.org>
169
170=head1 SEE ALSO
171
172L<http://sophie.zarb.org>
173
174=head1 COPYRIGHT AND LICENSE
175
176Copyright (C) 2010 by Olivier Thauvin
177
178This library is free software; you can redistribute it and/or modify
179it under the same terms as Perl itself, either Perl version 5.12.2 or,
180at your option, any later version of Perl 5 you may have available.
181
182=cut
Note: See TracBrowser for help on using the repository browser.