#!/usr/bin/env ruby # # Fast RevDep Lookup for portage/sqlite # V1.0 # # -- Kent Fredric require 'rubygems' require 'sqlite3' # DEPEND tokenizer # Breaks each seperate atom down def splitX( i ) arry=[] items=0 tokes=i.split(" ") tokes.length.times{ |n| thistoke=tokes[n] if thistoke.match( /^\|\|/) or thistoke.match( /\?$/ ) # Glob to the closing bracket i=n+1 #jump to the ( following blah? depth=1 while( depth > 0 ) i=i+1 if tokes[i].match(/\(/) depth=depth+1 end if tokes[i].match(/\)/) depth=depth-1 end end output=tokes[n..i].join(" ") tokes[n]=output ((n+1)..i).each{ |x| tokes[x]="" } end } tokes.delete_if{ |x| x==""} return tokes end pkg=ARGV[0] db=SQLite3::Database.new( "/var/cache/edb/dep/usr/portage.sqlite" ) db.execute( "select portage_package_key,DEPEND,RDEPEND,PDEPEND FROM portage_packages WHERE DEPEND GLOB '*#{pkg}*' OR RDEPEND GLOB '*#{pkg}*' OR PDEPEND GLOB '*#{pkg}*'") do |row| pname=row[0] print pname print "\n" deps={} deps[:PDEPEND]=[] deps[:RDEPEND]=[] deps[:DEPEND]=[] splitX(row[1]).each{ |x| if x.match(pkg) deps[:DEPEND] << x end } splitX(row[2]).each{ |x| if x.match(pkg) deps[:RDEPEND] << x end } splitX(row[3]).each{ |x| if x.match(pkg) deps[:PDEPEND] << x end } if deps[:DEPEND].length > 0 print "DEPEND = " print deps[:DEPEND].join(" , ") print "\n" end if deps[:RDEPEND].length > 0 print "RDEPEND = " print deps[:RDEPEND].join(" , ") print "\n" end if deps[:PDEPEND].length > 0 print "PDEPEND = " print deps[:PDEPEND].join(" , ") print "\n" end puts "\n" end db.close