#!/usr/bin/perl # Portage Inventory - Pulls data about ebuilds from the portage database # and prints it in CSV form # Copyright (C) 2005 Nikolas 'Atrus' Coukouma # # 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. # # 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. # You can fiddle with some of the variables below to get the # information you need sub package_licenses { # See manpage of esearch for details my $format = "%n\\t%d\\t%h\\t0\\t??\\t%l\\t??"; my $query_cmd ="esearch -nF --own=\"$format\""; #my $query_cmd ="emerge --search "; #preprocess name for query_cmd my $pkg_match = '^([\\w-]*/[\\w\\d-]*?)-[\\d\\.\\w]+(?:-r\\d+)?$'; my $output; for my $pkg ( @_ ) { $pkg =~ m/$pkg_match/; #print " $pkg\n"; $pkg = $1; $output = `$query_cmd $pkg`; #print " $query_cmd $pkg\n"; @lines = split( /\n/, $output ); #only print the first result print $lines[ 0 ] . "\n"; } } sub get_world_list () { my $ebuild_regex ="\\[ebuild.......\\] ([\\w\\/\\.\\d-]*)"; #my $list_cmd = "emerge -p world"; my $list_cmd = "emerge -p --emptytree world"; my @ebuilds = (); my $output = `$list_cmd`; foreach my $line (split "\n", $output) { push( @ebuilds, $1 ) if $line =~ m/$ebuild_regex/; } return @ebuilds; } package_licenses( get_world_list() );