#!/usr/bin/perl #- Copyright (C) 2000 MandrakeSoft (fpons@mandrakesoft.com) #- #- 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. #- this program is based upon urpmi. #use strict qw(subs vars refs); use urpm; #- default options. my $query = {}; my @files; my @names; my %I18N; load_po(); sub usage { die(_("usage: urpmq [-h] [-d] [-u] [-g] [-v] [-r] package_name|rpm_file [package_names|rpm_files...]\n")); } #- parse arguments list. my @nextargv; for (@ARGV) { /^--help$/ and do { usage; next }; /^-(.*)$/ and do { foreach (split //, $1) { /[\?h]/ and do { usage; next }; /d/ and do { $query->{deps} = 1; next }; /u/ and do { $query->{upgrade} = 1; next }; /g/ and do { $query->{group} = 1; next }; /v/ and do { $query->{version} = 1; next }; /r/ and do { $query->{release} = 1; next }; die "urpmq: unknown option \"-$1\", check usage with --help\n"; } next }; @nextargv and do { my $r = shift @nextargv; $r and $$r = $_; next }; /\.rpm$/ and do { -r $_ or print STDERR "urpmq: cannot read rpm file \"$_\"\n", next; push @files, $_; next }; push @names, $_; } #- params contains informations to parse installed system. my $urpm = new urpm; $urpm->read_depslist; $query && $query->{group} and $urpm->read_compss; if (@files) { #- read provides file which is needed only to compute incremental #- dependancies, of files provided. $urpm->read_provides; #- compute depslist of files provided on command line. $urpm->{params}->read_rpms($_) foreach @files; $urpm->{params}->compute_depslist; #- gets full names of packages, sanity check of pathname. m|(.*/)?(.*)\.[^.]+\.rpm$| and push @names, $2 foreach @files; m|^/| or $_ = "./$_" foreach @files; } #- reparse whole internal depslist to match against newer packages only. $urpm->{params}->relocate_depslist(); #- search the packages according the selection given by the user, #- basesystem is added to the list so if it need to be upgraded, all its dependancy #- will be updated too. my %packages; $urpm->search_packages(\%packages, [ @names ], all => $all) or $force or exit 1; #- filter to add in packages selected required packages. $query->{deps} && !$query->{upgrade} and $urpm->compute_closure(\%packages); $query->{upgrade} and $urpm->filter_packages_to_upgrade(\%packages); #- query of dependancies will make use of packages_to_install, else just #- need to use @names where all informations are given, with eventual #- limitation on packages already installed. my $l = $query->{deps} ? \%packages : \%packages; #- print sub for query. my $query_sub = sub { my ($id) = @_; my $info = $urpm->{params}{depslist}[$id]; my $str = ''; $query->{group} and $str .= $info->{group} . '/'; $str .= $info->{name}; $query->{version} and $str .= '-' . $info->{version}; $query->{release} and $str .= '-' . $info->{release}; $str; }; my %hack_only_one; foreach my $id (keys %$l) { my $class = $l->{$id}; if (ref $class) { foreach my $choices (@{$class || []}) { exists $hack_only_one{$choices} and next; print join('|', map { $query_sub->($_) } @$choices), "\n"; $hack_only_one{$choices} = undef; } } else { exists $l->{$id} and print $query_sub->($id), "\n"; } } sub _ { my $s = shift @_; my $t = translate($s); $t && ref $t or return sprintf $t, @_; my ($T, @p) = @$t; sprintf $T, @_[@p]; } sub translate { $I18N{$_[0]} || $_[0]; } sub load_po { my ($from, $to, $state, $fuzzy); my $lang = $ENV{LANGUAGE} || $ENV{LC_ALL} || $ENV{LC_MESSAGES} || $ENV{LANG}; my $f; -e ($f = "/usr/share/locale/$_/LC_MESSAGES/urpmi.po") and last foreach split ':', $lang; local *F; open F, $f or return; foreach () { /^msgstr/ and $state = 1; /^msgid/ && !$fuzzy and $state = 2; if (/^(#|$)/ && $state != 3) { $state = 3; s/\\n/\n/g foreach $from, $to; if (my @l = $to =~ /%(\d+)\$/g) { $to =~ s/%(\d+)\$/%/g; $to = [ $to, map { $_ - 1 } @l ]; } $I18N{$from} = $to if $from; $from = $to = ''; } $to .= (/"(.*)"/)[0] if $state == 1; $from .= (/"(.*)"/)[0] if $state == 2; $fuzzy = /^#, fuzzy/; } }