aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin H. Johnson <robbat2@gentoo.org>2015-06-27 22:32:45 -0700
committerRobin H. Johnson <robbat2@gentoo.org>2015-06-27 22:33:35 -0700
commit274977d0840c8a1879946234c4d07575e8bde153 (patch)
treee5ade4c066051b55a7b69a8c51ae132d252eebdc /countify
parentStart some cleanup of Election code. (diff)
downloadelections-274977d0840c8a1879946234c4d07575e8bde153.tar.gz
elections-274977d0840c8a1879946234c4d07575e8bde153.tar.bz2
elections-274977d0840c8a1879946234c4d07575e8bde153.zip
Refactor elections, so we can have common fetching of which elections are open, and then consistently use the epoch timestamp inside the start/stop files.
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
Diffstat (limited to 'countify')
-rwxr-xr-xcountify38
1 files changed, 11 insertions, 27 deletions
diff --git a/countify b/countify
index 975a7ec..1465da4 100755
--- a/countify
+++ b/countify
@@ -8,7 +8,13 @@
#
#BEGIN { push @INC, (getpwnam 'fox2mike')[7].'/elections' }
-BEGIN { push @INC, '/etc/elections/current' }
+BEGIN {
+ if(-f '/etc/elections/Votify.pm') {
+ push @INC, '/etc/elections';
+ } else {
+ push @INC, '.' if -f 'Votify.pm';
+ }
+}
use POSIX;
use Getopt::Long;
@@ -24,33 +30,11 @@ use strict;
(my $version = $Votify::version) =~ s/.*?(\d.*\d).*/$zero version $1\n/;
my %opt;
-sub grabfile_int {
- my $f = shift;
- open FILE, "<", $f;
- my $i = <FILE>;
- close FILE;
- chomp $i;
- return $i + 0;
-}
-
# Collect the open elections
-my (@open_elections, $usage_elections);
-opendir(D, "$Votify::datadir/") or die;
-@open_elections = sort grep {
- s/^start-// and do {
- my ($startfile) = sprintf "%s/start-%s", $Votify::datadir, $_;
- my ($stopfile) = sprintf "%s/stop-%s", $Votify::datadir, $_;
- my ($starttime) = grabfile_int($startfile);
- my ($stoptime) = grabfile_int($stopfile);
- $starttime = (stat _)[9] if stat($startfile) and (!defined($starttime) or ($starttime <= 0));
- $stoptime = (stat _)[9] if stat($stopfile) and (!defined($stoptime) or ($stoptime <= 0));
- ((not defined $starttime or $starttime < time) and
- (not defined $stoptime or $stoptime > time))
- }
-} readdir D;
-closedir D;
-if (@open_elections) {
- $usage_elections = join("\n ", @open_elections);
+my (%open_elections, $usage_elections);
+%open_elections = Votify::get_open_elections_hash();
+if (scalar keys %open_elections) {
+ $usage_elections = join("\n ", keys %open_elections);
} else {
$usage_elections = "(no elections currently open)";
}