Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 9745 Details for
Bug 17952
Unmask script to merge packages.mask with portdir_overlay version
Home
|
New
–
[Ex]
|
Browse
|
Search
|
Privacy Policy
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
Updated unmask script
unmask (text/plain), 6.06 KB, created by
Jason Rhinelander
on 2003-03-23 22:45:48 UTC
(
hide
)
Description:
Updated unmask script
Filename:
MIME Type:
Creator:
Jason Rhinelander
Created:
2003-03-23 22:45:48 UTC
Size:
6.06 KB
patch
obsolete
>#!/usr/bin/perl > >BEGIN { $> and exec("sudo $0") || die "You are not root, and sudo is not installed\n" } > >use v5.6.0; >use strict; > >use constant OP => 0; # Perl-5.8 allows: >use constant VERSION => 1; # use constant { OP => 0, VERSION => 1, ... } >use constant UNMASK => 2; >use constant NAME => 3; >use constant MATCH => 4; > >my $portdir = `/usr/lib/portage/bin/portageq portdir`; >my $portdir_overlay = `/usr/lib/portage/bin/portageq portdir_overlay`; >chomp($portdir, $portdir_overlay); > >my $Local_Mask_Path = "$portdir_overlay/profiles/package.mask"; >my $Real_Mask_Path = "$portdir/profiles/package.mask"; > >unless ($portdir_overlay and -f $Local_Mask_Path) { > die <<ERROR; >Unable to locate your local package.mask file. Ensure that you have enabled >PORTDIR_OVERLAY in /etc/make.conf, and created a profiles/package.mask file in >that directory. >ERROR >} >unless ($portdir and -f $Real_Mask_Path) { > die "Unable to locate your package.mask file. An `emerge rsync' may help.\n"; >} > >my $pkgs = get_local_packages(); >update_real_packages($pkgs); >append_leftover($pkgs); > >sub update_real_packages { > my $pkgs = shift; > local ($^I, @ARGV) = ('', $Real_Mask_Path); > while (<>) { > my $cp = $_; > # Strip out comments and whitespace > $cp =~ s/#.*//; > $cp =~ s/\s+//g; > > unless (length $cp) { > # If there's nothing left on the line after removing > # comments/spaces, skip it > print; > next; > } > my ($version, $op, $name) = parse_package($cp); > > for my $p (@$pkgs) { > next unless $p->[NAME] eq $name; > if ($_ eq "$p->[OP]$p->[NAME]-$p->[VERSION]\n" and not $p->[UNMASK]) { > # If the line we find is identical to one of the local lines, > # mark the local one as matched. > $p->[MATCH]++; > next; > } > my $cmp = versioncmp($version, $p->[VERSION]); > if (inrange($op, $p->[OP], $cmp)) { > # In this case, a line in the base file is matched by a local one > $p->[MATCH]++; > if ($p->[UNMASK]) { > print STDOUT "Unmasking $_"; > print "# Unmasked by $0\n"; > $_ = "#$_"; > } > else { > print STDOUT "Masking $p->[OP]$p->[NAME]-$p->[VERSION]\n"; > print "# Masked by $0\n"; > $_ = "$p->[OP]$p->[NAME]-$p->[VERSION]\n"; > } > last; > } > } > # Print the line back to the file, unless it looks like a comment that > # this program would have added > print $_ unless /# (?:Masked|Unmasked) by $0/; > } >} > >sub append_leftover { > my $pkgs = shift; > open my $fh, ">>", $Real_Mask_Path > or die "Could not open $Real_Mask_Path: $!"; > for (@$pkgs) { > if (!$_->[MATCH] and !$_->[UNMASK]) { > # Any remaining lines that weren't matched are added at the end > print STDOUT "Masking $_->[OP]$_->[NAME]-$_->[VERSION]\n"; > print $fh "# Masked by $0\n$_->[OP]$_->[NAME]-$_->[VERSION]\n"; > } > } > close $fh; >} > >sub parse_package { > my $pkg = shift; > my ($version, $cmp); > # Look for the comparison ('>=' in >=foo/bar-1.3) > if ($pkg =~ s/^!?([<>]=?|=)//) { > $cmp = $1; > } > else { > # A line without comparison/version is treated as >= version 0 > $cmp = '>='; > } > > # Look for the version (e.g. 4.3m-r3 in foo/bar-4.3m-r3) > if ($pkg =~ s/-(\d[-\w.*]*)$//) { > $version = $1; > } > else { > # If no version was found, assume 0 > $version = 0; > } > return ($version, $cmp, $pkg); >} > >sub get_local_packages { > my $pkgs = []; > open my $local_fh, '<', $Local_Mask_Path > or die "Could not open $Local_Mask_Path: $!"; > while (<$local_fh>) { > s/#.*//; > s/\s+//g; > next unless length; > > # Something prefixed by ! means something to unmask > my $unmask = s/^!//; > my ($version, $cmp, $name) = parse_package($_); > > push @$pkgs, [$cmp, $version, $unmask, $name, 0]; > } > close $local_fh; > return $pkgs; >} > >sub inrange { > my ($base, $local, $cmp) = @_; > my $ret = 0; > > if ($cmp == 0) { # Base version == local version > $ret = not ( > ($base eq '>' and $local eq '<') or > ($base eq '<' and $local eq '>') or > ($base eq '=' and $local !~ /=/) > ); > } > elsif ($cmp > 0) { # Base version > local version > $ret = not ( > ($base eq '>' or $base eq '>=') and > ($local eq '<' or $local eq '<=' or $local eq '=') > or > ($base eq '=') and > ($local eq '<' or $local eq '<=') > ); > } > elsif ($cmp < 0) { # Base version < local version > $ret = not ( > ($base eq '<' or $base eq '<=') and > ($local eq '>' or $local eq '>=') > or > ($base eq '=') and > ($local eq '>' or $local eq '>=') > ); > } > return $ret; >} > ># Taken and modified from Sort::Versions >sub versioncmp ($$) { > my @c = ($_[0] =~ /([-.]|\d+|[^-.\d]+)/g); > my @d = ($_[1] =~ /([-.]|\d+|[^-.\d]+)/g); > > my ($star_left, $star_right, $ci, $di); > for ($ci = 0, $di = 0; $ci < @c and $di < @d; $ci++, $di++) { > my $c = $c[$ci]; > my $d = $d[$di]; > if ($c eq '-' and $d eq '-') { next } > elsif ($c eq '-') { return -1 } > elsif ($d eq '-') { return 1 } > elsif ($c eq '.' and $d eq '.') { next } > elsif ($c eq '.') { return -1 } > elsif ($d eq '.') { return 1 } > elsif ($c eq '*' or $d eq '*') { return 0 } > elsif ($c =~ /^\d+$/ and $d =~ /^\d+$/) { > if ($c =~ /^0/ || $d =~ /^0/) { return $c cmp $d if $c cmp $d } > else { return $c <=> $d if $c <=> $d } > } > elsif ($c eq '*') { return 0 if $ci + 1 == @c } > else { $c = uc $c; $d = uc $d; return $c cmp $d if $c cmp $d } > } > @c <=> @d; >}
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 17952
:
9672
|
9673
| 9745