From 2ad99c20bcc297362aeccabb1c51e20c4bd4b533 Mon Sep 17 00:00:00 2001 From: Thomas Hochstein Date: Tue, 3 Sep 2013 09:21:55 +0200 Subject: [PATCH] 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 --- .gitignore | 2 +- feedlog.pl => bin/feedlog.pl | 11 ++++++----- gatherstats.pl => bin/gatherstats.pl | 11 ++++++----- groupstats.pl => bin/groupstats.pl | 11 ++++++----- newsstats.conf.sample => etc/newsstats.conf.sample | 0 install/install.pl | 12 ++++++------ NewsStats.pm => lib/NewsStats.pm | 10 ++++++++-- 7 files changed, 33 insertions(+), 24 deletions(-) rename feedlog.pl => bin/feedlog.pl (97%) rename gatherstats.pl => bin/gatherstats.pl (98%) rename groupstats.pl => bin/groupstats.pl (99%) rename newsstats.conf.sample => etc/newsstats.conf.sample (100%) rename NewsStats.pm => lib/NewsStats.pm (99%) diff --git a/.gitignore b/.gitignore index 40a80e5..a71cb91 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ tmp/ tmp/* -newsstats.conf +etc/newsstats.conf diff --git a/feedlog.pl b/bin/feedlog.pl similarity index 97% rename from feedlog.pl rename to bin/feedlog.pl index a5ecfb0..ef9429c 100755 --- a/feedlog.pl +++ b/bin/feedlog.pl @@ -15,7 +15,8 @@ BEGIN { our $VERSION = "0.01"; 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 warnings; @@ -75,7 +76,7 @@ GetOptions ('d|debug!' => \$OptDebug, 'V|version' => \&ShowVersion) or exit 1; ### read configuration -my %Conf = %{ReadConfig($HomePath.'/newsstats.conf')}; +my %Conf = %{ReadConfig('')}; ### init syslog openlog($0, 'nofatal,pid', LOG_NEWS); @@ -218,15 +219,15 @@ See L for further information. =over 4 -=item F +=item F The script itself. -=item F +=item F Library functions for the NewsStats package. -=item F +=item F Runtime configuration file. diff --git a/gatherstats.pl b/bin/gatherstats.pl similarity index 98% rename from gatherstats.pl rename to bin/gatherstats.pl index f1fe7de..f545456 100755 --- a/gatherstats.pl +++ b/bin/gatherstats.pl @@ -15,7 +15,8 @@ BEGIN { our $VERSION = "0.01"; 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 warnings; @@ -52,7 +53,7 @@ GetOptions ('c|checkgroups=s' => \$OptCheckgroupsFile, 'V|version' => \&ShowVersion) or exit 1; ### read configuration -my %Conf = %{ReadConfig($HomePath.'/newsstats.conf')}; +my %Conf = %{ReadConfig('')}; ### override configuration via commandline options my %ConfOverride; @@ -368,15 +369,15 @@ checking against checkgroups-*: =over 4 -=item F +=item F The script itself. -=item F +=item F Library functions for the NewsStats package. -=item F +=item F Runtime configuration file. diff --git a/groupstats.pl b/bin/groupstats.pl similarity index 99% rename from groupstats.pl rename to bin/groupstats.pl index 499e333..f1e566b 100755 --- a/groupstats.pl +++ b/bin/groupstats.pl @@ -15,7 +15,8 @@ BEGIN { our $VERSION = "0.01"; 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 warnings; @@ -81,7 +82,7 @@ if ($OptReportType) { my $ValidGroups = &ReadGroupList($OptCheckgroupsFile) if $OptCheckgroupsFile; ### read configuration -my %Conf = %{ReadConfig($HomePath.'/newsstats.conf')}; +my %Conf = %{ReadConfig('')}; ### override configuration via commandline options my %ConfOverride; @@ -635,15 +636,15 @@ machine-readable form (without formatting): =over 4 -=item F +=item F The script itself. -=item F +=item F Library functions for the NewsStats package. -=item F +=item F Runtime configuration file. diff --git a/newsstats.conf.sample b/etc/newsstats.conf.sample similarity index 100% rename from newsstats.conf.sample rename to etc/newsstats.conf.sample diff --git a/install/install.pl b/install/install.pl index ff392df..a5860d4 100755 --- a/install/install.pl +++ b/install/install.pl @@ -14,8 +14,8 @@ BEGIN { our $VERSION = "0.01"; use File::Basename; - # we're in .../install, so our module is in .. - push(@INC, dirname($0).'/..'); + # we're in .../install, so our module is in ../lib + push(@INC, dirname($0).'/../lib'); } use strict; use warnings; @@ -42,7 +42,7 @@ my $Path = cwd(); ### read configuration print("Reading configuration.\n"); -my %Conf = %{ReadConfig($Path.'/newsstats.conf')}; +my %Conf = %{ReadConfig('')}; ##### -------------------------------------------------------------------------- ##### Database table definitions @@ -294,15 +294,15 @@ Don't do a fresh install, but update from I. =over 4 -=item F +=item F The script itself. -=item F +=item F Library functions for the NewsStats package. -=item F +=item F Runtime configuration file. diff --git a/NewsStats.pm b/lib/NewsStats.pm similarity index 99% rename from NewsStats.pm rename to lib/NewsStats.pm index a237774..8a62179 100644 --- a/NewsStats.pm +++ b/lib/NewsStats.pm @@ -54,15 +54,19 @@ our $PackageVersion = '0.01'; use Data::Dumper; use File::Basename; +use Cwd qw(realpath); use Config::Auto; use DBI; #####-------------------------------- Vars --------------------------------##### -# trim the path +# save $0 in $FullPath 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%.*/%%; # set version string our $MyVersion = "$0 $::VERSION (NewsStats.pm $VERSION)"; @@ -99,6 +103,8 @@ sub ReadConfig { ### IN : $ConfFile: config filename ### OUT: reference to a hash containing the configuration my ($ConfFile) = @_; + # set default + $ConfFile = $HomePath . '/etc/newsstats.conf' if !$ConfFile; # mandatory configuration options my @Mandatory = ('DBDriver','DBHost','DBUser','DBPw','DBDatabase', 'DBTableRaw','DBTableGrps');