Sfoglia il codice sorgente

Patch by S. William Schulz <ss@sslinux.com> to enable a --silent switch to
pisg.

Morten Brix Pedersen 25 anni fa
parent
commit
700265a563
5 ha cambiato i file con 40 aggiunte e 19 eliminazioni
  1. 3 0
      docs/CONFIG-README
  2. 16 9
      modules/Pisg.pm
  3. 6 3
      modules/Pisg/HTMLGenerator.pm
  4. 8 4
      modules/Pisg/Parser/Logfile.pm
  5. 7 3
      pisg.pl

+ 3 - 0
docs/CONFIG-README

@@ -165,6 +165,9 @@ foul                Space seperated list of words considered to be 'foul'
 regexp_alises       1 or 0, enabling this will make aliases in <user> tags
                     regex-able. Default '0'.
 
+silent              1 or 0.  Enabling this will suppress all standard output
+                    from pisg.  Error messages will still be sent to STDOUT.
+
  * Colors / layout for your stats page *
 
 bgcolor             Background color of the page

+ 16 - 9
modules/Pisg.pm

@@ -62,12 +62,16 @@ sub run
     # Set the default configuration settings.
     $self->get_default_config_settings();
 
-    print "pisg $self->{cfg}->{version} - Perl IRC Statistics Generator\n\n";
-
     # Init the configuration file (aliases, ignores, channels, etc)
-    $self->init_config()
+    my $r = $self->init_config()
         if ($self->{use_configfile});
 
+    print "pisg $self->{cfg}->{version} - Perl IRC Statistics Generator\n\n"
+        unless ($self->{cfg}->{silent});
+
+    print "Using config file: $self->{cfg}->{configfile}\n\n"
+        if ($r && !$self->{cfg}->{silent});
+
     $self->init_words()       # Init words. (Foulwords, ignorewords, etc.)
         if ($self->{use_configfile});
 
@@ -112,6 +116,7 @@ sub get_default_config_settings
         lang => 'EN',
         langfile => 'lang.txt',
         prefix => "",
+        silent => 0,
 
         # Colors / Layout
 
@@ -226,7 +231,8 @@ sub init_debug
     my $self = shift;
     $self->{cfg}->{debugstarted} = 1;
     if ($self->{cfg}->{debug}) {
-        print "[ Debugging => $self->{cfg}->{debugfile} ]\n";
+        print "[ Debugging => $self->{cfg}->{debugfile} ]\n"
+            unless ($self->{cfg}->{silent});
         open(DEBUG,"> $self->{cfg}->{debugfile}") or print STDERR "$0: Unable to open debug
         file($self->{cfg}->{debugfile}): $!\n";
         $self->{debug}->("*** pisg debug file for $self->{cfg}->{logfile}\n");
@@ -262,7 +268,6 @@ sub init_config
     my $self = shift;
 
     if ((open(CONFIG, $self->{cfg}->{configfile}) or open(CONFIG, $FindBin::Bin . "/$self->{cfg}->{configfile}"))) {
-        print "Using config file: $self->{cfg}->{configfile}\n";
 
         my $lineno = 0;
         while (my $line = <CONFIG>)
@@ -346,6 +351,7 @@ sub init_config
         }
 
         close(CONFIG);
+
     }
 }
 
@@ -369,18 +375,19 @@ sub init_pisg
     # Add trailing slash when it's not there..
     $self->{cfg}->{imagepath} =~ s/([^\/])$/$1\//;
 
-    print "Using language template: $self->{cfg}->{lang}\n\n" if ($self->{cfg}->{lang} ne 'EN');
+    print "Using language template: $self->{cfg}->{lang}\n\n" if ($self->{cfg}->{lang} ne 'EN' && !$self->{cfg}->{silent});
 
-    print "Statistics for channel $self->{cfg}->{channel} \@ $self->{cfg}->{network} by $self->{cfg}->{maintainer}\n\n";
+    print "Statistics for channel $self->{cfg}->{channel} \@ $self->{cfg}->{network} by $self->{cfg}->{maintainer}\n\n"
+        unless ($self->{cfg}->{silent});
 }
 
 sub do_channel
 {
     my $self = shift;
     if (!$self->{cfg}->{channel}) {
-        print "No channels defined.\n";
+        print STDERR "No channels defined.\n";
     } elsif ((!$self->{cfg}->{logfile}) && (!$self->{cfg}->{logdir})) {
-        print "No logfile or logdir defined for " . $self->{cfg}->{channel} . "\n";
+        print STDERR "No logfile or logdir defined for " . $self->{cfg}->{channel} . "\n";
     } else {
         $self->init_pisg();        # Init some general things
 

+ 6 - 3
modules/Pisg/HTMLGenerator.pm

@@ -35,7 +35,8 @@ sub create_html
 
     my $self = shift;
 
-    print "Now generating HTML($self->{cfg}->{outputfile})...\n";
+    print "Now generating HTML($self->{cfg}->{outputfile})...\n"
+        unless ($self->{cfg}->{silent});
 
     open (OUTPUT, "> $self->{cfg}->{outputfile}") or
         die("$0: Unable to open outputfile($self->{cfg}->{outputfile}): $!\n");
@@ -366,7 +367,8 @@ sub _activenicks
 
     if ($self->{cfg}->{activenicks} > $nicks) {
         $self->{cfg}->{activenicks} = $nicks;
-        print "Note: There were fewer nicks in the logfile than your specificied there to be in most active nicks...\n";
+        print "Note: There were fewer nicks in the logfile than your specificied there to be in most active nicks...\n"
+            unless ($self->{cfg}->{silent});
     }
 
     my ($nick, $visiblenick, $randomline, %hash);
@@ -1201,7 +1203,8 @@ sub _template_text
         # Fall back to English if the language template doesn't exist
 
         if ($text = $self->{tmps}->{EN}{$template}) {
-            print "Note: There was no translation in $self->{cfg}->{lang} for '$template' - falling back to English..\n";
+            print "Note: There was no translation in $self->{cfg}->{lang} for '$template' - falling back to English..\n"
+                unless ($self->{cfg}->{silent});
         } else {
             die("No such template '$template' in language file.\n");
         }

+ 8 - 4
modules/Pisg/Parser/Logfile.pm

@@ -81,7 +81,8 @@ sub analyze
         sprintf("%02d hours, %02d minutes and %02d seconds", $hour, $min,
         $sec);
         print "Channel analyzed succesfully in $stats{processtime} on ",
-        scalar localtime(time()), "\n";;
+        scalar localtime(time()), "\n"
+            unless ($self->{cfg}->{silent});
 
         return \%stats;
 
@@ -102,7 +103,8 @@ sub _parse_dir
     # Add trailing slash when it's not there..
     $self->{cfg}->{logdir} =~ s/([^\/])$/$1\//;
 
-    print "Going into $self->{cfg}->{logdir} and parsing all files there...\n\n";
+    print "Going into $self->{cfg}->{logdir} and parsing all files there...\n\n"
+        unless ($self->{cfg}->{silent});
     my @filesarray;
     opendir(LOGDIR, $self->{cfg}->{logdir}) or
     die("Can't opendir $self->{cfg}->{logdir}: $!");
@@ -129,7 +131,8 @@ sub _parse_file
     my $self = shift;
     my ($stats, $lines, $file, $state) = @_;
 
-    print "Analyzing log($file) in '$self->{cfg}->{format}' format...\n";
+    print "Analyzing log($file) in '$self->{cfg}->{format}' format...\n"
+        unless ($self->{cfg}->{silent});
 
     if ($file =~ /.bz2?$/ && -f $file) {
         open (LOGFILE, "bunzip2 -c $file |") or
@@ -350,7 +353,8 @@ sub _parse_file
 
     close(LOGFILE);
 
-    print "Finished analyzing log, $stats->{days} days total.\n";
+    print "Finished analyzing log, $stats->{days} days total.\n"
+        unless ($self->{cfg}->{silent});
 }
 
 sub _opchanges

+ 7 - 3
pisg.pl

@@ -55,11 +55,11 @@ sub get_cmdline_options
 
     my $tmp;
     # Commandline options
-    my ($moduledir, $channel, $logfile, $format, $network, $maintainer, $outputfile, $logdir, $prefix, $configfile, $help);
+    my ($moduledir, $channel, $logfile, $format, $network, $maintainer, $outputfile, $logdir, $prefix, $configfile, $help, $silent);
 
 my $usage = <<END_USAGE;
 Usage: pisg.pl [-ch channel] [-l logfile] [-o outputfile] [-ma maintainer]
-[-f format] [-n network] [-d logdir] [-mo moduledir] [-h]
+[-f format] [-n network] [-d logdir] [-mo moduledir] [-s] [-h]
 
 -ch --channel=xxx      : Set channel name
 -l  --logfile=xxx      : Log file to parse
@@ -72,7 +72,8 @@ Usage: pisg.pl [-ch channel] [-l logfile] [-o outputfile] [-ma maintainer]
                          Only works with --dir
 -mo --moduledir=xxx    : Directory containing pisg's modules.
 -co --configfile=xxx   : Config file
--h --help              : Output this message and exit (-? also works).
+-s  --silent           : Suppress output (except error messages)
+-h  --help             : Output this message and exit (-? also works).
 
 Example:
 
@@ -95,6 +96,7 @@ END_USAGE
                    'aliasfile=s'  => \$tmp,
                    'moduledir=s'  => \$moduledir,
                    'configfile=s' => \$configfile,
+                   'silent'       => \$silent,
                    'help|?'       => \$help
                ) == 0 or $help) {
                    die($usage);
@@ -125,6 +127,8 @@ END_USAGE
 
     if ($configfile) { $cfg->{configfile} = $configfile; }
 
+    if ($silent) { $cfg->{silent} = 1; }
+
     return $cfg;
 
 }