[Checkins] SVN: zope-foundation-admin/trunk/vote/ Initial vote app.
Jim Fulton
jim at zope.com
Tue Jun 6 09:56:06 EDT 2006
Log message for revision 68505:
Initial vote app.
Changed:
A zope-foundation-admin/trunk/vote/
A zope-foundation-admin/trunk/vote/singletransferablevote.py
A zope-foundation-admin/trunk/vote/vote.py
-=-
Added: zope-foundation-admin/trunk/vote/singletransferablevote.py
===================================================================
--- zope-foundation-admin/trunk/vote/singletransferablevote.py 2006-06-06 10:32:25 UTC (rev 68504)
+++ zope-foundation-admin/trunk/vote/singletransferablevote.py 2006-06-06 13:56:05 UTC (rev 68505)
@@ -0,0 +1,37 @@
+
+
+def validate(issuefolder, args):
+ valid = [v.strip()
+ for v in open(issuefolder+'.valid').read().strip().split('\n')
+ ]
+ max = int(valid.pop(0))
+ if len(args) > max:
+ error("Too many votes.")
+
+ seen = set()
+ for arg in votes:
+ if arg in seen:
+ error("Repeated vote: "+args)
+ if arg not in valid:
+ error("Invalid vote: %s.\nValid choices are: %s"
+ % (arg, ' '.join(valid))
+ )
+
+def count(issuefolder, uname):
+ vote = os.path.join(issuefolder, uname)
+ if os.path.exists(vote):
+ print 'You voted:'
+ print open(vote).read()
+ else:
+ print "You haven't voted yet."
+ print
+
+ valid = [v.strip()
+ for v in open(issuefolder+'.valid').read().strip().split('\n')
+ ]
+ max = int(valid.pop(0))
+
+ print "You can make as many as %s votes from the choices:" % max
+ print '\n'.join(valid)
+
+
Property changes on: zope-foundation-admin/trunk/vote/singletransferablevote.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: zope-foundation-admin/trunk/vote/vote.py
===================================================================
--- zope-foundation-admin/trunk/vote/vote.py 2006-06-06 10:32:25 UTC (rev 68504)
+++ zope-foundation-admin/trunk/vote/vote.py 2006-06-06 13:56:05 UTC (rev 68505)
@@ -0,0 +1,91 @@
+#!/usr/local/bin/python2.4
+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Dirt-simple voting app
+
+There is a directory: /foundation/votes
+
+This directory is writable only by zf committer members.
+(Enforced using a group.)
+
+There is a subdirectory for each question. When a question is
+open for voting, the directory is writable.
+
+The vote command is invoked via ssh:
+
+ ssh svn.zope.com vote issueid args
+
+an issue has an associated "schema". This is a
+Python file containing two functions, validate, and count.
+The validate method validates a sequence of arguments.
+The count methods prints the current results.
+
+When someone votes, their input is validates and, if valid:
+
+ - Their vote is written to a file with the same name as their
+ login id
+
+ - The results of all votes (the output of count) is printed.
+
+If the vote command is invoked with an issue id but no arguments,
+then the current results are printed.
+
+$Id$
+"""
+
+import os, pwd, re, sys
+
+votes = os.path.dirname(os.path.realpath(__file__))
+print votes
+
+valid_issueid = re.compile('\w+$').match
+
+def error(mess):
+ print mess
+ sys.exit(1)
+
+def main(args=None):
+ if args is None:
+ args = sys.argv[1:]
+ if not args:
+ error("Usage: vote issueid [arguments]")
+ issueid, args = args[0], args[1:]
+ if not valid_issueid(issueid):
+ error("Invalid issue id")
+
+ issuefolder = os.path.join(votes, issueid)
+ if not os.path.isdir(issuefolder):
+ error("Invalid issue id")
+
+ if not os.access(issuefolder, os.W_OK):
+ error("Voting is closed")
+
+ issueschema = os.path.join(votes, issueid+'.py')
+ if not os.path.exists(issueschema):
+ error("Invalid issue id")
+
+ execfile(issueschema, globals())
+
+ uname = pwd.getpwuid(os.geteuid())[0]
+ if args:
+ validate(issuefolder, args)
+ open(os.path.join(issuefolder, uname), 'w').write('\n'.join(args))
+
+ if os.access(issuefolder, os.R_OK):
+ count(issuefolder, uname)
+ else:
+ print 'Vote results are not available'
+
+if __name__ == '__main__':
+ main()
Property changes on: zope-foundation-admin/trunk/vote/vote.py
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
More information about the Checkins
mailing list