Skip to content

Instantly share code, notes, and snippets.

@kentfredric
Created January 28, 2017 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kentfredric/59c23360307331c593d2d66fe307e332 to your computer and use it in GitHub Desktop.
Save kentfredric/59c23360307331c593d2d66fe307e332 to your computer and use it in GitHub Desktop.
whatevers + Gentoo Revdep magic
http://gentoo-en.vfose.ru/wiki/Portage_SQLite_Cache
read -r -d '' config <<'EOF'
[DEFAULT]
main-repo = gentoo
[gentoo]
location = /usr/local/gentoo
sync-type = git
sync-url = git+ssh://git@git.gentoo.org/repo/gentoo.git
EOF
egencache --repositories-configuration="$config" --repo gentoo -j 10 --update
use strict;
use warnings;
use DBD::SQLite;
use DBI;
my $dbh = DBI->connect("dbi:SQLite:dbname=/var/cache/edb/dep/usr/local/gentoo.sqlite","","", {
RaiseError => 1
});
my @keywords = (
# "arm64",
"mips",
);
#@keywords = ();
#push @keywords, "amd64";
my @bindvars;
my $keyword_construct = join q[ OR ], map { " KEYWORDS LIKE ? " } @keywords;
push @bindvars, map { "%$_%" } @keywords;
if ( @keywords ) {
$keyword_construct = "( $keyword_construct ) AND "
}
my $sth = $dbh->prepare("SELECT * FROM portage_packages WHERE
$keyword_construct (
DEPEND LIKE ?
OR
HDEPEND LIKE ?
OR
PDEPEND LIKE ?
OR
RDEPEND LIKE ?
)
");
my $atom = $ARGV[0];
$sth->execute(@bindvars, "%$atom%", "%$atom%", "%$atom%", "%$atom%");
use Data::Dump qw(pp);
while ( my $rc = $sth->fetchrow_hashref ) {
my @lines;
push @lines, sprintf "%20s: %s", "KEYWORDS", matched_keywords($rc) if @keywords;
push @lines, sprintf "%20s: %s", "DEPS IN PHASES", matched_phases($rc);
push @lines, sprintf "%20s: %s", "DEPSTRINGS", matched_atoms($rc);
printf "%s\n %s\n\n", $rc->{portage_package_key}, join qq[\n ], @lines;
}
sub matched_keywords {
my ($rec) = @_;
my @fields = split / /, $rec->{KEYWORDS};
my @matched_fields;
fields: for my $f (@fields) {
for my $k ( @keywords ) {
if ( $f =~ /\Q$k\E/ ) {
push @matched_fields, $f;
next fields;
}
}
}
return join q[ ], @matched_fields;
}
sub matched_phases {
my ($rec) = @_;
my @matched_fields;
for my $field ( qw( DEPEND HDEPEND PDEPEND RDEPEND )) {
push @matched_fields, $field if $rec->{$field} =~ /\Q$atom\E/;
}
return join q[,], @matched_fields;
}
sub matched_atoms {
my ($rec) = @_;
my @fields;
push @fields, split / /, $rec->{$_} for qw( DEPEND HDEPEND PDEPEND RDEPEND );
my %matched_fields;
fields: for my $f (@fields) {
next if exists $matched_fields{$f};
if ( $f =~ /\Q$atom\E/ ) {
$matched_fields{$f}++;
next fields;
}
}
return join q[ ], sort keys %matched_fields;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment