def create_tokend_file(tokend, reg, elid): outf = None try: import hts hh = hts.HTS(elid) fn = 'tokend.' fn += time.strftime('%Y%m%d%H%M%S') out = '' for el in tokend: if hh.haaletanud(el): out += el out += '\t' out += '\t'.join(tokend[el]) out += '\n' if len(out) != 0: out = elid + '\n' + out out = '1\n' + out filename = reg.path(['hts', 'output', fn]) outf = file(filename, 'w') outf.write(out) outf.close() ksum.store(filename) outf = None finally: if (outf != None): outf.close()
def create_tokend_file(tokend, reg, elid): outf = None try: import hts hh = hts.HTS(elid) fn = "tokend." fn += time.strftime("%Y%m%d%H%M%S") out = "" for el in tokend: if hh.haaletanud(el): out += el out += "\t" out += "\t".join(tokend[el]) out += "\n" if out: out = elid + "\n" + out out = "1\n" + out filename = reg.path(["hts", "output", fn]) outf = file(filename, "w") outf.write(out) outf.close() ksum.store(filename) outf = None finally: if outf is not None: outf.close()
def __write_masinloetav(self, jaoskonnad): # sortimine: # Kov-jsk numbriliselt -> hääletajad ridade kaupa ret = 0 kov_jsk = jaoskonnad.keys() kov_jsk.sort(jaoskonnad_cmp) of = htscommon.LoggedFile(\ self._reg.path(\ ['hts', 'output', evcommon.ELECTORSLIST_FILE]), self) of.open('w') of.write(evcommon.VERSION + "\n") of.write(self._elid + "\n") for jsk in kov_jsk: if (len(jaoskonnad[jsk])): jaoskonnad[jsk].sort(reanumber_cmp) for voter in jaoskonnad[jsk]: outline = '%s\t%s\t%s\t%s\t%s\n' % ( voter['jaoskond_omavalitsus'], voter['jaoskond'], voter['reanumber'], voter['isikukood'], voter['nimi']) of.write(outline) ret = ret + 1 of.close() ksum.store(of.name()) return ret
def create_tokend_file(tokend, reg, elid): outf = None try: import hts hh = hts.HTS(elid) fn = 'tokend.' fn += time.strftime('%Y%m%d%H%M%S') out = '' for el in tokend: if hh.haaletanud(el): out += el out += '\t' out += '\t'.join(tokend[el]) out += '\n' if out: out = elid + '\n' + out out = '1\n' + out filename = reg.path(['hts', 'output', fn]) outf = file(filename, 'w') outf.write(out) outf.close() ksum.store(filename) outf = None finally: if outf is not None: outf.close()
def _write_result(self): electionresult_file = \ self._reg.path(['hlr', 'output', evcommon.ELECTIONRESULT_FILE]) out_f = file(electionresult_file, 'w') out_f.write(evcommon.VERSION + '\n' + self._elid + '\n') self.__cnt.output(out_f) out_f.close() ksum.store(electionresult_file) print "Hääled (%d) on loetud." % self.__cnt.count()
def tyhista_ennista(self, filename): tmp_tyhis_f = None try: bdocpython.initialize() bconf = bdocpythonutils.BDocConfig() bconf.load(Election().get_bdoc_conf()) result = regrights.kontrolli_volitusi(self._elid, filename, "TYHIS", bconf) if not result[0]: self._errmsg = "Tühistus-/ennistusnimekirja volituste " "kontroll andis negatiivse tulemuse: " self._errmsg += result[1] raise Exception(self._errmsg) _signercode = result[2] tmp_tyhis_f = bdocpythonutils.get_doc_content_file(filename) rl = revocationlists.RevocationList() rl.attach_elid(self._elid) rl.attach_logger(evlog.AppLog()) if not rl.check_format(tmp_tyhis_f, "Kontrollin tühistus-/ennistusnimekirja: "): self._errmsg = "Vigase formaadiga tühistus-/ennistusnimekiri" raise Exception(self._errmsg) g_l = None b_l = None act = "" report = [] if rl.revoke: act = "tühistamine" g_l, b_l = self.__tyhista_haaled(rl.rev_list, _signercode) else: act = "ennistamine" g_l, b_l = self.__ennista_haaled(rl.rev_list, _signercode) for el in b_l: el.append(act + " nurjus") report.append(el) for el in g_l: el.append(act + " õnnestus") report.append(el) fn = self._reg.path(["hts", "output", evcommon.REVREPORT_FILE]) self.__save_list(report, fn) ksum.store(fn) return len(rl.rev_list), len(g_l), len(b_l) finally: if tmp_tyhis_f != None: os.unlink(tmp_tyhis_f)
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)
def _write_result(self): result_dist_fn = self._reg.path(\ ['hlr', 'output', evcommon.ELECTIONRESULT_FILE]) out_f = file(result_dist_fn, 'w') out_f.write(evcommon.VERSION + '\n' + self._elid + '\n') self.__cnt.outputdist(out_f) out_f.close() ksum.store(result_dist_fn) result_stat_fn = self._reg.path(\ ['hlr', 'output', evcommon.ELECTIONRESULT_STAT_FILE]) out_f = file(result_stat_fn, 'w') out_f.write(evcommon.VERSION + '\n' + self._elid + '\n') self.__cnt.outputstat(out_f) out_f.close() ksum.store(result_stat_fn) print "Hääled (%d) on loetud." % self.__cnt.count()
def lugemisperioodi(self): r_votes = 0 v_votes = 0 self._reg.ensure_no_key(\ ['hts', 'output', evcommon.ELECTIONS_RESULT_FILE]) vf = htscommon.LoggedFile(\ self._reg.path(\ ['hts', 'output', evcommon.ELECTIONS_RESULT_FILE]), self) vf.open('a') vf.write(evcommon.VERSION + "\n") vf.write(self._elid + "\n") tic = ticker.Counter(\ 'Hääli:', '\tKehtivaid: %d\tAvalduse alusel tühistatuid: %d') tic.start('Koostan loendamisele minevate häälte nimekirja') for path in os.walk(self._reg.path(['hts', 'votes'])): root = path[0] for vote_file in path[2]: if htscommon.VALID_VOTE_PATTERN.match(vote_file): v_votes += 1 res = self.__handle_valid(root, vote_file) vf.write('\t'.join(res) + '\n') elif htscommon.USERREVOKED_VOTE_PATTERN.match(vote_file): r_votes += 1 self.__handle_userrevoked(root, vote_file) elif htscommon.AUTOREVOKED_VOTE_PATTERN.match(vote_file): pass elif htscommon.REVOKE_REASON_PATTERN.match(vote_file): pass else: pass tic.tick(1, v_votes, r_votes) tic.finish() vf.close() ksum.store(vf.name()) return v_votes, r_votes
def lugemisperioodi(self): r_votes = 0 v_votes = 0 a_votes = 0 b_votes = 0 self._reg.ensure_no_key( ['hts', 'output', evcommon.ELECTIONS_RESULT_FILE]) vf = htscommon.LoggedFile( self._reg.path( ['hts', 'output', evcommon.ELECTIONS_RESULT_FILE])) vf.open('a') vf.write(evcommon.VERSION + "\n") vf.write(self._elid + "\n") l1_lines = [] l2_lines = [] l3_lines = [] tic = ticker.Counter( 'Hääli:', '\tKehtivaid: %d\tAvalduse alusel tühistatuid: %d') tic.start('Koostan loendamisele minevate häälte nimekirja') nowstr = time.strftime("%Y%m%d%H%M%S") for path in os.walk(self._reg.path(['hts', 'votes'])): root = path[0] code = root.split('/').pop() if not formatutil.is_isikukood(code): continue log_lines = self.get_log_lines(root, path[2]) if len(log_lines) > 0: log_lines.sort(key=itemgetter(0), reverse=True) new = None for lines in log_lines: old = lines[0].rsplit('\t', 2)[0] notime = old.split('\t', 1)[1] fn = lines[1] voteforres = self.get_vote_for_result(old, fn) if voteforres: l1_lines.append(old) if new is None: ur, reason, tim = self.is_user_revoked(code) if ur: l2_lines.append("%s\t%s\t%s" % (tim, notime, reason)) r_votes += 1 else: vf.write('\t'.join(voteforres) + '\n') v_votes += 1 l3_lines.append("%s\t%s" % (nowstr, notime)) else: autor = new.split('\t') l2_lines.append("%s\t%s\tkorduv e-hääl: %s" % (autor[0], notime, autor[1])) a_votes += 1 new = old else: b_votes += 1 tic.tick(1, v_votes, r_votes) vf.close() ksum.store(vf.name()) tic.finish() l1_lines.sort() self.save_log(l1_lines, '1') l2_lines.sort() self.save_log(l2_lines, '2') l3_lines.sort() self.save_log(l3_lines, '3') return v_votes, r_votes, a_votes, b_votes
def tyhista_ennista(self, filename): tmp_tyhis_f = None try: bdocpython.initialize() bconf = bdocpythonutils.BDocConfig() bconf.load(Election().get_bdoc_conf()) result = regrights.kontrolli_volitusi(\ self._elid, filename, 'TYHIS', bconf) if not result[0]: self._errmsg = \ 'Tühistus-/ennistusnimekirja volituste ' \ 'kontroll andis negatiivse tulemuse: ' self._errmsg += result[1] raise Exception(self._errmsg) _signercode = result[2] tmp_tyhis_f = bdocpythonutils.get_doc_content_file(filename) rl = revocationlists.RevocationList() rl.attach_elid(self._elid) rl.attach_logger(evlog.AppLog()) if not rl.check_format(tmp_tyhis_f, \ 'Kontrollin tühistus-/ennistusnimekirja: '): self._errmsg = 'Vigase formaadiga tühistus-/ennistusnimekiri' raise Exception(self._errmsg) g_l = None b_l = None act = '' report = [] if rl.revoke: act = 'tühistamine' g_l, b_l = self.__tyhista_haaled(rl.rev_list, _signercode) else: act = 'ennistamine' g_l, b_l = self.__ennista_haaled(rl.rev_list, _signercode) for el in b_l: el.append(act + ' nurjus') report.append(el) for el in g_l: el.append(act + ' õnnestus') report.append(el) fn = self._reg.path(['hts', 'output', evcommon.REVREPORT_FILE]) self.__save_list(report, fn) ksum.store(fn) return len(rl.rev_list), len(g_l), len(b_l) finally: if tmp_tyhis_f != None: os.unlink(tmp_tyhis_f)
def lugemisperioodi(self): r_votes = 0 v_votes = 0 a_votes = 0 b_votes = 0 self._reg.ensure_no_key( ['hts', 'output', evcommon.ELECTIONS_RESULT_FILE]) vf = htscommon.LoggedFile( self._reg.path(['hts', 'output', evcommon.ELECTIONS_RESULT_FILE])) vf.open('a') vf.write(evcommon.VERSION + "\n") vf.write(self._elid + "\n") l1_lines = [] l2_lines = [] l3_lines = [] tic = ticker.Counter( 'Hääli:', '\tKehtivaid: %d\tAvalduse alusel tühistatuid: %d') tic.start('Koostan loendamisele minevate häälte nimekirja') nowstr = time.strftime("%Y%m%d%H%M%S") for path in os.walk(self._reg.path(['hts', 'votes'])): root = path[0] code = root.split('/').pop() if not formatutil.is_isikukood(code): continue log_lines = self.get_log_lines(root, path[2]) if len(log_lines) > 0: log_lines.sort(key=itemgetter(0), reverse=True) new = None for lines in log_lines: old = lines[0].rsplit('\t', 2)[0] notime = old.split('\t', 1)[1] fn = lines[1] voteforres = self.get_vote_for_result(old, fn) if voteforres: l1_lines.append(old) if new is None: ur, reason, tim = self.is_user_revoked(code) if ur: l2_lines.append("%s\t%s\t%s" % (tim, notime, reason)) r_votes += 1 else: vf.write('\t'.join(voteforres) + '\n') v_votes += 1 l3_lines.append("%s\t%s" % (nowstr, notime)) else: autor = new.split('\t') l2_lines.append("%s\t%s\tkorduv e-hääl: %s" % (autor[0], notime, autor[1])) a_votes += 1 new = old else: b_votes += 1 tic.tick(1, v_votes, r_votes) vf.close() ksum.store(vf.name()) tic.finish() l1_lines.sort() self.save_log(l1_lines, '1') l2_lines.sort() self.save_log(l2_lines, '2') l3_lines.sort() self.save_log(l3_lines, '3') return v_votes, r_votes, a_votes, b_votes