summaryrefslogtreecommitdiffstats
path: root/urpmf
blob: 1be612fc9516c104c7f8afbdb2106ef6d45fdbbc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/usr/bin/perl

# $Id$

#- Copyright (C) 2002, 2003, 2004, 2005 Mandriva
#-
#- This program is free software; you can redistribute it and/or modify
#- it under the terms of the GNU General Public License as published by
#- the Free Software Foundation; either version 2, or (at your option)
#- any later version.
#-
#- This program is distributed in the hope that it will be useful,
#- but WITHOUT ANY WARRANTY; without even the implied warranty of
#- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#- GNU General Public License for more details.
#-
#- You should have received a copy of the GNU General Public License
#- along with this program; if not, write to the Free Software
#- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

use strict;
use urpm;
use urpm::args;
use urpm::msg;

sub usage {
    print N("urpmf version %s
Copyright (C) 2002-2005 Mandriva.
This is free software and may be redistributed under the terms of the GNU GPL.

usage:
", $urpm::VERSION) . N("  --help         - print this help message
") . N("  --all          - print all tags
") . N("  --arch         - print architecture
") . N("  --buildhost    - print build host
") . N("  --buildtime    - print build time
") . N("  --conffiles    - print configuration files
") . N("  --conflicts    - print conflict tags
") . N("  --distribution - print distribution
") . N("  --description  - print package description
") . N("  --env          - use specific environment (typically a bug report)
") . N("  --epoch        - print epoch
") . N("  --excludemedia - do not use the given media, separated by comma
") . N("  --files        - print the package's files
") . N("  --group        - print group
") . N("  --literal      - don't match patterns, but use argument as a literal string
") . N("  --media        - use only the given media, separated by comma
") . N("  --name         - print only package names
") . N("  --obsoletes    - print obsoletes tags
") . N("  --packager     - print packager
") . N("  --provides     - print provides tags
") . N("  --requires     - print requires tags
") . N("  --size         - print installed size
") . N("  --sortmedia    - sort media according to substrings separated by comma
") . N("  --sourcerpm    - print source rpm name
") . N("  --summary      - print summary
") . N("  --synthesis    - use the synthesis given instead of urpmi db
") . N("  --uniq         - do not print identical lines
") . N("  --update       - use only update media
") . N("  --url          - print url
") . N("  --vendor       - print vendor
") . N("  --verbose      - verbose mode
") . N("  -m             - print the media in which the package was found
") . N("  -i             - ignore case distinctions in every pattern
") . N("  -f             - print version, release and arch with name
") . N("  -e             - include perl code directly as perl -e
") . N("  -a             - binary AND operator, true if both expression are true
") . N("  -o             - binary OR operator, true if one expression is true
") . N("  !              - unary NOT, true if expression is false
") . N("  (              - left parenthesis to open group expression
") . N("  )              - right parenthesis to close group expression
");
    exit(0);
}

#- default options.
our $update = 0;
our $media = '';
our $excludemedia = '';
our $sortmedia = '';
our $synthesis = '';
our $verbose = 0;
our $uniq = '';
our $pattern = ''; # regexp match flags ("i" or "")
our $full = ''; # -f : print rpm fullname instead of rpm name
our $literal = 0; # should we quotemeta the pattern
our $env;
our (%params, %uniq);

#- parse arguments list.
our $expr;
urpm::args::parse_cmdline();

my $urpm = new urpm;
$verbose or $urpm->{log} = sub {};

unless (scalar(grep defined, values %params)) {
    #- nothing on the command-line : default is to search on file names
    $params{files} = 1;
}

#- build the callback matching the expression.
my $callback = 'sub {
    my ($urpm, $pkg) = @_;';
if ($uniq) {
    $uniq = "\n\t" . '$uniq{$_} and next; $uniq{$_} = 1;';
}
#- XXX name and fullname are for later
foreach my $tag (grep { $params{$_} } qw(
    arch
    buildhost
    buildtime
    conf_files
    conflicts
    description
    distribution
    epoch
    filename
    files
    fullname
    group
    media
    name
    obsoletes
    packager
    provides
    requires
    size
    sourcerpm
    summary
    url
    vendor
)) {
    my $fi = $tag eq 'media' ? '$urpm::currentmedia->{name}' : '$pkg->' . $tag;
    $callback .= qq{
    foreach my \$e ($fi) {
	local \$_ = \$pkg->${full}name.":\$e";
	$expr or next;$uniq
	print "\$_\\n";
    }};
}
$callback .= '
    1;
}';
$urpm->{error}(N("callback is:\n%s\n", $callback)) if our $debug;
$callback = eval $callback;
if ($@) {
    $debug and warn "Internal error: $@\n";
    usage;
}

if ($env) {
    print STDERR N("using specific environment on %s\n", $env);
    #- setting new environment.
    $urpm->{config} = "$env/urpmi.cfg";
    $urpm->{skiplist} = "$env/skip.list";
    $urpm->{instlist} = "$env/inst.list";
    $urpm->{statedir} = $env;
}

{
    #- lock to avoid concurrent media updates,
    #- but don't die if it doesn't work
    local $urpm->{fatal} = sub { printf STDERR "%s\n", $_[0] };
    $urpm->shlock_urpmi_db;
}
my $use_hdlist = scalar grep { $params{$_} } qw(
    buildhost
    buildtime
    conf_files
    description
    distribution
    files
    packager
    sourcerpm
    url
    vendor
);
$urpm->configure(
    nocheck_access => 1,
    noskipping => 1,
    media => $media,
    excludemedia => $excludemedia,
    sortmedia => $sortmedia,
    synthesis => $synthesis,
    update => $update,
    callback => $callback,
    call_back_only_once => 1,
    hdlist => $use_hdlist,
);
$urpm->unlock_urpmi_db;

if ($use_hdlist) {
    # @hdmedia is the list of all media searched that use hdlists
    my @hdmedia = grep {
	!$_->{synthesis} && !$_->{removable} && !$_->{ignore};
    } @{ $urpm->{media} };
    if (!@hdmedia) {
	print N("Note: since no media searched uses hdlists, urpmf was unable to return any result\n");
	print N("You may want to use --name to search for package names.\n") if !$params{filename};
    }
}