Beispiel #1
0
    def _create_user(self, code):
        """     Loome kasutaja, kui teda veel pole
        """
        if not formatutil.is_isikukood(code):
            raise Exception('Vigane isikukood')

        self.reg.ensure_key([code, 'rights'])
Beispiel #2
0
    def _dataline_form(self, lst):  # pylint: disable=R0911
        if len(lst) != 9:
            self.errform('Kirjete arv real')
            return False

        if not formatutil.is_isikukood(lst[0]):
            self.errform('Isikukood')
            return False

        if not formatutil.is_nimi(lst[1]):
            self.errform('Valija nimi')
            return False

        if not lst[2] in ['lisamine', 'kustutamine']:
            self.errform('Kirje tüüp')
            return False

        if not formatutil.is_jaoskonna_number_kov_koodiga(\
                lst[3], lst[4]):
            self.errform('Valimisjaoskonna number KOV koodiga')
            return False

        if not formatutil.is_ringkonna_number_kov_koodiga(lst[5], lst[6]):
            self.errform('Ringkonna number KOV koodiga')
            return False

        if not formatutil.is_rea_number_voi_tyhi(lst[7]):
            self.errform('Rea number')
            return False

        return True
Beispiel #3
0
    def _dataline_form(self, lst): # pylint: disable=R0911
        if len(lst) != 9:
            self.errform('Kirjete arv real')
            return False

        if not formatutil.is_isikukood(lst[0]):
            self.errform('Isikukood')
            return False

        if not formatutil.is_nimi(lst[1]):
            self.errform('Valija nimi')
            return False

        if not lst[2] in ['lisamine', 'kustutamine']:
            self.errform('Kirje tüüp')
            return False

        if not formatutil.is_jaoskonna_number_kov_koodiga(\
                lst[3], lst[4]):
            self.errform('Valimisjaoskonna number KOV koodiga')
            return False

        if not formatutil.is_ringkonna_number_kov_koodiga(lst[5], lst[6]):
            self.errform('Ringkonna number KOV koodiga')
            return False

        if not formatutil.is_rea_number_voi_tyhi(lst[7]):
            self.errform('Rea number')
            return False

        return True
Beispiel #4
0
    def _create_user(self, code):
        """     Loome kasutaja, kui teda veel pole
        """
        if not formatutil.is_isikukood(code):
            raise Exception('Vigane isikukood')

        self.reg.ensure_key([code, 'rights'])
Beispiel #5
0
    def remuser(self, code):
        """
        Eemaldab ühe kasutaja volituste failist
        """
        if not formatutil.is_isikukood(code):
            raise Exception('Vigane isikukood')

        return self.reg.ensure_no_key([code])
Beispiel #6
0
    def remuser(self, code):
        """
        Eemaldab ühe kasutaja volituste failist
        """
        if not formatutil.is_isikukood(code):
            raise Exception('Vigane isikukood')

        return self.reg.ensure_no_key([code])
Beispiel #7
0
    def descr(self, code):
        """
        Tagastab tegelase kohta käiva kirjelduse
        """
        if not formatutil.is_isikukood(code):
            raise Exception('Vigane isikukood')

        if self.reg.check([code, 'description']):
            return self.reg.read_string_value([code], 'description').value

        return 'Andmed puuduvad'
Beispiel #8
0
    def descr(self, code):
        """
        Tagastab tegelase kohta käiva kirjelduse
        """
        if not formatutil.is_isikukood(code):
            raise Exception('Vigane isikukood')

        if self.reg.check([code, 'description']):
            return self.reg.read_string_value([code], 'description').value
        else:
            return 'Andmed puuduvad'
Beispiel #9
0
    def has(self, code, right):
        """
        Kas koodil on vastav volitus
        """

        if not formatutil.is_isikukood(code):
            raise Exception('Vigane isikukood')

        new_right = right.upper()
        if not _proper_right(new_right):
            raise Exception('Vigane volitus')

        if not self.reg.check([code, 'rights', new_right]):
            return False
        return True
Beispiel #10
0
    def has(self, code, right):
        """
        Kas koodil on vastav volitus
        """

        if not formatutil.is_isikukood(code):
            raise Exception('Vigane isikukood')

        new_right = right.upper()
        if not _proper_right(new_right):
            raise Exception('Vigane volitus')

        if not self.reg.check([code, 'rights', new_right]):
            return False
        return True
Beispiel #11
0
    def status_verify(self):
        import bdocconfig

        tic = ticker.Counter('Hääli:', '\tKorras: %d\tVigaseid: %d')
        tic.start('Hääletuse \"%s\" olekuanalüüs' % self._elid)
        conf = bdocconfig.BDocConfig()
        conf.load(Election().get_bdoc_conf())

        for path in os.walk(self._reg.path(['hts', 'votes'])):
            root = path[0]
            code = root.split('/').pop()

            if not formatutil.is_isikukood(code):
                continue

            user_revoked = False

            valid_files = []
            for vote_file in path[2]:
                if htscommon.REVOKE_REASON_PATTERN.match(vote_file):
                    user_revoked = True
                    continue
                if htscommon.VOTE_VERIFICATION_ID_FILENAME == vote_file:
                    continue
                if htscommon.PARTIAL_VOTE_PATTERN.match(vote_file):
                    continue
                if not htscommon.VALID_VOTE_PATTERN.match(vote_file):
                    self.__sti.unknown_file(1, '\tTundmatu fail: ' + code + '/' + vote_file)
                    continue
                valid_files.append(vote_file)

            if len(valid_files) > 0:
                valid_files.sort()
                latest = valid_files.pop()
                res, msg = self.do_verify(root, latest, conf, code)
                if not user_revoked:
                    self.__sti.valid_vote(1, msg, res)
                else:
                    self.__sti.userrevoked_vote(1, msg, res)
                self.__sti.autorevoked_vote(len(valid_files), None, True)
            else:
                self.__sti.unknown_file(1, '\tHäälteta kaust: ' + code)
                continue

            tic.tick(1 + len(valid_files), self.__sti.ok_count(), self.__sti.bad_count())

        tic.finish(True, self.__sti.ok_count(), self.__sti.bad_count())
Beispiel #12
0
    def status_verify(self):
        import bdocconfig

        tic = ticker.Counter('Hääli:', '\tKorras: %d\tVigaseid: %d')
        tic.start('Hääletuse \"%s\" olekuanalüüs' % self._elid)
        conf = bdocconfig.BDocConfig()
        conf.load(Election().get_bdoc_conf())

        for path in os.walk(self._reg.path(['hts', 'votes'])):
            root = path[0]
            code = root.split('/').pop()

            if not formatutil.is_isikukood(code):
                continue

            user_revoked = False

            valid_files = []
            for vote_file in path[2]:
                if htscommon.REVOKE_REASON_PATTERN.match(vote_file):
                    user_revoked = True
                    continue
                if htscommon.VOTE_VERIFICATION_ID_FILENAME == vote_file:
                    continue
                if htscommon.PARTIAL_VOTE_PATTERN.match(vote_file):
                    continue
                if not htscommon.VALID_VOTE_PATTERN.match(vote_file):
                    self.__sti.unknown_file(
                        1, '\tTundmatu fail: ' + code + '/' + vote_file)
                    continue
                valid_files.append(vote_file)

            if len(valid_files) > 0:
                valid_files.sort()
                latest = valid_files.pop()
                res, msg = self.do_verify(root, latest, conf, code)
                if not user_revoked:
                    self.__sti.valid_vote(1, msg, res)
                else:
                    self.__sti.userrevoked_vote(1, msg, res)
                self.__sti.autorevoked_vote(len(valid_files), None, True)
            else:
                self.__sti.unknown_file(1, '\tHäälteta kaust: ' + code)

            tic.tick(1, self.__sti.ok_count(), self.__sti.bad_count())

        tic.finish()
Beispiel #13
0
    def remove(self, code, right):
        """
        Võtab kasutajalt volituse
        """

        if not formatutil.is_isikukood(code):
            raise Exception('Vigane isikukood')

        new_right = right.upper()
        if not _proper_right(new_right):
            raise Exception('Vigane volitus')

        if self.has(code, new_right):
            self.reg.delete_value([code, 'rights'], new_right)
            return True

        return False
Beispiel #14
0
    def listuser(self, code):
        """
        Ainult konkreetse kasutaja õigused
        """
        if not formatutil.is_isikukood(code):
            raise Exception('Vigane isikukood')

        ret = ''
        if self.reg.check([code]):
            ret += code + ' (%s)' % self.descr(code)
            sub_list = self.reg.list_keys([code, 'rights'])
            if len(sub_list) > 0:
                for _s in sub_list:
                    ret += '\n\t' + G_DESCS[_s]
            else:
                ret += '\n\tVolitused puuduvad'
        return ret.strip()
Beispiel #15
0
    def remove(self, code, right):
        """
        Võtab kasutajalt volituse
        """

        if not formatutil.is_isikukood(code):
            raise Exception('Vigane isikukood')

        new_right = right.upper()
        if not _proper_right(new_right):
            raise Exception('Vigane volitus')

        if self.has(code, new_right):
            self.reg.delete_value([code, 'rights'], new_right)
            return True

        return False
Beispiel #16
0
    def listuser(self, code):
        """
        Ainult konkreetse kasutaja õigused
        """
        if not formatutil.is_isikukood(code):
            raise Exception('Vigane isikukood')

        ret = ''
        if self.reg.check([code]):
            ret += code + ' (%s)' % self.descr(code)
            sub_list = self.reg.list_keys([code, 'rights'])
            if len(sub_list) > 0:
                for _s in sub_list:
                    ret += '\n\t' + G_DESCS[_s]
            else:
                ret += '\n\tVolitused puuduvad'
        return ret.strip()
Beispiel #17
0
    def tyhistusperioodi(self):

        vc_valid = 0
        vc_autor = 0

        jaoskonnad = {}
        jaoskonnad_rev = {}
        self.__load_jaoskonnad(jaoskonnad, jaoskonnad_rev)
        tic = ticker.Counter(
            'Hääli:', '\tArvesse minevaid: %d\tKorduvaid: %d')
        tic.start('Koostan e-hääletanute nimekirja:')

        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))
                latest = log_lines.pop()
                vc_autor += len(log_lines)
                vc_valid += 1

                voter = htscommon.get_logline_voter(latest[0])
                jaoskonnad_rev['%s\t%s\t%s\t%s' % (
                    voter['jaoskond_omavalitsus'],
                    voter['jaoskond'], voter['ringkond_omavalitsus'],
                    voter['ringkond'])].append(voter)

            tic.tick(1, vc_valid, vc_autor)

        tic.finish()

        valijaid1 = self.__write_masinloetav(jaoskonnad_rev)
        valijaid2 = self.__write_inimloetav(jaoskonnad)
        if not (valijaid1 == valijaid2):
            self._errmsg = 'Viga nimekirjade koostamisel'
            raise Exception(self._errmsg)

        return vc_valid + vc_autor, vc_autor, valijaid1
Beispiel #18
0
    def tyhistusperioodi(self):

        vc_valid = 0
        vc_autor = 0

        jaoskonnad = {}
        jaoskonnad_rev = {}
        self.__load_jaoskonnad(jaoskonnad, jaoskonnad_rev)
        tic = ticker.Counter('Hääli:', '\tArvesse minevaid: %d\tKorduvaid: %d')
        tic.start('Koostan e-hääletanute nimekirja:')

        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))
                latest = log_lines.pop()
                vc_autor += len(log_lines)
                vc_valid += 1

                voter = htscommon.get_logline_voter(latest[0])
                jaoskonnad_rev['%s\t%s\t%s\t%s' %
                               (voter['jaoskond_omavalitsus'],
                                voter['jaoskond'],
                                voter['ringkond_omavalitsus'],
                                voter['ringkond'])].append(voter)

            tic.tick(1, vc_valid, vc_autor)

        tic.finish()

        valijaid1 = self.__write_masinloetav(jaoskonnad_rev)
        valijaid2 = self.__write_inimloetav(jaoskonnad)
        if not (valijaid1 == valijaid2):
            self._errmsg = 'Viga nimekirjade koostamisel'
            raise Exception(self._errmsg)

        return vc_valid + vc_autor, vc_autor, valijaid1
Beispiel #19
0
    def dataline(self, line):
        lst = line.split('\t')
        if not len(lst) == 3:
            self.errform('Kirjete arv real')
            return False

        if not formatutil.is_isikukood(lst[0]):
            self.errform('Vigase vorminguga isikukood')
            return False

        if not formatutil.is_nimi(lst[1]):
            self.errform('Nimi')
            return False

        if not formatutil.is_pohjus(lst[2]):
            self.errform('Põhjus')
            return False

        return True
Beispiel #20
0
    def dataline(self, line):
        lst = line.split('\t')
        if not len(lst) == 3:
            self.errform('Kirjete arv real')
            return False

        if not formatutil.is_isikukood(lst[0]):
            self.errform('Vigase vorminguga isikukood')
            return False

        if not formatutil.is_nimi(lst[1]):
            self.errform('Nimi')
            return False

        if not formatutil.is_pohjus(lst[2]):
            self.errform('Põhjus')
            return False

        return True
Beispiel #21
0
    def status_noverify(self):
        for path in os.walk(self._reg.path(['hts', 'votes'])):
            root = path[0]
            code = root.split('/').pop()

            if not formatutil.is_isikukood(code):
                continue

            user_revoked = False
            vc = 0
            for vote_file in path[2]:
                if htscommon.REVOKE_REASON_PATTERN.match(vote_file):
                    user_revoked = True
                if htscommon.VALID_VOTE_PATTERN.match(vote_file):
                    vc += 1

            if vc > 0:
                if not user_revoked:
                    self.__sti.valid_vote(1, None, True)
                else:
                    self.__sti.userrevoked_vote(1, None, True)
                self.__sti.autorevoked_vote(vc - 1, None, True)
Beispiel #22
0
    def status_noverify(self):
        for path in os.walk(self._reg.path(['hts', 'votes'])):
            root = path[0]
            code = root.split('/').pop()

            if not formatutil.is_isikukood(code):
                continue

            user_revoked = False
            vc = 0
            for vote_file in path[2]:
                if htscommon.REVOKE_REASON_PATTERN.match(vote_file):
                    user_revoked = True
                if htscommon.VALID_VOTE_PATTERN.match(vote_file):
                    vc += 1

            if vc > 0:
                if not user_revoked:
                    self.__sti.valid_vote(1, None, True)
                else:
                    self.__sti.userrevoked_vote(1, None, True)
                self.__sti.autorevoked_vote(vc - 1, None, True)
Beispiel #23
0
    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
Beispiel #24
0
    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
Beispiel #25
0
 def has_voter(self, voter_id):
     if not formatutil.is_isikukood(voter_id):
         return False
     return self.__has_voter(voter_id)
Beispiel #26
0
 def has_voter(self, voter_id):
     if not formatutil.is_isikukood(voter_id):
         return False
     return self.__has_voter(voter_id)