Redo directory structure.

* Move all scripts to /bin
* Move configuration to /etc
* Move NewsStats.pm to /lib
* Add new path to NewsStats.pm to all scripts
* Set $HomePath to top level directory
* Move setting of config file name to ReadConf()

Signed-off-by: Thomas Hochstein <thh@inter.net>
This commit is contained in:
Thomas Hochstein 2013-09-03 09:21:55 +02:00
parent 07c0b2589a
commit 2ad99c20bc
7 changed files with 33 additions and 24 deletions

2
.gitignore vendored
View file

@ -1,3 +1,3 @@
tmp/ tmp/
tmp/* tmp/*
newsstats.conf etc/newsstats.conf

View file

@ -15,7 +15,8 @@
BEGIN { BEGIN {
our $VERSION = "0.01"; our $VERSION = "0.01";
use File::Basename; use File::Basename;
push(@INC, dirname($0)); # we're in .../bin, so our module is in ../lib
push(@INC, dirname($0).'/../lib');
} }
use strict; use strict;
use warnings; use warnings;
@ -75,7 +76,7 @@ GetOptions ('d|debug!' => \$OptDebug,
'V|version' => \&ShowVersion) or exit 1; 'V|version' => \&ShowVersion) or exit 1;
### read configuration ### read configuration
my %Conf = %{ReadConfig($HomePath.'/newsstats.conf')}; my %Conf = %{ReadConfig('')};
### init syslog ### init syslog
openlog($0, 'nofatal,pid', LOG_NEWS); openlog($0, 'nofatal,pid', LOG_NEWS);
@ -218,15 +219,15 @@ See L<doc/INSTALL> for further information.
=over 4 =over 4
=item F<feedlog.pl> =item F<bin/feedlog.pl>
The script itself. The script itself.
=item F<NewsStats.pm> =item F<lib/NewsStats.pm>
Library functions for the NewsStats package. Library functions for the NewsStats package.
=item F<newsstats.conf> =item F<etc/newsstats.conf>
Runtime configuration file. Runtime configuration file.

View file

@ -15,7 +15,8 @@
BEGIN { BEGIN {
our $VERSION = "0.01"; our $VERSION = "0.01";
use File::Basename; use File::Basename;
push(@INC, dirname($0)); # we're in .../bin, so our module is in ../lib
push(@INC, dirname($0).'/../lib');
} }
use strict; use strict;
use warnings; use warnings;
@ -52,7 +53,7 @@ GetOptions ('c|checkgroups=s' => \$OptCheckgroupsFile,
'V|version' => \&ShowVersion) or exit 1; 'V|version' => \&ShowVersion) or exit 1;
### read configuration ### read configuration
my %Conf = %{ReadConfig($HomePath.'/newsstats.conf')}; my %Conf = %{ReadConfig('')};
### override configuration via commandline options ### override configuration via commandline options
my %ConfOverride; my %ConfOverride;
@ -368,15 +369,15 @@ checking against checkgroups-*:
=over 4 =over 4
=item F<gatherstats.pl> =item F<bin/gatherstats.pl>
The script itself. The script itself.
=item F<NewsStats.pm> =item F<lib/NewsStats.pm>
Library functions for the NewsStats package. Library functions for the NewsStats package.
=item F<newsstats.conf> =item F<etc/newsstats.conf>
Runtime configuration file. Runtime configuration file.

View file

@ -15,7 +15,8 @@
BEGIN { BEGIN {
our $VERSION = "0.01"; our $VERSION = "0.01";
use File::Basename; use File::Basename;
push(@INC, dirname($0)); # we're in .../bin, so our module is in ../lib
push(@INC, dirname($0).'/../lib');
} }
use strict; use strict;
use warnings; use warnings;
@ -81,7 +82,7 @@ if ($OptReportType) {
my $ValidGroups = &ReadGroupList($OptCheckgroupsFile) if $OptCheckgroupsFile; my $ValidGroups = &ReadGroupList($OptCheckgroupsFile) if $OptCheckgroupsFile;
### read configuration ### read configuration
my %Conf = %{ReadConfig($HomePath.'/newsstats.conf')}; my %Conf = %{ReadConfig('')};
### override configuration via commandline options ### override configuration via commandline options
my %ConfOverride; my %ConfOverride;
@ -635,15 +636,15 @@ machine-readable form (without formatting):
=over 4 =over 4
=item F<groupstats.pl> =item F<bin/groupstats.pl>
The script itself. The script itself.
=item F<NewsStats.pm> =item F<lib/NewsStats.pm>
Library functions for the NewsStats package. Library functions for the NewsStats package.
=item F<newsstats.conf> =item F<etc/newsstats.conf>
Runtime configuration file. Runtime configuration file.

View file

@ -14,8 +14,8 @@
BEGIN { BEGIN {
our $VERSION = "0.01"; our $VERSION = "0.01";
use File::Basename; use File::Basename;
# we're in .../install, so our module is in .. # we're in .../install, so our module is in ../lib
push(@INC, dirname($0).'/..'); push(@INC, dirname($0).'/../lib');
} }
use strict; use strict;
use warnings; use warnings;
@ -42,7 +42,7 @@ my $Path = cwd();
### read configuration ### read configuration
print("Reading configuration.\n"); print("Reading configuration.\n");
my %Conf = %{ReadConfig($Path.'/newsstats.conf')}; my %Conf = %{ReadConfig('')};
##### -------------------------------------------------------------------------- ##### --------------------------------------------------------------------------
##### Database table definitions ##### Database table definitions
@ -294,15 +294,15 @@ Don't do a fresh install, but update from I<version>.
=over 4 =over 4
=item F<install.pl> =item F<install/install.pl>
The script itself. The script itself.
=item F<NewsStats.pm> =item F<lib/NewsStats.pm>
Library functions for the NewsStats package. Library functions for the NewsStats package.
=item F<newsstats.conf> =item F<etc/newsstats.conf>
Runtime configuration file. Runtime configuration file.

View file

@ -54,15 +54,19 @@ our $PackageVersion = '0.01';
use Data::Dumper; use Data::Dumper;
use File::Basename; use File::Basename;
use Cwd qw(realpath);
use Config::Auto; use Config::Auto;
use DBI; use DBI;
#####-------------------------------- Vars --------------------------------##### #####-------------------------------- Vars --------------------------------#####
# trim the path # save $0 in $FullPath
our $FullPath = $0; our $FullPath = $0;
our $HomePath = dirname($0); # strip filename and /bin or /install directory to create the $HomePath
our $HomePath = dirname(realpath($0));
$HomePath =~ s/\/(bin|install)//;
# trim $0
$0 =~ s%.*/%%; $0 =~ s%.*/%%;
# set version string # set version string
our $MyVersion = "$0 $::VERSION (NewsStats.pm $VERSION)"; our $MyVersion = "$0 $::VERSION (NewsStats.pm $VERSION)";
@ -99,6 +103,8 @@ sub ReadConfig {
### IN : $ConfFile: config filename ### IN : $ConfFile: config filename
### OUT: reference to a hash containing the configuration ### OUT: reference to a hash containing the configuration
my ($ConfFile) = @_; my ($ConfFile) = @_;
# set default
$ConfFile = $HomePath . '/etc/newsstats.conf' if !$ConfFile;
# mandatory configuration options # mandatory configuration options
my @Mandatory = ('DBDriver','DBHost','DBUser','DBPw','DBDatabase', my @Mandatory = ('DBDriver','DBHost','DBUser','DBPw','DBDatabase',
'DBTableRaw','DBTableGrps'); 'DBTableRaw','DBTableGrps');