diff options
author | 2016-06-19 12:05:35 +0000 | |
---|---|---|
committer | 2016-06-19 12:05:35 +0000 | |
commit | feb500c197990874101ae84aa51a6b718e96ae79 (patch) | |
tree | 53ee700c2fec3e779303d800b2410f128f8cf40c /Votify.pm | |
parent | Prepare the council-201606 election. (diff) | |
download | elections-feb500c197990874101ae84aa51a6b718e96ae79.tar.gz elections-feb500c197990874101ae84aa51a6b718e96ae79.tar.bz2 elections-feb500c197990874101ae84aa51a6b718e96ae79.zip |
Allow running votify outside of /etc/elections and the repository dir.
Signed-off-by: Jorge Manuel B. S. Vicetto (jmbsvicetto) <jmbsvicetto@gentoo.org>
Diffstat (limited to 'Votify.pm')
-rw-r--r-- | Votify.pm | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -10,13 +10,13 @@ package Votify; use POSIX; use Cwd qw(abs_path); +use File::Basename; use File::Spec::Functions; use List::Util; use strict; our $datefmt = '%Y-%m-%d %H:%M:%S UTC'; - -our ($basedir) = List::Util::first { -d $_ } ('/etc/elections', '.'); +our ($basedir) = List::Util::first { -d $_ } ('/etc/elections', dirname(__FILE__)); (our $zero = $0) =~ s,.*/,,; our $version = '1.6'; @@ -41,16 +41,16 @@ sub validate_election_dir { my $election_dir = $_; my $election_name = $election_dir; $election_name =~ /.*\//; - return 0 unless -d $election_dir; + return 0 unless -d "$basedir/$election_dir"; return 0 if substr($election_name,0,1) eq "."; my $valid = List::Util::reduce { $a or $b ? 1 : 0; } map { my $file_valid = 0; # Legacy naming: - $file_valid = 1 if -f sprintf("%s/%s-%s", $election_name, $_, $election_name); + $file_valid = 1 if -f sprintf("%s/%s-%s", "$basedir/$election_name", $_, $election_name); # New naming: - $file_valid = 1 if -f sprintf("%s/%s", $election_name, $_); + $file_valid = 1 if -f sprintf("%s/%s", "$basedir/$election_name", $_); #printf "File %s valid=%d\n", $_, $file_valid; $file_valid; } @REQUIRED_FILES; @@ -88,7 +88,7 @@ sub get_single_election_hashref { my %election; foreach my $fn (@REQUIRED_FILES){ #print "Scan $fn\n"; - my @filenames = (sprintf("%s/%s", $election_name, $fn), sprintf("%s/%s-%s", $election_name, $fn, $election_name)); + my @filenames = (sprintf("%s/%s", "$basedir/$election_name", $fn), sprintf("%s/%s-%s", "$basedir/$election_name", $fn, $election_name)); #print Dumper(@filenames); my $filename = abs_path(List::Util::first { -f $_ } @filenames); $election{"${fn}file"} = $filename; |