本文整理汇总了Python中election.Election类的典型用法代码示例。如果您正苦于以下问题:Python Election类的具体用法?Python Election怎么用?Python Election使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Election类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main_function
def main_function():
if len(sys.argv) != 3:
usage()
el_id = sys.argv[1]
_if = sys.argv[2]
if not check_file(_if):
print "Faili " + _if + " ei eksisteeri"
sys.exit(1)
if not ksum.has(_if):
print "Faili " + ksum.filename(_if) + " ei eksisteeri"
sys.exit(1)
if not ksum.check(_if):
print "Kontrollsumma ei klapi"
sys.exit(1)
reg = Election().get_sub_reg(el_id)
reg.ensure_key(['hlr', 'input'])
dst = reg.path(['hlr', 'input', 'votes'])
os.system("cp " + _if + " " + dst)
os.system("cp " + ksum.filename(_if) + " " + ksum.filename(dst))
Election().config_hlr_input_elid_done(el_id)
示例2: main
def main():
# Run Experiments
start = time()
for cname in sorted(CONTESTS):
for t in xrange(NTRIALS):
cattr = CONTESTS[cname]
c, g, a, params = cattr['c'], cattr['g'], cattr['a'], cattr['p']
contest = Contest(c, g, a, params)
e = Election([contest])
e.run()
for aname in sorted(AUDITS):
outcome, nballots = e.audit(AUDITS[aname])[0] # assumes 1 contest
if outcome != contest.outcome[0]:
results[cname][aname]['e'] += 1
results[cname][aname]['n'] += nballots
end = time()
# Report Results
for cname in sorted(CONTESTS):
print cname
for aname in sorted(AUDITS):
avg_nballots = results[cname][aname]['n'] / float(NTRIALS)
avg_nerrors = results[cname][aname]['e'] / float(NTRIALS)
print '\t%s\t%f\t%f' % (aname, avg_nballots, avg_nerrors)
print 'Runtime: ' + str(end - start)
示例3: __create_vote_key
def __create_vote_key(self):
reg = Election().get_root_reg()
while True:
vote_id = _generate_vote_id()
key = htscommon.get_verification_key(vote_id)
if not reg.check(key):
reg.create_key(key)
return vote_id
示例4: add_hts_files_to_table
def add_hts_files_to_table(elid, table):
import os
reg = Election().get_root_reg()
if reg.check(['questions', elid, 'hts', 'output']):
o_files = os.listdir(reg.path(['questions', elid, 'hts', 'output']))
for of in o_files:
if of.find("tokend.") == 0 and of.find(".sha1") == -1:
table.add_file(EvFile(of, of, ['questions', elid, 'hts', 'output']))
示例5: do_view_election_description
def do_view_election_description(elid):
el_reg = Election().get_sub_reg(elid)
try:
description = el_reg.read_string_value(['common'], 'description').value
except IOError:
description = uiutil.NOT_DEFINED_STR
except LookupError:
description = uiutil.NOT_DEFINED_STR
print "Valimiste %s kirjeldus: %s\n" % (elid, description)
示例6: _count_votes
def _count_votes(self, elid):
user_key = htscommon.get_user_key(self.signercode)
if Election().get_sub_reg(elid).check(user_key):
keys = Election().get_sub_reg(elid).list_keys(user_key)
try:
keys.remove(htscommon.VOTE_VERIFICATION_ID_FILENAME)
except ValueError:
pass # No "otp" file
return len(keys)
return 0
示例7: purge_otp
def purge_otp(reg, otp):
otp_key = htscommon.get_verification_key(otp)
voter = reg.read_string_value(otp_key, "voter").value.rstrip()
voter_key = htscommon.get_user_key(voter)
elids = reg.read_string_value(otp_key, "elids").value.rstrip().split("\t")
for elid in elids:
sreg = Election().get_sub_reg(elid)
if sreg.check(voter_key + [htscommon.VOTE_VERIFICATION_ID_FILENAME]):
sreg.delete_value(voter_key, htscommon.VOTE_VERIFICATION_ID_FILENAME)
reg.ensure_no_key(otp_key)
示例8: main_function
def main_function():
try:
election_ids = Election().get_questions()
if len(election_ids) == 0:
print "Sätteid pole laaditud"
else:
election_ids.sort()
for el_i in election_ids:
process_elid(el_i)
except Exception as ex:
print 'Viga valijanimekirjade uuenduste ajaloo kuvamisel: ' + str(ex)
sys.exit(1)
示例9: __init__
class EvFile:
def __init__(self, filename, uiname, regprefix):
self.__filename = filename
self.__uiname = uiname
self.__regprefix = regprefix
self.__reg = Election().get_root_reg()
def exists(self):
return self.__reg.check(self.__regprefix + [self.__filename])
def path(self):
return self.__reg.path(self.__regprefix + [self.__filename])
def name(self):
return self.__uiname
示例10: __init__
def __init__(self, elid):
self._elid = elid
self._errmsg = None
self._reg = Election().get_sub_reg(self._elid)
self._revlog = evlog.Logger()
self._revlog.set_format(evlog.RevLogFormat())
self._revlog.set_logs(self._reg.path(['common', evcommon.REVLOG_FILE]))
示例11: main_function
def main_function():
if len(sys.argv) != 3:
usage()
el_id = sys.argv[1]
_if = sys.argv[2]
if not ksum.check(_if, True):
print "Kontrollsumma ei klapi"
sys.exit(1)
reg = Election().get_sub_reg(el_id)
reg.ensure_key(['hlr', 'input'])
dst = reg.path(['hlr', 'input', 'votes'])
shutil.copy(_if, dst)
ksum.store(dst)
Election().config_hlr_input_elid_done(el_id)
示例12: __load_bdoc
def __load_bdoc(self, elid):
voter_key = htscommon.get_user_key(self._voter_code)
sreg = Election().get_sub_reg(elid)
for votefile in sreg.list_keys(voter_key):
if htscommon.VALID_VOTE_PATTERN.match(votefile):
bdoc = bdocpythonutils.BDocContainer()
bdoc.load(sreg.path(voter_key + [votefile]))
bdoc.validate(bdocpythonutils.ManifestProfile("TM"))
self._voter = htscommon.get_votefile_voter(votefile)
break
if not bdoc:
evlog.log_error("No valid BDOC found for voter %s using vote ID %s" % \
(self._voter, self._vote_id))
raise HTSVerifyException, evcommon.VERIFY_ERROR
return bdoc
示例13: _revoke_vote_id
def _revoke_vote_id(voter_code):
elec = Election()
otps = set()
for quest in elec.get_questions():
reg = elec.get_sub_reg(quest)
key = htscommon.get_user_key(voter_code)
if reg.check(key + [htscommon.VOTE_VERIFICATION_ID_FILENAME]):
otp = reg.read_string_value(key, \
htscommon.VOTE_VERIFICATION_ID_FILENAME)
otps.add(otp.value)
evlog.log("Revoking vote ID %s" % otp)
if not _delete_vote_id(otp.value):
evlog.log_error("No such vote-ID: %s" % otp)
otp.delete()
if len(otps) > 1:
evlog.log_error("The voter %s had multiple vote ID-s: %s" % \
(voter_code, ", ".join(otps)))
示例14: do_set_hts_conf
def do_set_hts_conf():
reg = Election().get_root_reg()
if reg.check(['common', 'htsip']):
try:
def_ip_port = reg.read_ipaddr_value(\
['common'], 'htsip').value.split(":")
def_ip = def_ip_port[0]
if len(def_ip_port) > 1:
try:
def_port = int(def_ip_port[-1])
except ValueError:
def_port = 80
else:
def_port = 80
except:
def_ip = None
def_port = 80
else:
def_ip = None
def_port = 80
hts_ip = uiutil.ask_string("Sisesta HTSi IP aadress", None, None, def_ip)
hts_port = uiutil.ask_int("Sisesta HTSi port", def_port, 0, 65535)
if reg.check(['common', 'htspath']):
try:
def_url = reg.read_string_value(['common'], 'htspath').value
except:
def_url = None
else:
def_url = None
hts_url = uiutil.ask_string("Sisesta HTSi URL", None, None, def_url)
try:
def_verify = Election().get_hts_verify_path()
except:
def_verify = None
hts_verify = uiutil.ask_string("Sisesta HTSi hääle kontrolli URL", \
None, None, def_verify)
cmd = "%s set %s:%d %s %s" % (SCRIPT_CONFIG_HTH, hts_ip, hts_port, \
hts_url, hts_verify)
os.system(cmd)
示例15: __load_bdoc
def __load_bdoc(self, elid):
voter_key = htscommon.get_user_key(self._voter_code)
sreg = Election().get_sub_reg(elid)
vote_files = []
for vfile in sreg.list_keys(voter_key):
if htscommon.VALID_VOTE_PATTERN.match(vfile):
vote_files.append(vfile)
vote_files.sort()
latest = vote_files.pop()
if latest:
bdoc = htsbase.get_vote(sreg.path(voter_key + [latest]))
if not bdoc:
evlog.log_error("No valid BDOC found for voter %s using vote ID %s" % \
(self._voter_code, self._vote_id))
raise HTSVerifyException, evcommon.VERIFY_ERROR
return bdoc