5 # Look through a provided database to find which CD/DVD image(s)
6 # contain a specified Debian package or source file.
8 # Copyright (c) 2011 Steve McIntyre <93sam@debian.org>
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
27 my $dbdir = "/home/steve/debian/debian-cd/search/search-db";
35 # Borrowed from Ikiwiki.pm
37 my $re=quotemeta(shift);
43 chdir($dbdir) || die "Failed to cd to $dbdir: $!\n";
44 opendir(my $dh, ".") || die "Failed to open $dbdir: $!\n";
45 while (defined($_ = readdir($dh))) {
46 m/(.*)\.db$/ and push (@AREAS, $1);
50 my $query_term = shift;
52 if (!defined($query_term) || !length($query_term)) {
53 die "No query term specified!\n";
57 my $re_search = glob2re($query_term);
59 foreach my $area (@AREAS) {
60 print "Looking in area $area\n";
61 my $db_file_name = "$dbdir/$area.db";
62 dbmopen(%fileinfo, "$db_file_name", 0000) ||
63 die "Failed to open db file: $!\n";
65 if ($query_term =~ /[\*\?]/) {
66 # Will need to search through all the keys to allow for glob
67 foreach my $file (keys %fileinfo) {
68 if ($file =~ $re_search) {
70 push(@results, "$file $fileinfo{$file}");
71 if ($count >= $max_count) {
77 # We've been given an exact name - do the exact key lookup \o/
78 push (@results, "$query_term $fileinfo{$query_term}");
80 if ($count >= $max_count) {
86 if ($count >= $max_count) {
87 print "More than $max_count results for \"$query_term\", showing the first $count only\n";
89 print "$count results for \"$query_term\":\n";
92 foreach my $result (sort (@results)) {
93 my($found, @list) = split(' ', $result);
95 foreach my $image (sort(@list)) {