Adapt feedlog.pl to new coding style.

* Switch to Getopt::Long, change coding style;
  limit line length.

* Completely changed options due to new
  GetOpt::Long processing.

* Adapt to changes in NewsStats.pm

* Redo documentation.

* Update TODO.

Signed-off-by: Thomas Hochstein <thh@inter.net>
This commit is contained in:
Thomas Hochstein 2012-05-27 14:30:14 +02:00
parent 880c3eb227
commit f05ec4aeaa
2 changed files with 37 additions and 40 deletions

View file

@ -47,7 +47,6 @@ Bug numbers refer to the Mantis issue tracker at <http://bugs.th-h.de/>.
- General tests and optimisations - General tests and optimisations
+ feedlog.pl + feedlog.pl
- Complete rewrite (like groupstats.pl, include changes in NewsStats.pm)
- Gracefully handle interruptions to database connection, at least log - Gracefully handle interruptions to database connection, at least log
lost postings (Bug #30). lost postings (Bug #30).
- Buffer output that cannot be written to database (Bug #31). - Buffer output that cannot be written to database (Bug #31).

View file

@ -7,7 +7,7 @@
# #
# It is part of the NewsStats package. # It is part of the NewsStats package.
# #
# Copyright (c) 2010 Thomas Hochstein <thh@inter.net> # Copyright (c) 2010-2012 Thomas Hochstein <thh@inter.net>
# #
# It can be redistributed and/or modified under the same terms under # It can be redistributed and/or modified under the same terms under
# which Perl itself is published. # which Perl itself is published.
@ -25,18 +25,24 @@ use Sys::Syslog qw(:standard :macros);
use Date::Format; use Date::Format;
use DBI; use DBI;
use Getopt::Long qw(GetOptions);
Getopt::Long::config ('bundling');
################################# Main program ################################# ################################# Main program #################################
### read commandline options ### read commandline options
my %Options = &ReadOptions('qd'); my ($OptDebug,$OptQuiet);
GetOptions ('d|debug!' => \$OptDebug,
'q|test!' => \$OptQuiet,
'h|help' => \&ShowPOD,
'V|version' => \&ShowVersion) or exit 1;
### read configuration ### read configuration
my %Conf = %{ReadConfig('newsstats.conf')}; my %Conf = %{ReadConfig($HomePath.'/newsstats.conf')};
### init syslog ### init syslog
openlog($MySelf, 'nofatal,pid', LOG_NEWS); openlog($0, 'nofatal,pid', LOG_NEWS);
syslog(LOG_NOTICE, "$MyVersion starting up.") if !$Options{'q'}; syslog(LOG_NOTICE, "$MyVersion starting up.") if !$OptQuiet;
### init database ### init database
my $DBHandle = InitDB(\%Conf,0); my $DBHandle = InitDB(\%Conf,0);
@ -44,7 +50,11 @@ if (!$DBHandle) {
syslog(LOG_CRIT, 'Database connection failed: %s', $DBI::errstr); syslog(LOG_CRIT, 'Database connection failed: %s', $DBI::errstr);
while (1) {}; # go into endless loop to suppress further errors and respawning while (1) {}; # go into endless loop to suppress further errors and respawning
}; };
my $DBQuery = $DBHandle->prepare(sprintf("INSERT INTO %s.%s (day,date,mid,timestamp,token,size,peer,path,newsgroups,headers) VALUES (?,?,?,?,?,?,?,?,?,?)",$Conf{'DBDatabase'},$Conf{'DBTableRaw'})); my $DBQuery = $DBHandle->prepare(sprintf("INSERT INTO %s.%s (day,date,mid,
timestamp,token,size,peer,path,
newsgroups,headers)
VALUES (?,?,?,?,?,?,?,?,?,?)",
$Conf{'DBDatabase'},$Conf{'DBTableRaw'}));
### main loop ### main loop
while (<>) { while (<>) {
@ -72,17 +82,21 @@ while (<>) {
my $Date = time2str("%Y-%m-%d %H:%M:%S", $Timestamp); my $Date = time2str("%Y-%m-%d %H:%M:%S", $Timestamp);
# write to database # write to database
if (!$DBQuery->execute($Day, $Date, $Mid, $Timestamp, $Token, $Size, $Peer, $Path, $Newsgroups, $Headers)) { if (!$DBQuery->execute($Day, $Date, $Mid, $Timestamp, $Token, $Size, $Peer,
$Path, $Newsgroups, $Headers)) {
syslog(LOG_ERR, 'Database error: %s', $DBI::errstr); syslog(LOG_ERR, 'Database error: %s', $DBI::errstr);
}; };
$DBQuery->finish; $DBQuery->finish;
warn sprintf("-----\nDay: %s\nDate: %s\nMID: %s\nTS: %s\nToken: %s\nSize: %s\nPeer: %s\nPath: %s\nNewsgroups: %s\nHeaders: %s\n",$Day, $Date, $Mid, $Timestamp, $Token, $Size, $Peer, $Path, $Newsgroups, $Headers) if $Options{'d'}; warn sprintf("-----\nDay: %s\nDate: %s\nMID: %s\nTS: %s\nToken: %s\n".
"Size: %s\nPeer: %s\nPath: %s\nNewsgroups: %s\nHeaders: %s\n",
$Day, $Date, $Mid, $Timestamp, $Token, $Size, $Peer, $Path,
$Newsgroups, $Headers) if $OptDebug;
} }
### close handles ### close handles
$DBHandle->disconnect; $DBHandle->disconnect;
syslog(LOG_NOTICE, "$MySelf closing down.") if !$Options{'q'}; syslog(LOG_NOTICE, "$0 closing down.") if !$OptQuiet;
closelog(); closelog();
__END__ __END__
@ -99,23 +113,7 @@ B<feedlog> [B<-Vhdq>]
=head1 REQUIREMENTS =head1 REQUIREMENTS
See doc/README: Perl 5.8.x itself and the following modules from CPAN: See L<doc/README>.
=over 2
=item -
Config::Auto
=item -
Date::Format
=item -
DBI
=back
=head1 DESCRIPTION =head1 DESCRIPTION
@ -131,29 +129,29 @@ terminating would only result in a rapid respawn.
=head2 Configuration =head2 Configuration
F<feedlog.pl> will read its configuration from F<newsstats.conf> which B<feedlog> will read its configuration from F<newsstats.conf> which
should be present in the same directory via Config::Auto. should be present in the same directory via Config::Auto.
See doc/INSTALL for an overview of possible configuration options. See L<doc/INSTALL> for an overview of possible configuration options.
=head1 OPTIONS =head1 OPTIONS
=over 3 =over 3
=item B<-V> (version) =item B<-V>, B<--version>
Print out version and copyright information on B<yapfaq> and exit. Print out version and copyright information and exit.
=item B<-h> (help) =item B<-h>, B<--help>
Print this man page and exit. Print this man page and exit.
=item B<-d> (debug) =item B<-d>, B<--debug>
Output debugging information to STDERR while parsing STDIN. You'll Output debugging information to STDERR while parsing STDIN. You'll
find that information most probably in your B<INN> F<errlog> file. find that information most probably in your B<INN> F<errlog> file.
=item B<-q> (quiet) =item B<-q>, B<--quiet>
Suppress logging to syslog. Suppress logging to syslog.
@ -161,7 +159,7 @@ Suppress logging to syslog.
=head1 INSTALLATION =head1 INSTALLATION
See doc/INSTALL. See L<doc/INSTALL.>
=head1 EXAMPLES =head1 EXAMPLES
@ -172,7 +170,7 @@ Set up a feed like that in your B<INN> F<newsfeeds> file:
:!*,de.* :!*,de.*
:Tc,WmtfbsPNH,Ac:/path/to/feedlog.pl :Tc,WmtfbsPNH,Ac:/path/to/feedlog.pl
See doc/INSTALL for further information. See L<doc/INSTALL> for further information.
=head1 FILES =head1 FILES
@ -188,7 +186,7 @@ Library functions for the NewsStats package.
=item F<newsstats.conf> =item F<newsstats.conf>
Runtime configuration file for B<yapfaq>. Runtime configuration file.
=back =back
@ -203,11 +201,11 @@ bug tracker at L<http://bugs.th-h.de/>!
=item - =item -
doc/README L<doc/README>
=item - =item -
doc/INSTALL L<doc/INSTALL>
=back =back
@ -219,7 +217,7 @@ Thomas Hochstein <thh@inter.net>
=head1 COPYRIGHT AND LICENSE =head1 COPYRIGHT AND LICENSE
Copyright (c) 2010 Thomas Hochstein <thh@inter.net> Copyright (c) 2010-2012 Thomas Hochstein <thh@inter.net>
This program is free software; you may redistribute it and/or modify it This program is free software; you may redistribute it and/or modify it
under the same terms as Perl itself. under the same terms as Perl itself.