pisg 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use Getopt::Long;
  4. # pisg - Perl IRC Statistics Generator
  5. #
  6. # Copyright (C) 2001-2002 <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 - then we just remove
  25. # everything after the last slash, if it was executed as 'perl pisg'
  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 $version;
  35. if ($cfg->{version}) {
  36. $version = 1;
  37. undef $cfg->{version};
  38. }
  39. my $pisg;
  40. eval <<END;
  41. use Pisg;
  42. \$pisg = new Pisg(
  43. use_configfile => '1',
  44. override_cfg => \$cfg,
  45. search_path => \$script_dir,
  46. );
  47. if (\$version) {
  48. print \$pisg->{cfg}->{version} . "\n";
  49. } else {
  50. \$pisg->run();
  51. }
  52. END
  53. if ($@) {
  54. print STDERR "Could not load pisg! Reason:\n$@\n";
  55. return undef;
  56. }
  57. }
  58. sub get_cmdline_options
  59. {
  60. my $script_dir = shift;
  61. my %cfg = (
  62. modules_dir => "$script_dir/modules/", # Module search path
  63. );
  64. # Commandline options
  65. my ($tmp, $help, $silent, $option, @cfg);
  66. my $usage = <<END_USAGE;
  67. Usage: pisg [-ch channel] [-l logfile] [-o outputfile] [-ma maintainer]
  68. [-f format] [-n network] [-d logdir] [-mo moduledir] [-s] [-v] [-h]
  69. -ch --channel=xxx : Set channel name
  70. -cc --cchannels=xxx : Only do this channel from cfg file, give multiple
  71. times to do multiple channels
  72. -l --logfile=xxx : Log file to parse
  73. -o --outfile=xxx : Name of HTML file to create
  74. -t --tag=xxx : Replace \%t in --outfile by xxx
  75. -ma --maintainer=xxx : Channel/statistics maintainer
  76. -f --format=xxx : Logfile format [see FORMATS file]
  77. -n --network=xxx : IRC network for the channel
  78. -d --dir=xxx : Analyze all files in this dir. Ignores logfile
  79. -nf --nfiles=xxx : Analyze the last xxx files if used with --dir
  80. -p --prefix=xxx : Analyse only files prefixed by xxx in dir
  81. Only works with --dir
  82. -cf --cfg opt=value : Specify configuration options, eg. -cf ShowWpl=1
  83. -co --configfile=xxx : Configuration file
  84. -mo --moduledir=xxx : Directory containing pisg modules
  85. -s --silent : Suppress output (except error messages)
  86. -v --version : Show version
  87. -h --help : Output this message and exit.
  88. Example:
  89. \$ pisg -n IRCnet -f xchat -o suid.html -ch \\#channel -l logfile.log
  90. All options may also be defined by editing the configuration file and
  91. calling pisg without arguments.
  92. END_USAGE
  93. if (GetOptions('channel=s' => \$cfg{channel},
  94. 'cchannels=s@' => \@{ $cfg{cchannels} },
  95. 'logfile=s' => \$cfg{logfile},
  96. 'format=s' => \$cfg{format},
  97. 'network=s' => \$cfg{network},
  98. 'maintainer=s' => \$cfg{maintainer},
  99. 'outfile=s' => \$cfg{outputfile},
  100. 'tag=s' => \$cfg{outputtag},
  101. 'dir=s' => \$cfg{logdir},
  102. 'nfiles=i' => \$cfg{nfiles},
  103. 'prefix=s' => \$cfg{logprefix},
  104. 'moduledir=s' => \$cfg{moduledir},
  105. 'configfile=s' => \$cfg{configfile},
  106. 'ignorefile=s' => \$tmp,
  107. 'aliasfile=s' => \$tmp,
  108. 'silent' => \$silent,
  109. 'version' => \$cfg{version},
  110. 'cfg=s' => \@cfg,
  111. 'help|?' => \$help
  112. ) == 0 or $help) {
  113. die($usage);
  114. }
  115. if ($tmp) {
  116. die("The aliasfile and ignorefile has been obsoleted by the new
  117. pisg.cfg, please use that instead [see pisg.cfg]\n");
  118. }
  119. if ($silent) { $cfg{silent} = 1; }
  120. if (@cfg) {
  121. foreach (@cfg) {
  122. if (/(.*)=(.*)/) {
  123. $cfg{$1} = $2;
  124. } else {
  125. print STDERR "Warning: Couldn't parse -cfg option\n";
  126. }
  127. }
  128. }
  129. return \%cfg;
  130. }
  131. main(); # Run the script