Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 34878 Details for
Bug 56261
simple script for update USE flags
Home
|
New
–
[Ex]
|
Browse
|
Search
|
Privacy Policy
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
useupdate script
useupdate (text/plain), 10.41 KB, created by
Marcin Kryczek (RETIRED)
on 2004-07-06 11:22:21 UTC
(
hide
)
Description:
useupdate script
Filename:
MIME Type:
Creator:
Marcin Kryczek (RETIRED)
Created:
2004-07-06 11:22:21 UTC
Size:
10.41 KB
patch
obsolete
>#!/usr/bin/perl >############################################################################ ># # ># 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 of the License, 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. # ># # ># # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ## ># # ># If you have any questions or comments or just want to write how # ># marvellous (;>) this program is, feel free to mail. # ># # ># Marcin 'aye' Kryczek <aye@gentoo.pl> # ># # >############################################################################ > >use strict; >use POSIX; >use Term::ANSIColor; > >my $version="0.9"; > >my %COLORS = ( > 'blue' => 'bold blue', > 'green' => 'green', > 'yellow'=> 'bold yellow', > 'red' => 'bold red', > 'bold' => 'bold', >); > >my ($change_on, > $change_off, > %local_flags, > @global_flags, > $portdir, > $portdir_overlay, > @categories, > @changes, > $nocolor, > $pretend); > >############################################ ># gets local flags for indyvidual packages # >############################################ >sub get_local_use { > > my ($name, $rest, @flags); > > if (open(FP,"</etc/portage/package.use")) { > while (<FP>) { > s/#.*//; # ommiting comments > chomp; > ($name,$rest) = split / /,$_,2; > if ($name eq "") { next; }; > @flags = split ' ',$rest; > $local_flags{$name} = [ @flags ]; > } > close(FP); > } > return %local_flags; >} > >############################################ ># get enviroment settings # >############################################ > >sub get_env { > > my (@lines); > @lines = `emerge info`; > (*portdir, *portdir_overlay, *global_flags) = @_; > foreach (@lines) { > chomp; > if (/USE=/) { > s/.*"(.*)"/\1/; > @global_flags = split; > }elsif (/PORTDIR=/) { > s/.*"(.*)"/\1/; > $portdir = $_; > }elsif (/PORTDIR_OVERLAY=/) { > s/.*"(.*)"/\1/; > $portdir_overlay = $_; > }; > }; >} > >############################################ ># get category's list # >############################################ > >sub get_categories { > *categories = @_; > opendir(DIR, "/var/db/pkg/") || die "can't open /var/db/pkg/\n"; > @categories=readdir(DIR); > shift @categories; shift @categories; > closedir(DIR); >} > >############################################ ># get packages from one category # >############################################ > >sub get_packages_from_category { > > my $cat = $_; > my @packages; > > opendir(DIR,"/var/db/pkg/$cat") || die "can't open /var/db/pkg/$cat\n"; > @packages=readdir(DIR); > shift @packages; shift @packages; > close(DIR); > return @packages; >} > >########################################### ># get flags from compilation of one pkg # >########################################### > >sub get_compilation_use { > > my ($cat, $package) = @_; > my ($tmp, @my_flags); > > if (not open(FP,"/var/db/pkg/$cat/$package/USE")) { > print colored("WARNING: ",%COLORS->{'red'}); > print "can't get USE for $cat/$package"; > print colored(" (possibly injected)\n",%COLORS->{'red'}); > next; > } > $tmp=<FP>; > chomp $tmp; > @my_flags=split / /,$tmp; > @my_flags=sort @my_flags; > close(FP); > return @my_flags; >} > >############################################# ># compare global and compilation time flags # >############################################# > >sub combine_compilation { > > my ($cat,$package,@global) = @_; > my @compilation_flags = get_compilation_use($cat,$package); > my (@tmp_on, @tmp_off); > until (( $#compilation_flags==-1 ) || ( $#global==-1 )) { > if ($compilation_flags[0]=~/^-/) { > shift @compilation_flags; > next; > }elsif ($compilation_flags[0] lt $global[0]) { > push @tmp_off,shift @compilation_flags; > next; > }elsif ($compilation_flags[0] gt $global[0]) { > push @tmp_on, shift @global; > next; > }else {shift @compilation_flags; shift @global; }; > } > foreach (@compilation_flags) { push @tmp_off,$_;} > foreach (@global) { push @tmp_on,$_;} > $change_on = join(' ',@tmp_on); > $change_off= join(' ',@tmp_off); > return ($change_on, $change_off); >} > >############################################# ># combine global and local flags for pkg # >############################################# > >sub combine_local { > > local *global_flags; > my @local_flags = @_; > my @global = @global_flags; > my ($i, $k); > foreach (@local_flags) { > if (/^-/) { > s/^-//; > for $i (0 .. $#global) { > if ($global[$i] eq $_) { > splice @global,$i,1; > } > } > }else{ > $i=0; > while ($i<=$#global && $global[$i] ne $_) { $i+=1;}; > if ($i>$#global) {push @global,$_; $k=1 }; > } > } > if ($k == 1) { @global=sort @global}; > return @global; >} > >############################################# ># gets name from package # >############################################# > >sub get_name { > > my $ver; > > $ver=$_; > $ver=~ s/.*(\-([0-9]|\.)+((_pre[0-9]+)|(-r[0-9]+)){0,2})/\1/; > s/$ver//; > return $_; >} > >############################################ ># gets IUSE from package # >############################################ > >sub get_iuse { > my ($cat,$name,$package) = @_; > my $iuse; > if (open(FP,"</var/db/pkg/$cat/$package/IUSE")){ > $iuse=<FP>; > chomp $iuse; > close(FP); > }else{ > print colored("WARNING: ",$COLORS{'red'}); > print "can't get IUSE for $cat/$package "; > print colored("(possibly injected)\n",$COLORS{'red'}); > } > return $iuse; >} > >############################################ ># prints what it founds # >############################################ > >sub print_output { > local *changes; > my ($i, @tmp_iuse,@tmp_on,@tmp_off,$command,$answer,$prev); > my $command = "emerge --oneshot"; > print "\n\n"; > if ($#changes < 0) { > print colored(" Nothing to be done\n\n",$COLORS{'bold'}); > }else{ > print colored(" Those packages should be reemerged:\n\n",$COLORS{'bold'}); > foreach (@changes) { > print colored(" * ",%COLORS->{'bold'}); > print colored("$_->{name}",%COLORS->{'green'}); > print colored(": ",%COLORS->{'bold'}); > $command .=" =".$_->{name}; > @tmp_iuse = grep($_ ne $prev &&($prev=$_,1),sort split / /,$_->{iuse}); > @tmp_on = split / /,$_->{change_on}; > @tmp_off = split / /,$_->{change_off}; > foreach (@tmp_iuse) { > if (@tmp_on[0] eq $_) { > print colored("+$_ ",%COLORS->{'yellow'}); > shift @tmp_on; > }elsif (@tmp_off[0] eq $_) { > print colored("-$_ ",%COLORS->{'yellow'}); > shift @tmp_off; > }else{ > $i=0; > while ( $i <= $#global_flags && $_ ne $global_flags[$i]) { > $i+=1; > } > if ($i <= $#global_flags) { > print colored("+$_ ",%COLORS->{'red'}); > }else{ > print colored("-$_ ",%COLORS->{'blue'}); > } > } > } > print "\n"; > } > > print "\n"; > print colored(" Command to execute: ",%COLORS->{'bold'}); > print "$command\n\n"; > if ($pretend != 1) { > exec($command); > } > } >} > >sub print_help { > print colored("UseUpdate v$version\n",%COLORS->{'bold'}); > print ("useupdate is a simple script, which compares USE flags used for compilation with currently set for each installed package\n\n"); > print colored(" Usage: ",%COLORS->{'bold'}); > print "useupdater <options>\n\n"; > print colored(" Options are: \n",%COLORS->{'bold'}); > print colored(" -n, --nocolor: ",%COLORS->{'bold'}); > print "disable colors \n"; > print colored(" -p, --pretend: ",%COLORS->{'bold'}); > print "don't execute emerge\n\n"; > > exit(0); >} > >############################################ ># compares changes with IUSE # >############################################ >sub combine_with_iuse { > my ($change, $iuse) = @_; > > my (@tmp_ch, @tmp_iuse, $i, $j); > @tmp_ch = split / /,$change; > @tmp_iuse=split / /,$iuse; > if ( $#tmp_iuse == -1 ) { > return ""; > }else{ > for ($i=0;$i<=$#tmp_ch;$i+=1) { > $j=0; > while ($j<=$#tmp_iuse && $tmp_iuse[$j] ne $tmp_ch[$i]) { $j+=1}; > if ($j>$#tmp_iuse) { > splice @tmp_ch,$i,1; > $i-=1; > }; > } > return join(' ',@tmp_ch); > } >} >############################################ ># parse arguments # >############################################ > >sub get_opt() { > my $i; > local *pretend, *nocolor; > foreach (@ARGV) { > if (/^-/ and not /^--/) { > for ($i=1;$i<length($_);$i++) { > if ( substr($_,$i,1) eq 'p') { > $pretend=1; > }elsif ( substr($_,$i,1) eq 'n') { > $nocolor=1; > }else {print_help;}; > } > }elsif(/^--/) { > if (substr($_,2,7) eq "pretend") { > $pretend=1; > }elsif (substr($_,2,7) eq "nocolor") { > $nocolor=1; > }else {print_help}; > }else {print_help}; > } >} > >############################################ ># main part # >############################################ >get_opt(); > >if ($nocolor == 1) { > %COLORS = ( > 'blue' => 'white', > 'green' => 'bold', > 'yellow'=> 'bold', > 'red' => 'white', > 'bold' => 'bold', > ); >} > > >%local_flags = get_local_use; >print "\n"; >get_env(\$portdir, \$portdir_overlay, \@global_flags); >get_categories(\@categories); >my ($cat,@packages,$package,$name,$iuse,@global,$tmp); > >foreach (@categories) { > $cat = $_; > @packages = get_packages_from_category; > foreach (@packages) { > $package = $_; > $name=get_name; > $iuse=get_iuse($cat,$name,$package); > if (exists $local_flags{"$cat/$name"}) { > @global=combine_local(@{$local_flags{"$cat/$name"}}); > }else {@global=@global_flags;} > ($change_on, $change_off)=combine_compilation($cat,$package,@global); > $change_on = combine_with_iuse($change_on, $iuse); > $change_off= combine_with_iuse($change_off,$iuse); > if ($change_on ne "" || $change_off ne "") { > $changes[++$#changes]->{name} = "$cat/$package"; > $changes[$#changes]->{iuse} = $iuse; > $changes[$#changes]->{change_on} = $change_on; > $changes[$#changes]->{change_off}= $change_off; > } > } >}; >print_output; >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 56261
: 34878