pisg.pl 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use Getopt::Long;
  4. # pisg - Perl IRC Statistics Generator
  5. #
  6. # Copyright (C) 2001 <Morten Brix Pedersen> - morten@wtf.dk
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software
  20. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. sub main
  22. {
  23. my $script_dir = $0;
  24. # If the script was executed as ./pisg.pl - then we just remove
  25. # everything after the last slash, if it was executed as 'perl pisg.pl'
  26. # we assume that we are executing in the current dir.
  27. if ($script_dir =~ m/\/[^\/]*$/) {
  28. $script_dir =~ s/\/[^\/]*$//;
  29. } else {
  30. $script_dir = ".";
  31. }
  32. my $cfg = get_cmdline_options($script_dir);
  33. push(@INC, $cfg->{modules_dir});
  34. my $pisg;
  35. eval <<END;
  36. use Pisg;
  37. \$pisg = new Pisg(
  38. use_configfile => '1',
  39. override_cfg => \$cfg,
  40. search_path => \$script_dir,
  41. );
  42. \$pisg->run();
  43. END
  44. if ($@) {
  45. print $@;
  46. }
  47. if ($@) {
  48. print STDERR "Could not load pisg! Reason:\n$@\n";
  49. return undef;
  50. }
  51. }
  52. sub get_cmdline_options
  53. {
  54. my $script_dir = shift;
  55. my $cfg = {
  56. modules_dir => "$script_dir/modules/", # Module search path
  57. };
  58. my $tmp;
  59. # Commandline options
  60. my ($moduledir, $channel, $logfile, $format, $network, $maintainer, $outputfile, $logdir, $prefix, $configfile, $help, $silent);
  61. my $usage = <<END_USAGE;
  62. Usage: pisg.pl [-ch channel] [-l logfile] [-o outputfile] [-ma maintainer]
  63. [-f format] [-n network] [-d logdir] [-mo moduledir] [-s] [-h]
  64. -ch --channel=xxx : Set channel name
  65. -l --logfile=xxx : Log file to parse
  66. -o --outfile=xxx : Name of html file to create
  67. -ma --maintainer=xxx : Channel/statistics maintainer
  68. -f --format=xxx : Logfile format [see FORMATS file]
  69. -n --network=xxx : IRC Network this channel is on.
  70. -d --dir=xxx : Analyze all files in this dir. Ignores logfile.
  71. -p --prefix=xxx : Analyse only files starting with xxx in dir.
  72. Only works with --dir
  73. -mo --moduledir=xxx : Directory containing pisg's modules.
  74. -co --configfile=xxx : Config file
  75. -s --silent : Suppress output (except error messages)
  76. -h --help : Output this message and exit (-? also works).
  77. Example:
  78. \$ pisg.pl -n IRCnet -f xchat -o suid.html -ch \\#channel -l logfile.log
  79. All options may also be defined by editing the configuration file and
  80. calling pisg without arguments.
  81. END_USAGE
  82. #'
  83. if (GetOptions('channel=s' => \$channel,
  84. 'logfile=s' => \$logfile,
  85. 'format=s' => \$format,
  86. 'network=s' => \$network,
  87. 'maintainer=s' => \$maintainer,
  88. 'outfile=s' => \$outputfile,
  89. 'dir=s' => \$logdir,
  90. 'prefix=s' => \$prefix,
  91. 'ignorefile=s' => \$tmp,
  92. 'aliasfile=s' => \$tmp,
  93. 'moduledir=s' => \$moduledir,
  94. 'configfile=s' => \$configfile,
  95. 'silent' => \$silent,
  96. 'help|?' => \$help
  97. ) == 0 or $help) {
  98. die($usage);
  99. }
  100. if ($tmp) {
  101. die("The aliasfile and ignorefile has been obsoleted by the new
  102. pisg.cfg, please use that instead [look in pisg.cfg]\n");
  103. }
  104. if ($channel) { $cfg->{channel} = $channel; }
  105. if ($logfile) { $cfg->{logfile} = $logfile; }
  106. if ($format) { $cfg->{format} = $format; }
  107. if ($network) { $cfg->{network} = $network; }
  108. if ($maintainer) { $cfg->{maintainer} = $maintainer; }
  109. if ($outputfile) { $cfg->{outputfile} = $outputfile; }
  110. if ($logdir) { $cfg->{logdir} = $logdir; }
  111. if ($prefix) { $cfg->{prefix} = $prefix; }
  112. if ($moduledir) { $cfg->{modules_dir} = $moduledir; }
  113. if ($configfile) { $cfg->{configfile} = $configfile; }
  114. if ($silent) { $cfg->{silent} = 1; }
  115. return $cfg;
  116. }
  117. main(); # Run the script