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