1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
#!/usr/bin/perl -w
# $Id: votify,v 1.5 2005/05/16 04:03:46 agriffis Exp $
#
# Copyright 2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
#
# votify: generate, verify and submit voting ballots for trustee elections
#
#BEGIN { push @INC, (getpwnam 'fox2mike')[7].'/elections' }
BEGIN { push @INC, '/etc/elections/current' }
use POSIX;
use Getopt::Long;
use List::Util;
use Votify 'user';
use strict;
######################################################################
# Global vars
######################################################################
(my $zero = $0) =~ s,.*/,,;
(my $version = '$Revision: 1.5 $') =~ s/.*?(\d.*\d).*/$zero version $1\n/;
my (%opt, %elections);
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 ($name) = $_;
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));
my $valid = ((not defined $starttime or $starttime < time) and
(not defined $stoptime or $stoptime > time));
if($valid) {
$elections{$name} = {};
$elections{$name}{starttime} = $starttime;
$elections{$name}{stoptime} = $stoptime;
}
$valid;
}
} readdir D;
closedir D;
my $datefmt = '%Y-%m-%d %H:%M UTC';
if (@open_elections) {
$usage_elections = "Presently available elections:\n" . join('', map {
my ($name) = $_;
my ($start) = strftime($datefmt, localtime($elections{$name}{starttime}));
my ($stop) = strftime($datefmt, localtime($elections{$name}{stoptime}));
sprintf("\t%s: %s to %s\n", $name, $start, $stop) } @open_elections);
$usage_elections .= <<EOF
\nA handy tool called "votify" can be used to vote in the election. You can use
"votify --help" to get instructions on how to vote, verify, and submit your
ballot.
EOF
} else {
#$usage_elections = "No Gentoo elections are presently open.\n";
$usage_elections = "";
}
print $usage_elections;
exit;
# vim:sw=4 et
|