pisg 5.2 KB

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