Example #1
0
def execute():
    _state = election.ElectionState().get()
    if _state == election.ETAPP_TYHISTUS:
        qlist = election.Election().get_questions()
        for el in qlist:
            print el
            htsdisp.start_revocation(el)
    elif _state == election.ETAPP_LUGEMINE:
        qlist = election.Election().get_questions()
        for el in qlist:
            print el
            htsdisp.start_tabulation(el)
    else:
        pass
Example #2
0
def _execute_prepare_stop():
    import datetime

    if election.ElectionState().election_on():
        election.Election().refuse_new_voters()
        sched = scheduled(COMMAND_PREPARE_STOP)
        minutes = stop_grace_period()
        if not sched or not minutes:
            return
        _, time = sched

        dt = datetime.datetime.strptime(time, TIME_FORMAT)
        dt += datetime.timedelta(minutes=minutes)
        schedule(COMMAND_STOP, dt.timetuple())
Example #3
0
def _main(expected, cmd):
    if election.ElectionState().get() == int(expected):
        print "Executing automatic command \"%s\"" % cmd
        if cmd == COMMAND_START:
            _execute_start()
        elif cmd == COMMAND_PREPARE_STOP:
            _execute_prepare_stop()
        elif cmd == COMMAND_STOP:
            _execute_stop()
        else:
            raise Exception, "Unknown command"
        _clean_reg(cmd)
        _signal_ui()
        print "Done."
    else:
        print "Unexpected state, nothing to do."
Example #4
0
def _main(expected, cmd):
    state = election.ElectionState().get()
    if state == int(expected):
        evlog.log(LOG_EXECUTING % cmd)
        if cmd == COMMAND_START:
            _execute_start()
        elif cmd == COMMAND_PREPARE_STOP:
            _execute_prepare_stop()
        elif cmd == COMMAND_STOP:
            _execute_stop()
        else:
            evlog.log_error(LOG_ERROR_UNKNOWN % cmd)
            raise Exception
        _signal_ui()
    else:
        evlog.log_error(LOG_ERROR_STATE % (cmd, state, expected))
    _clean_reg(cmd)
Example #5
0
def _execute_stop():
    if election.ElectionState().election_on():
        election.ElectionState().next()
Example #6
0
def _execute_start():
    if election.ElectionState().get() == election.ETAPP_ENNE_HAALETUST:
        election.ElectionState().next()
Example #7
0
        sreg = elec.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)

def purge_otps():
    runtime = int(time.time())
    AppLog().set_app("purgeotps.py")
    AppLog().log("Purging expired vote ID's as of %s: START" % \
            time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime(runtime)))
    try:
        reg = election.Election().get_root_reg()
        timeout = election.Election().get_verification_time() * 60
        for otp in reg.list_keys(htscommon.get_verification_key()):
            otp_key = htscommon.get_verification_key(otp)
            created = reg.read_integer_value(otp_key, "timestamp").value
            if created + timeout < runtime:
                AppLog().log("Purging expired vote ID %s" % otp)
                purge_otp(otp_key)
    except:
        AppLog().log_exception()
    finally:
        AppLog().log("Purging expired vote ID's: DONE")


if __name__ == '__main__':
    if election.ElectionState().election_on():
        purge_otps()

# vim:set ts=4 sw=4 et fileencoding=utf8:
Example #8
0
 def init_done(self):  # pylint: disable=R0201
     election.ElectionState().init()
     election.Election().init_conf_done()