]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Modules/Debian.pl
- new time delta function
[infobot.git] / src / Modules / Debian.pl
index a9aa5997239e5e770644cb0e0acecc61bcd9680a..7652c8cf20be9c2933df57ab39bd40338b6a6996 100644 (file)
@@ -10,11 +10,15 @@ package Debian;
 use strict;
 
 # format: "alias=real".
+my $announce   = 0;
 my $defaultdist        = "woody";
 my %dists      = (
-       "unstable"      => "woody",
+       "unstable"      => "sid",
+       "testing"       => "woody,      # new since 20001219.
        "stable"        => "potato",
        "incoming"      => "incoming",
+### the following don't work. too much effort to get 3 types of distros
+### to work harmoniously :-)
        "slink"         => "archive-2.1",
        "hamm"          => "archive-2.0",
        "rex"           => "archive-1.?",
@@ -24,10 +28,11 @@ my %dists   = (
 my %urlcontents = (
        "debian/Contents-##DIST-i386.gz" =>
                "ftp://ftp.us.debian.org".
-               "/debian/dists/##DIST/Contents-i386.gz", #woody = BROKEN
-
+               "/debian/dists/##DIST/Contents-i386.gz",
+### APPEARS TO BE FIXED?
+# => strip control chars just to be safe.
        "debian/Contents-##DIST-i386-non-US.gz" =>
-               "ftp://non-us.debian.org".
+               "ftp://ftp.ca.debian.org".
                "/debian-non-US/dists/##DIST/non-US/Contents-i386.gz",
 );
 
@@ -43,13 +48,13 @@ my %urlpackages = (
                "/debian/dists/##DIST/non-free/binary-i386/Packages.gz",
 
        "debian/Packages-##DIST-non-US-main-i386.gz" =>
-               "ftp://non-us.debian.org".
+               "ftp://ftp.ca.debian.org".
                "/debian-non-US/dists/##DIST/non-US/main/binary-i386/Packages.gz",
        "debian/Packages-##DIST-non-US-contrib-i386.gz" =>
-               "ftp://non-us.debian.org".
+               "ftp://ftp.ca.debian.org".
                "/debian-non-US/dists/##DIST/non-US/contrib/binary-i386/Packages.gz",
        "debian/Packages-##DIST-non-US-non-free-i386.gz" =>
-               "ftp://non-us.debian.org".
+               "ftp://ftp.ca.debian.org".
                "/debian-non-US/dists/##DIST/non-US/non-free/binary-i386/Packages.gz",
 );
 
@@ -73,6 +78,7 @@ sub DebianDownload {
     # fe dists.
     # Download the files.
     my $file;
+##    my %ret;
     foreach $file (keys %urls) {
        my $url = $urls{$file};
        $url  =~ s/##DIST/$dist/g;
@@ -88,9 +94,11 @@ sub DebianDownload {
 
        next unless ($update);
 
-       if ($good + $bad == 0) {
+       &main::DEBUG("announce == $announce.");
+       if ($good + $bad == 0 and !$announce) {
            &main::status("Debian: Downloading files for '$dist'.");
            &main::msg($main::who, "Updating debian files... please wait.");
+           $announce++;
        }
 
        if (exists $main::debian{$url}) {
@@ -106,13 +114,13 @@ sub DebianDownload {
            # hope it doesn't do anything bad.
            if ($file =~ /Contents-woody-i386-non-US/) {
                &main::DEBUG("Skipping Contents-woody-i386-non-US.");
-               $file =~ s/woody/potato/;
-               $path =~ s/woody/potato/;
+#              $file =~ s/woody/potato/;
+#              $path =~ s/woody/potato/;
 ###            next;
            }
 
            if (!&main::ftpGet($host,$path,$thisfile,$file)) {
-               &main::DEBUG("deb: down: ftpGet($host,$path,$thisfile,$file) == BAD.");
+               &main::WARN("deb: down: $file == BAD.");
                $bad++;
                next;
            }
@@ -129,6 +137,7 @@ sub DebianDownload {
            }
 
            &main::DEBUG("deb: download: good.");
+##         $ret{$
            $good++;
        } else {
            &main::ERROR("Debian: invalid format of url => ($url).");
@@ -162,9 +171,8 @@ sub searchContents {
     ### larne's regex.
     # $query = $query.'(\.so\.)?([.[[:digit:]]+\.]+)?$';
 
-    $query =~ s/\\([\^\$])/$1/g;
+    $query =~ s/\\([\^\$])/$1/g;       # hrm?
     $query =~ s/^\s+|\s+$//g;
-    $query =~ s/\*/\\S*/g;             # does it even work?
 
     if (!&main::validExec($query)) {
        &main::msg($main::who, "search string looks fuzzy.");
@@ -184,11 +192,27 @@ sub searchContents {
     }
 
     # start of search.
-    my $start_time = &main::gettimeofday();
+    my $start_time = &main::timeget();
 
     my $found = 0;
     my %contents;
-    my $search = "$query.*\[ \t]";
+    my $grepRE;
+    my $front = 0;
+    ### TODO: search properly if /usr/bin/blah is done.
+    if ($query =~ s/\$$//) {
+       &main::DEBUG("search-regex found.");
+       $grepRE = "$query\[ \t]";
+    } elsif ($query =~ s/^\^//) {
+       &main::DEBUG("front marker regex found.");
+       $front = 1;
+       $grepRE = $query;
+    } else {
+       $grepRE = "$query*\[ \t]";
+    }
+
+    ### fix up grepRE for "*".
+    $grepRE =~ s/\*/.*/g;
+
     my @files;
     foreach (keys %urlcontents) {
        s/##DIST/$dist/g;
@@ -205,7 +229,7 @@ sub searchContents {
 
     my $files = join(' ', @files);
 
-    open(IN,"zegrep -h '$search' $files |");
+    open(IN,"zegrep -h '$grepRE' $files |");
     while (<IN>) {
        if (/^\.?\/?(.*?)[\t\s]+(\S+)\n$/) {
            my ($file,$package) = ("/".$1,$2);
@@ -216,10 +240,13 @@ sub searchContents {
                next unless ($basename =~ /\Q$query\E/);
            }
            next if ($query !~ /\.\d\.gz/ and $file =~ /\/man\//);
+           next if ($front and $file !~ /^\/\Q$query\E/);
 
            $contents{$package}{$file} = 1;
            $found++;
        }
+
+       last if ($found > 100);
     }
     close IN;
 
@@ -237,11 +264,7 @@ sub searchContents {
            return;
        }
 
-       if (! -d "Temp/") {
-           mkdir("Temp",0755);
-       }
-
-       my $file = "temp/$main::who.txt";
+       my $file = "$main::param{tempDir}/$main::who.txt";
        if (!open(OUT,">$file")) {
            &main::ERROR("Debian: cannot write file for dcc send.");
            return;
@@ -276,7 +299,7 @@ sub searchContents {
     @list = sort { length $a <=> length $b } @list;
 
     # show how long it took.
-    my $delta_time = &main::gettimeofday() - $start_time;
+    my $delta_time = &main::timedelta($start_time);
     &main::status(sprintf("Debian: %.02f sec to complete query.", $delta_time)) if ($delta_time > 0);
 
     my $prefix = "Debian Search of '$query' ";
@@ -296,7 +319,7 @@ sub searchAuthor {
     $query =~ s/^\s+|\s+$//g;
 
     # start of search.
-    my $start_time = &main::gettimeofday();
+    my $start_time = &main::timeget();
     &main::status("Debian: starting author search.");
 
     my $files;
@@ -377,7 +400,7 @@ sub searchAuthor {
     my @pkg = sort keys %{$pkg{$list[0]}};
 
     # show how long it took.
-    my $delta_time = &main::gettimeofday() - $start_time;
+    my $delta_time = &main::timedelta($start_time);
     &main::status(sprintf("Debian: %.02f sec to complete query.", $delta_time)) if ($delta_time > 0);
 
     my $email  = join(', ', keys %{$maint{$list[0]}});
@@ -393,7 +416,7 @@ sub searchDesc {
     $query =~ s/^\s+|\s+$//g;
 
     # start of search.
-    my $start_time = &main::gettimeofday();
+    my $start_time = &main::timeget();
     &main::status("Debian: starting desc search.");
 
     my $files;
@@ -448,15 +471,15 @@ sub searchDesc {
        my $prefix = "Debian Desc Search of '$query' ";
        &main::performStrictReply( &main::formListReply(0, $prefix, ) );
     } elsif (scalar @list == 1) {      # list = 1.
-       &main::DEBUG("list == 1; showing package info of '$query'.");
-       &infoPackages("info", $query);
+       &main::DEBUG("list == 1; showing package info of '$list[0]'.");
+       &infoPackages("info", $list[0]);
     } else {                           # list > 1.
        my $prefix = "Debian Desc Search of '$query' ";
        &main::performStrictReply( &main::formListReply(0, $prefix, @list) );
     }
 
     # show how long it took.
-    my $delta_time = &main::gettimeofday() - $start_time;
+    my $delta_time = &main::timedelta($start_time);
     &main::status(sprintf("Debian: %.02f sec to complete query.", $delta_time)) if ($delta_time > 0);
 }
 
@@ -768,6 +791,8 @@ sub infoStats {
        close IN;
     }
 
+    ### TODO: don't count ppl with multiple email addresses.
+
     &main::performStrictReply(
        "Debian Distro Stats on $dist... ".
        "\002$total{'count'}\002 packages, ".
@@ -796,7 +821,7 @@ sub infoStats {
 sub generateIndex {
     my (@dists)        = @_;
     &main::status("Debian: !!! generateIndex() called !!!");
-    if (!scalar @dists) {
+    if (!scalar @dists or $dists[0] eq '') {
        &main::ERROR("gI: no dists to generate index.");
        return 1;
     }
@@ -816,10 +841,15 @@ sub generateIndex {
            next;
        }
 
+       if (/^woody$/i) {
+           &main::DEBUG("Copying old index of woody to -old");
+           system("cp $idx $idx-old");
+       }
+
        &main::DEBUG("gIndeX: calling DebianDownload($dist, ...).");
        &DebianDownload($dist, %urlpackages);
 
-       &main::status("Debian: generating index for '$_'.");
+       &main::status("Debian: generating index for '$dist'.");
        if (!open(OUT,">$idx")) {
            &main::ERROR("cannot write to $idx.");
            return 0;
@@ -838,9 +868,8 @@ sub generateIndex {
            open(IN,"zcat $packages |");
 
            while (<IN>) {
-               if (/^Package: (.*)\n$/) {
-                   print OUT $1."\n";
-               }
+               next unless (/^Package: (.*)\n$/);
+               print OUT $1."\n";
            }
            close IN;
        }
@@ -877,7 +906,7 @@ sub validPackage {
            next;
        }
 
-       if (/^$package\n$/) {
+       if (/^\Q$package\E\n$/) {
            push(@files,$file);
        }
        $count++;
@@ -893,16 +922,17 @@ sub searchPackage {
     my ($dist, $query) = &getDistroFromStr($_[0]);
     my $file = "debian/Packages-$dist.idx";
     my @files;
-    my $error = 0;
+    my $error  = 0;
+    my $warn   = 0;
 
-    &main::status("Debian: Search package matching '$query' in '$dist'.");
-    if ( -z $file) {
-       &main::DEBUG("sP: $file == NULL; removing, redoing.");
-       unlink $file;
+    if ($query =~ tr/A-Z/a-z/) {
+       $warn++;
     }
 
+    &main::status("Debian: Search package matching '$query' in '$dist'.");
+    unlink $file if ( -z $file);
+
     while (!open(IN, $file)) {
-       &main::ERROR("$file does not exist (#2).");
        if ($dist eq "incoming") {
            &main::DEBUG("sP: dist == incoming; calling gI().");
            &generateIncoming();
@@ -912,7 +942,9 @@ sub searchPackage {
            &main::ERROR("could not generate index!!!");
            return;
        }
+
        $error++;
+       &main::DEBUG("should we be doing this?");
        &generateIndex(($dist));
     }
 
@@ -920,7 +952,7 @@ sub searchPackage {
        chop;
 
        if (/^\*(.*)$/) {
-           &main::DEBUG("sP: hrm => '$1'.");
+           $file = $1;
 
            if (&main::isStale($file, $main::param{'debianRefreshInterval'})) {
                &main::DEBUG("STALE $file! regen.");
@@ -930,7 +962,6 @@ sub searchPackage {
                last;
            }
 
-           $file = $1;
            next;
        }
 
@@ -940,6 +971,10 @@ sub searchPackage {
     }
     close IN;
 
+    if (scalar @files and $warn) {
+       &main::msg($main::who, "searching for package name should be fully lowercase!");
+    }
+
     return @files;
 }