pisg 5.1 KB

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