aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
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)";
}