]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Modules/Debian.pl
- use &hasParam() instead of IsChanConf for more commands
[infobot.git] / src / Modules / Debian.pl
index c86d7aa665c364958c9f52a817aa101378c441fc..331493e5462302b7781b34f2d1545f9c7c58e891 100644 (file)
@@ -11,14 +11,24 @@ use strict;
 
 # format: "alias=real".
 my $announce   = 0;
-my $defaultdist        = "unstable";
+my $defaultdist        = "sid";
 my $refresh = &::getChanConfDefault("debianRefreshInterval",7)
                        * 60 * 60 * 24;
+my $debug      = 1;
 
+### ... old
+#my %dists     = (
+#      "sid"           => "unstable",
+#      "woody"         => "testing",   # new since 20001219.
+#      "potato"        => "stable",
+#      "incoming"      => "incoming",
+#);
+
+### new... the right way.
 my %dists      = (
-       "sid"           => "unstable",
-       "woody"         => "testing",   # new since 20001219.
-       "potato"        => "stable",
+       "unstable"      => "sid",
+       "testing"       => "woody",     # new since 20001219.
+       "stable"        => "potato",
        "incoming"      => "incoming",
 );
 
@@ -87,7 +97,7 @@ sub DebianDownload {
 
        next unless ($update);
 
-       &::DEBUG("announce == $announce.");
+       &::DEBUG("announce == $announce.") if ($debug);
        if ($good + $bad == 0 and !$announce) {
            &::status("Debian: Downloading files for '$dist'.");
            &::msg($::who, "Updating debian files... please wait.");
@@ -95,9 +105,9 @@ sub DebianDownload {
        }
 
        if (exists $::debian{$url}) {
-           &::DEBUG("2: ".(time - $::debian{$url})." <= $refresh");
+           &::DEBUG("2: ".(time - $::debian{$url})." <= $refresh") if ($debug);
            next if (time() - $::debian{$url} <= $refresh);
-           &::DEBUG("stale for url $url; updating!");
+           &::DEBUG("stale for url $url; updating!") if ($debug);
        }
 
        if ($url =~ /^ftp:\/\/(.*?)\/(\S+)\/(\S+)$/) {
@@ -118,7 +128,7 @@ sub DebianDownload {
            }
 
            if (! -f $file) {
-               &::DEBUG("deb: down: ftpGet: !file");
+               &::WARN("deb: down: ftpGet: !file");
                $bad++;
                next;
            }
@@ -129,7 +139,7 @@ sub DebianDownload {
 #              system("cp debian/Contents-potato-i386-non-US.gz debian/Contents-woody-i386-non-US.gz");
 #          }
 
-           &::DEBUG("deb: download: good.");
+           &::DEBUG("deb: download: good.") if ($debug);
            $good++;
        } else {
            &::ERROR("Debian: invalid format of url => ($url).");
@@ -269,7 +279,7 @@ sub searchContents {
        }
 
        foreach $pkg (keys %contents) {
-           foreach (keys %{$contents{$pkg}}) {
+           foreach (keys %{ $contents{$pkg} }) {
                # TODO: correct padding.
                print OUT "$_\t\t\t$pkg\n";
            }
@@ -285,7 +295,7 @@ sub searchContents {
 
     my @list;
     foreach $pkg (keys %contents) {
-       my @tmplist = &::fixFileList(keys %{$contents{$pkg}});
+       my @tmplist = &::fixFileList(keys %{ $contents{$pkg} });
        my @sublist = sort { length $a <=> length $b } @tmplist;
 
        pop @sublist while (scalar @sublist > 3);
@@ -303,6 +313,7 @@ sub searchContents {
     my $prefix = "Debian Search of '$query' ";
     if (scalar @list) {        # @list.
        &::pSReply( &::formListReply(0, $prefix, @list) );
+
     } else {           # !@list.
        &::DEBUG("ok, !\@list, searching desc for '$query'.");
        my @list = &searchDesc($query);
@@ -310,9 +321,11 @@ sub searchContents {
        if (!scalar @list) {
            my $prefix = "Debian Package/File/Desc Search of '$query' ";
            &::pSReply( &::formListReply(0, $prefix, ) );
+
        } elsif (scalar @list == 1) {   # list = 1.
            &::DEBUG("list == 1; showing package info of '$list[0]'.");
            &infoPackages("info", $list[0]);
+
        } else {                                # list > 1.
            my $prefix = "Debian Desc Search of '$query' ";
            &::pSReply( &::formListReply(0, $prefix, @list) );
@@ -352,6 +365,7 @@ sub searchAuthor {
     if ($good == 0 and $bad != 0) {
        my %urls = &fixDist($dist, %urlpackages);
        &::DEBUG("deb: download 2.");
+
        if (!&DebianDownload($dist, %urls)) {
            &::ERROR("Debian(sA): could not download files.");
            return;
@@ -363,6 +377,7 @@ sub searchAuthor {
     while (<IN>) {
        if (/^Package: (\S+)$/) {
            $package = $1;
+
        } elsif (/^Maintainer: (.*) \<(\S+)\>$/) {
            my($name,$email) = ($1,$2);
            if ($package eq "") {
@@ -372,6 +387,7 @@ sub searchAuthor {
            $maint{$name}{$email} = 1;
            $pkg{$name}{$package} = 1;
            $package = "";
+
        } else {
            &::WARN("invalid line: '$_'.");
        }
@@ -387,9 +403,11 @@ sub searchAuthor {
     # TODO: should we only search email if '@' is used?
     if (scalar keys %hash < 15) {
        my $name;
+
        foreach $name (keys %maint) {
            my $email;
-           foreach $email (keys %{$maint{$name}}) {
+
+           foreach $email (keys %{ $maint{$name} }) {
                next unless ($email =~ /\Q$query\E/i);
                next if (exists $hash{$name});
                $hash{$name} = 1;
@@ -406,13 +424,13 @@ sub searchAuthor {
 
     &::DEBUG("showing all packages by '$list[0]'...");
 
-    my @pkg = sort keys %{$pkg{$list[0]}};
+    my @pkg = sort keys %{ $pkg{$list[0]} };
 
     # show how long it took.
     my $delta_time = &::timedelta($start_time);
     &::status(sprintf("Debian: %.02f sec to complete query.", $delta_time)) if ($delta_time > 0);
 
-    my $email  = join(', ', keys %{$maint{$list[0]}});
+    my $email  = join(', ', keys %{ $maint{$list[0]} });
     my $prefix = "Debian Packages by $list[0] \002<\002$email\002>\002 ";
     &::pSReply( &::formListReply(0, $prefix, @pkg) );
 }
@@ -449,6 +467,7 @@ sub searchDesc {
     if ($good == 0 and $bad != 0) {
        my %urls = &fixDist($dist, %urlpackages);
        &::DEBUG("deb: download 2c.");
+
        if (!&DebianDownload($dist, %urls)) {
            &::ERROR("Debian(sD): could not download files.");
            return;
@@ -634,7 +653,8 @@ sub infoPackages {
     # hrm...
     my %urls = &fixDist($dist, %urlpackages);
     if ($dist ne "incoming") {
-       &::DEBUG("deb: download 3.");
+       &::DEBUG("deb: download 3.") if ($debug);
+
        if (!&DebianDownload($dist, %urls)) {   # no good download.
            &::WARN("Debian(iP): could not download ANY files.");
        }
@@ -688,7 +708,8 @@ sub infoPackages {
            $pkg{'info'}  = "\002(\002". $pkg{'desc'} ."\002)\002";
            $pkg{'info'} .= ", section ".$pkg{'section'};
            $pkg{'info'} .= ", is ".$pkg{'priority'};
-           $pkg{'info'} .= ". Version: \002$pkg{'version'}\002";
+#          $pkg{'info'} .= ". Version: \002$pkg{'version'}\002";
+           $pkg{'info'} .= ". Version: \002$pkg{'version'}\002 ($dist)";
            $pkg{'info'} .= ", Packaged size: \002". int($pkg{'size'}/1024) ."\002 kB";
            $pkg{'info'} .= ", Installed size: \002$pkg{'installed'}\002 kB";
 
@@ -799,14 +820,14 @@ sub infoStats {
     &::pSReply(
        "Debian Distro Stats on $dist... ".
        "\002$total{'count'}\002 packages, ".
-       "\002".scalar(keys %{$total{'maint'}})."\002 maintainers, ".
+       "\002".scalar(keys %{ $total{'maint'} })."\002 maintainers, ".
        "\002". int($total{'isize'}/1024)."\002 MB installed size, ".
        "\002". int($total{'csize'}/1024/1024)."\002 MB compressed size."
     );
 
 ### TODO: do individual stats? if so, we need _another_ arg.
 #    foreach $file (keys %stats) {
-#      foreach (keys %{$stats{$file}}) {
+#      foreach (keys %{ $stats{$file} }) {
 #          &::DEBUG("  '$file' '$_' '$stats{$file}{$_}'.");
 #      }
 #    }
@@ -897,7 +918,7 @@ sub validPackage {
     my $olddist        = $dist;
     $dist = &getDistro($dist);
 
-    &::DEBUG("D: validPackage($package, $dist) called.");
+    &::DEBUG("D: validPackage($package, $dist) called.") if ($debug);
 
     my $error = 0;
     while (!open(IN, "debian/Packages-$dist.idx")) {
@@ -925,7 +946,7 @@ sub validPackage {
     }
     close IN;
 
-    &::DEBUG("vP: scanned $count items in index.");
+    &::VERB("vP: scanned $count items in index.",2);
 
     return @files;
 }
@@ -1005,15 +1026,16 @@ sub getDistro {
     }
 
     if (exists $dists{$dist}) {
-       &::DEBUG("gD: returning dists{$dist} ($dists{$dist})");
+       &::VERB("gD: returning dists{$dist} ($dists{$dist})",2);
        return $dists{$dist};
+
     } else {
        if (!grep /^\Q$dist\E$/i, %dists) {
            &::msg($::who, "invalid dist '$dist'.");
            return;
        }
 
-       &::DEBUG("gD: returning $dist (no change or conversion)");
+       &::VERB("gD: returning $dist (no change or conversion)",2);
        return $dist;
     }
 }
@@ -1058,7 +1080,7 @@ sub DebianFind {
        &::status("searchPackage returned one result; getting info of package instead!");
        &::Forker("debian", sub { &infoPackages("info", "$results[0] $dist"); } );
     } else {
-       my $prefix = "Debian Package Listing of '$str' ";
+       my $prefix = "Debian Package Listing of '$query' ";
        &::pSReply( &::formListReply(0, $prefix, @results) );
     }
 }