From 57ce115d84224fe8dd75f19490f788fe8acf198c Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Sat, 11 Aug 2007 16:25:18 +0000 Subject: - urpmi o handle preferred choices (through --prefer, /etc/urpmi/prefer.list and /etc/urpmi/prefer.vendor.list) --- urpm/args.pm | 3 ++- urpm/select.pm | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) (limited to 'urpm') diff --git a/urpm/args.pm b/urpm/args.pm index 80419d78..efe0349e 100644 --- a/urpm/args.pm +++ b/urpm/args.pm @@ -133,6 +133,7 @@ my %options_spec = ( 'norebuild!' => sub { $urpm->{options}{'build-hdlist-on-error'} = !$_[1] }, 'test!' => \$::test, 'skip=s' => \$options{skip}, + 'prefer=s' => \$options{prefer}, 'root=s' => sub { require File::Spec; $urpm->{root} = File::Spec->rel2abs($_[1]); @@ -359,7 +360,7 @@ foreach my $k ("help|h", "version", "no-locales", "test!", "force", "root=s", "u { $options_spec{urpme}{$k} = $options_spec{urpmi}{$k}; } -foreach my $k ("root=s", "nolock", "use-distrib=s", "skip=s") +foreach my $k ("root=s", "nolock", "use-distrib=s", "skip=s", "prefer=s") { $options_spec{urpmq}{$k} = $options_spec{urpmi}{$k}; } diff --git a/urpm/select.pm b/urpm/select.pm index 7544e83b..978f88bb 100644 --- a/urpm/select.pm +++ b/urpm/select.pm @@ -4,6 +4,7 @@ package urpm::select; use urpm::msg; use urpm::util; +use urpm::sys; use URPM; sub _findindeps { @@ -248,6 +249,38 @@ sub resolve_dependencies { $need_restart; } +sub cooked_prefer { + my ($urpm, $cmdline_prefer) = @_; + + $urpm->{prefer_regexps} ||= [ + map { + m!^/(.*)/$! ? "($1)" : '^' . quotemeta($_) . '$'; + } map { @$_ } + urpm::sys::get_packages_list($urpm->{prefer_list}, $cmdline_prefer), + urpm::sys::get_packages_list($urpm->{prefer_vendor_list}) + ]; + @{$urpm->{prefer_regexps}}; +} + +sub sort_choices { + my ($urpm, $choices, $cmdline_prefer) = @_; + + my @prefer; + my @l = @$choices; + foreach my $re (cooked_prefer($urpm, $cmdline_prefer)) { + my ($prefer, $other) = partition { $_->name =~ $re } @l; + push @prefer, @$prefer; + @l = @$other; + + if (@$prefer) { + my $prefer_s = join(',', map { $_->name } @$prefer); + my $other_s = join(',', map { $_->name } @l); + $urpm->{log}("preferring $prefer_s over $other_s"); + } + } + (@prefer, @l); +} + #- find packages to remove. #- options: #- bundle -- cgit v1.2.1