You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@steve.apache.org by Jake Farrell <jf...@apache.org> on 2013/06/13 04:40:42 UTC
stv_tool.py number of available seats patch
While calculating the results for a vote today ran into an issue with
the stv_tool which had hardcoded values within it for the total number
of seats. The following patch adds argparse and makes the number of
seats as an available option
-Jake
Help print out:
usage: stv_tool.py [-h] [-s SEATS] [-v] raw_file
Calculate a winner for a vote
positional arguments:
raw_file
optional arguments:
-h, --help show this help message and exit
-s SEATS, --seats SEATS
Number of seats available, default 9
-v, --verbose Enable verbose logging
Patch:
--- /home/voter/steve/monitoring/stv_tool.py 2013-05-13
14:42:46.407723615 +0000
+++ stv_tool.py 2013-06-13 02:21:16.154038271 +0000
@@ -31,6 +31,7 @@
import os.path
import random
import ConfigParser
+import argparse
import re
ELECTED = 1
@@ -377,24 +378,35 @@
print fmt % args
-def usage():
- print 'USAGE: %s [-v] RAW_VOTES_FILE' % (os.path.basename(sys.argv[0]),)
- sys.exit(1)
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser(description="Calculate a winner for
a vote")
+ parser.add_argument('raw_file')
-if __name__ == '__main__':
- if len(sys.argv) < 2 or len(sys.argv) > 3:
- usage()
+ parser.add_argument("-s", "--seats", dest="seats",
+ help="Number of seats available, default 9",
+ default=9)
+
+ parser.add_argument("-v", "--verbose", dest="verbose",
action="store_true",
+ help="Enable verbose logging", default=False)
- if sys.argv[1] == '-v':
- VERBOSE = True
+ args = parser.parse_args()
+
+ VERBOSE = args.verbose
+ votefile = args.raw_file
+ num_seats = args.seats
- votefile = sys.argv[-1]
if not os.path.exists(votefile):
- usage()
+ parser.print_help()
+ sys.exit(1)
+
+ nominees = os.path.join(os.path.dirname(votefile),
'board_nominations.ini')
+ if not os.path.exists(nominees):
+ print 'Error: board_nominations.ini could not be found at %s' %
nominees
+ sys.exit(1)
names, votes = load_votes(votefile)
- ### take the count from options? (for whatif.cgi)
- run_vote(names, votes, 9)
+ run_vote(names, votes, num_seats)
print 'Done!'
+
Re: stv_tool.py number of available seats patch
Posted by Greg Stein <gs...@gmail.com>.
Ouch. Hard-coding sucks :-) (and yes, that hard-code and that script
is my fault...)
The patch looks good, on cursory review. I'll look closer later
tonite/tomorrow unless somebody beats me to it.
Thanks!
-g
On Wed, Jun 12, 2013 at 10:40 PM, Jake Farrell <jf...@apache.org> wrote:
> While calculating the results for a vote today ran into an issue with the
> stv_tool which had hardcoded values within it for the total number of seats.
> The following patch adds argparse and makes the number of seats as an
> available option
>
> -Jake
>
>
> Help print out:
>
> usage: stv_tool.py [-h] [-s SEATS] [-v] raw_file
>
> Calculate a winner for a vote
>
> positional arguments:
> raw_file
>
> optional arguments:
> -h, --help show this help message and exit
> -s SEATS, --seats SEATS
> Number of seats available, default 9
> -v, --verbose Enable verbose logging
>
>
>
>
> Patch:
>
>
> --- /home/voter/steve/monitoring/stv_tool.py 2013-05-13
> 14:42:46.407723615 +0000
> +++ stv_tool.py 2013-06-13 02:21:16.154038271 +0000
> @@ -31,6 +31,7 @@
> import os.path
> import random
> import ConfigParser
> +import argparse
> import re
>
> ELECTED = 1
> @@ -377,24 +378,35 @@
> print fmt % args
>
>
> -def usage():
> - print 'USAGE: %s [-v] RAW_VOTES_FILE' % (os.path.basename(sys.argv[0]),)
> - sys.exit(1)
> +if __name__ == '__main__':
> + parser = argparse.ArgumentParser(description="Calculate a winner for a
> vote")
>
> + parser.add_argument('raw_file')
>
> -if __name__ == '__main__':
> - if len(sys.argv) < 2 or len(sys.argv) > 3:
> - usage()
> + parser.add_argument("-s", "--seats", dest="seats",
> + help="Number of seats available, default 9",
> + default=9)
> +
> + parser.add_argument("-v", "--verbose", dest="verbose",
> action="store_true",
> + help="Enable verbose logging", default=False)
>
> - if sys.argv[1] == '-v':
> - VERBOSE = True
> + args = parser.parse_args()
> +
> + VERBOSE = args.verbose
> + votefile = args.raw_file
> + num_seats = args.seats
>
> - votefile = sys.argv[-1]
> if not os.path.exists(votefile):
> - usage()
> + parser.print_help()
> + sys.exit(1)
> +
> + nominees = os.path.join(os.path.dirname(votefile),
> 'board_nominations.ini')
> + if not os.path.exists(nominees):
> + print 'Error: board_nominations.ini could not be found at %s' %
> nominees
> + sys.exit(1)
>
> names, votes = load_votes(votefile)
>
> - ### take the count from options? (for whatif.cgi)
> - run_vote(names, votes, 9)
> + run_vote(names, votes, num_seats)
> print 'Done!'
> +
>
Re: stv_tool.py number of available seats patch
Posted by Jake Farrell <jf...@apache.org>.
My fault, I looked at the .svn config on minotaur in /home/voter not at
/home/voter/steve, thought it was in foundation/voter and didnt think to
check that the /home/voter/steve folder would be a separate checkout
Thanks
-Jake
On Thu, Jun 13, 2013 at 11:35 AM, Greg Stein <gs...@gmail.com> wrote:
> On Jun 13, 2013 9:55 AM, "Jake Farrell" <jf...@apache.org> wrote:
> >
> > Patch attached, added type=int to patch as well. note: patch is a diff
> against /home/voter/steve/monitoring/stv_tool.py as I dont have access to
> the steve repo. Let me know if anything else need to be looked at
>
> Huh? You should. It's at:
> http://svn.apache.org/repos/asf/steve/trunk/
>
Re: stv_tool.py number of available seats patch
Posted by Greg Stein <gs...@gmail.com>.
On Jun 13, 2013 9:55 AM, "Jake Farrell" <jf...@apache.org> wrote:
>
> Patch attached, added type=int to patch as well. note: patch is a diff
against /home/voter/steve/monitoring/stv_tool.py as I dont have access to
the steve repo. Let me know if anything else need to be looked at
Huh? You should. It's at:
http://svn.apache.org/repos/asf/steve/trunk/
Re: stv_tool.py number of available seats patch
Posted by Jake Farrell <jf...@apache.org>.
Patch attached, added type=int to patch as well. note: patch is a diff
against /home/voter/steve/monitoring/stv_tool.py as I dont have access to
the steve repo. Let me know if anything else need to be looked at
-Jake
On Thu, Jun 13, 2013 at 8:17 AM, Jim Jagielski <ji...@jagunet.com> wrote:
> I found that I needed ' type=int,' for seats for it to work
> (string->int issues, 'natch)
>
> On Jun 13, 2013, at 8:39 AM, Jim Jagielski <ji...@jaguNET.com> wrote:
>
> > +1
> >
> > (I've not used argparse much)
> >
> > I'll fold in ;)
> >
> > On Jun 12, 2013, at 10:40 PM, Jake Farrell <jf...@apache.org> wrote:
> >
> >> While calculating the results for a vote today ran into an issue with
> the stv_tool which had hardcoded values within it for the total number of
> seats. The following patch adds argparse and makes the number of seats as
> an available option
> >>
> >> -Jake
> >>
> >>
> >> Help print out:
> >>
> >> usage: stv_tool.py [-h] [-s SEATS] [-v] raw_file
> >>
> >> Calculate a winner for a vote
> >>
> >> positional arguments:
> >> raw_file
> >>
> >> optional arguments:
> >> -h, --help show this help message and exit
> >> -s SEATS, --seats SEATS
> >> Number of seats available, default 9
> >> -v, --verbose Enable verbose logging
> >>
> >>
> >>
> >>
> >> Patch:
> >>
> >>
> >> --- /home/voter/steve/monitoring/stv_tool.py 2013-05-13
> 14:42:46.407723615 +0000
> >> +++ stv_tool.py 2013-06-13 02:21:16.154038271 +0000
> >> @@ -31,6 +31,7 @@
> >> import os.path
> >> import random
> >> import ConfigParser
> >> +import argparse
> >> import re
> >>
> >> ELECTED = 1
> >> @@ -377,24 +378,35 @@
> >> print fmt % args
> >>
> >>
> >> -def usage():
> >> - print 'USAGE: %s [-v] RAW_VOTES_FILE' %
> (os.path.basename(sys.argv[0]),)
> >> - sys.exit(1)
> >> +if __name__ == '__main__':
> >> + parser = argparse.ArgumentParser(description="Calculate a winner for
> a vote")
> >>
> >> + parser.add_argument('raw_file')
> >>
> >> -if __name__ == '__main__':
> >> - if len(sys.argv) < 2 or len(sys.argv) > 3:
> >> - usage()
> >> + parser.add_argument("-s", "--seats", dest="seats",
> >> + help="Number of seats available, default 9",
> >> + default=9)
> >> +
> >> + parser.add_argument("-v", "--verbose", dest="verbose",
> action="store_true",
> >> + help="Enable verbose logging", default=False)
> >>
> >> - if sys.argv[1] == '-v':
> >> - VERBOSE = True
> >> + args = parser.parse_args()
> >> +
> >> + VERBOSE = args.verbose
> >> + votefile = args.raw_file
> >> + num_seats = args.seats
> >>
> >> - votefile = sys.argv[-1]
> >> if not os.path.exists(votefile):
> >> - usage()
> >> + parser.print_help()
> >> + sys.exit(1)
> >> +
> >> + nominees = os.path.join(os.path.dirname(votefile),
> 'board_nominations.ini')
> >> + if not os.path.exists(nominees):
> >> + print 'Error: board_nominations.ini could not be found at %s' %
> nominees
> >> + sys.exit(1)
> >>
> >> names, votes = load_votes(votefile)
> >>
> >> - ### take the count from options? (for whatif.cgi)
> >> - run_vote(names, votes, 9)
> >> + run_vote(names, votes, num_seats)
> >> print 'Done!'
> >> +
> >>
> >
>
>
Re: stv_tool.py number of available seats patch
Posted by Jim Jagielski <ji...@jaguNET.com>.
I found that I needed ' type=int,' for seats for it to work
(string->int issues, 'natch)
On Jun 13, 2013, at 8:39 AM, Jim Jagielski <ji...@jaguNET.com> wrote:
> +1
>
> (I've not used argparse much)
>
> I'll fold in ;)
>
> On Jun 12, 2013, at 10:40 PM, Jake Farrell <jf...@apache.org> wrote:
>
>> While calculating the results for a vote today ran into an issue with the stv_tool which had hardcoded values within it for the total number of seats. The following patch adds argparse and makes the number of seats as an available option
>>
>> -Jake
>>
>>
>> Help print out:
>>
>> usage: stv_tool.py [-h] [-s SEATS] [-v] raw_file
>>
>> Calculate a winner for a vote
>>
>> positional arguments:
>> raw_file
>>
>> optional arguments:
>> -h, --help show this help message and exit
>> -s SEATS, --seats SEATS
>> Number of seats available, default 9
>> -v, --verbose Enable verbose logging
>>
>>
>>
>>
>> Patch:
>>
>>
>> --- /home/voter/steve/monitoring/stv_tool.py 2013-05-13 14:42:46.407723615 +0000
>> +++ stv_tool.py 2013-06-13 02:21:16.154038271 +0000
>> @@ -31,6 +31,7 @@
>> import os.path
>> import random
>> import ConfigParser
>> +import argparse
>> import re
>>
>> ELECTED = 1
>> @@ -377,24 +378,35 @@
>> print fmt % args
>>
>>
>> -def usage():
>> - print 'USAGE: %s [-v] RAW_VOTES_FILE' % (os.path.basename(sys.argv[0]),)
>> - sys.exit(1)
>> +if __name__ == '__main__':
>> + parser = argparse.ArgumentParser(description="Calculate a winner for a vote")
>>
>> + parser.add_argument('raw_file')
>>
>> -if __name__ == '__main__':
>> - if len(sys.argv) < 2 or len(sys.argv) > 3:
>> - usage()
>> + parser.add_argument("-s", "--seats", dest="seats",
>> + help="Number of seats available, default 9",
>> + default=9)
>> +
>> + parser.add_argument("-v", "--verbose", dest="verbose", action="store_true",
>> + help="Enable verbose logging", default=False)
>>
>> - if sys.argv[1] == '-v':
>> - VERBOSE = True
>> + args = parser.parse_args()
>> +
>> + VERBOSE = args.verbose
>> + votefile = args.raw_file
>> + num_seats = args.seats
>>
>> - votefile = sys.argv[-1]
>> if not os.path.exists(votefile):
>> - usage()
>> + parser.print_help()
>> + sys.exit(1)
>> +
>> + nominees = os.path.join(os.path.dirname(votefile), 'board_nominations.ini')
>> + if not os.path.exists(nominees):
>> + print 'Error: board_nominations.ini could not be found at %s' % nominees
>> + sys.exit(1)
>>
>> names, votes = load_votes(votefile)
>>
>> - ### take the count from options? (for whatif.cgi)
>> - run_vote(names, votes, 9)
>> + run_vote(names, votes, num_seats)
>> print 'Done!'
>> +
>>
>
Re: stv_tool.py number of available seats patch
Posted by Jim Jagielski <ji...@jaguNET.com>.
+1
(I've not used argparse much)
I'll fold in ;)
On Jun 12, 2013, at 10:40 PM, Jake Farrell <jf...@apache.org> wrote:
> While calculating the results for a vote today ran into an issue with the stv_tool which had hardcoded values within it for the total number of seats. The following patch adds argparse and makes the number of seats as an available option
>
> -Jake
>
>
> Help print out:
>
> usage: stv_tool.py [-h] [-s SEATS] [-v] raw_file
>
> Calculate a winner for a vote
>
> positional arguments:
> raw_file
>
> optional arguments:
> -h, --help show this help message and exit
> -s SEATS, --seats SEATS
> Number of seats available, default 9
> -v, --verbose Enable verbose logging
>
>
>
>
> Patch:
>
>
> --- /home/voter/steve/monitoring/stv_tool.py 2013-05-13 14:42:46.407723615 +0000
> +++ stv_tool.py 2013-06-13 02:21:16.154038271 +0000
> @@ -31,6 +31,7 @@
> import os.path
> import random
> import ConfigParser
> +import argparse
> import re
>
> ELECTED = 1
> @@ -377,24 +378,35 @@
> print fmt % args
>
>
> -def usage():
> - print 'USAGE: %s [-v] RAW_VOTES_FILE' % (os.path.basename(sys.argv[0]),)
> - sys.exit(1)
> +if __name__ == '__main__':
> + parser = argparse.ArgumentParser(description="Calculate a winner for a vote")
>
> + parser.add_argument('raw_file')
>
> -if __name__ == '__main__':
> - if len(sys.argv) < 2 or len(sys.argv) > 3:
> - usage()
> + parser.add_argument("-s", "--seats", dest="seats",
> + help="Number of seats available, default 9",
> + default=9)
> +
> + parser.add_argument("-v", "--verbose", dest="verbose", action="store_true",
> + help="Enable verbose logging", default=False)
>
> - if sys.argv[1] == '-v':
> - VERBOSE = True
> + args = parser.parse_args()
> +
> + VERBOSE = args.verbose
> + votefile = args.raw_file
> + num_seats = args.seats
>
> - votefile = sys.argv[-1]
> if not os.path.exists(votefile):
> - usage()
> + parser.print_help()
> + sys.exit(1)
> +
> + nominees = os.path.join(os.path.dirname(votefile), 'board_nominations.ini')
> + if not os.path.exists(nominees):
> + print 'Error: board_nominations.ini could not be found at %s' % nominees
> + sys.exit(1)
>
> names, votes = load_votes(votefile)
>
> - ### take the count from options? (for whatif.cgi)
> - run_vote(names, votes, 9)
> + run_vote(names, votes, num_seats)
> print 'Done!'
> +
>