From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <gentoo-commits+bounces-887819-garchives=archives.gentoo.org@lists.gentoo.org> Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id E34C61382AC for <garchives@archives.gentoo.org>; Sun, 19 Jun 2016 12:13:45 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 5B5499422F; Sun, 19 Jun 2016 12:13:45 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id DE2919422F for <gentoo-commits@lists.gentoo.org>; Sun, 19 Jun 2016 12:13:44 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id B4CB73406DD for <gentoo-commits@lists.gentoo.org>; Sun, 19 Jun 2016 12:13:43 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id A62C3208E for <gentoo-commits@lists.gentoo.org>; Sun, 19 Jun 2016 12:13:39 +0000 (UTC) From: "Jorge Manuel B. S. Vicetto" <jmbsvicetto@gentoo.org> To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Jorge Manuel B. S. Vicetto" <jmbsvicetto@gentoo.org> Message-ID: <1466337935.feb500c197990874101ae84aa51a6b718e96ae79.jmbsvicetto@gentoo> Subject: [gentoo-commits] proj/elections:master commit in: / X-VCS-Repository: proj/elections X-VCS-Files: Votify.pm votify X-VCS-Directories: / X-VCS-Committer: jmbsvicetto X-VCS-Committer-Name: Jorge Manuel B. S. Vicetto X-VCS-Revision: feb500c197990874101ae84aa51a6b718e96ae79 X-VCS-Branch: master Date: Sun, 19 Jun 2016 12:13:39 +0000 (UTC) Precedence: bulk List-Post: <mailto:gentoo-commits@lists.gentoo.org> List-Help: <mailto:gentoo-commits+help@lists.gentoo.org> List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org> List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org> List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org> X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 6b6b07b4-cefc-48f6-abd5-ec4f4a8683a3 X-Archives-Hash: 4d0250c357aac5ad9aa87eb30728b1a3 commit: feb500c197990874101ae84aa51a6b718e96ae79 Author: Jorge Manuel B. S. Vicetto (jmbsvicetto) <jmbsvicetto <AT> gentoo <DOT> org> AuthorDate: Sun Jun 19 12:05:35 2016 +0000 Commit: Jorge Manuel B. S. Vicetto <jmbsvicetto <AT> gentoo <DOT> org> CommitDate: Sun Jun 19 12:05:35 2016 +0000 URL: https://gitweb.gentoo.org/proj/elections.git/commit/?id=feb500c1 Allow running votify outside of /etc/elections and the repository dir. Signed-off-by: Jorge Manuel B. S. Vicetto (jmbsvicetto) <jmbsvicetto <AT> gentoo.org> Votify.pm | 12 ++++++------ votify | 8 +++++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Votify.pm b/Votify.pm index 48e5938..ed5b519 100644 --- a/Votify.pm +++ b/Votify.pm @@ -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; diff --git a/votify b/votify index e52881d..4fb688d 100755 --- a/votify +++ b/votify @@ -7,13 +7,15 @@ # votify: generate, verify and submit voting ballots for trustee elections # -#BEGIN { push @INC, (getpwnam 'fox2mike')[7].'/elections' } BEGIN { + my $dirname; if(-f '/etc/elections/Votify.pm') { - push @INC, '/etc/elections'; + $dirname = '/etc/elections'; } else { - push @INC, '.' if -f 'Votify.pm'; + use File::Basename; + $dirname = dirname(__FILE__); } + push @INC, $dirname; } use POSIX;