当前位置: 首页>>代码示例>>Python>>正文


Python Election.path方法代码示例

本文整理汇总了Python中election.Election.path方法的典型用法代码示例。如果您正苦于以下问题:Python Election.path方法的具体用法?Python Election.path怎么用?Python Election.path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在election.Election的用法示例。


在下文中一共展示了Election.path方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main_function

# 需要导入模块: from election import Election [as 别名]
# 或者: from election.Election import path [as 别名]
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)
开发者ID:100dBsound,项目名称:evalimine,代码行数:27,代码来源:config_hlr_input.py

示例2: add_hts_files_to_table

# 需要导入模块: from election import Election [as 别名]
# 或者: from election.Election import path [as 别名]
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']))
开发者ID:IGBAnet,项目名称:evalimine,代码行数:10,代码来源:evfiles.py

示例3: __init__

# 需要导入模块: from election import Election [as 别名]
# 或者: from election.Election import path [as 别名]
class HTSBase:

    def __init__(self, elid):
        self._elid = elid
        self._errmsg = None
        self._reg = Election().get_sub_reg(self._elid)

        self._log1 = evlog.Logger()
        self._log1.set_format(evlog.EvLogFormat())
        self._log1.set_logs(self._reg.path(['common', 'log1']))

        self._log2 = evlog.Logger()
        self._log2.set_format(evlog.EvLogFormat())
        self._log2.set_logs(self._reg.path(['common', 'log2']))

        self._log3 = evlog.Logger()
        self._log3.set_format(evlog.EvLogFormat())
        self._log3.set_logs(self._reg.path(['common', 'log3']))

        self._revlog = evlog.Logger()
        self._revlog.set_format(evlog.RevLogFormat())
        self._revlog.set_logs(self._reg.path(['common', evcommon.REVLOG_FILE]))

    def _haaletanud_konf(self, isikukood):
        user_key = htscommon.get_user_key(isikukood)
        return self._reg.check(user_key) and \
                len(self._reg.list_keys(user_key)) > 0

    def haaletanud(self, isikukood):
        logi = self._log1.contains(isikukood)
        konf = self._haaletanud_konf(isikukood)
        if logi and konf:
            return True
        if (not logi) and (not konf):
            return False
        self._errmsg = 'Logifail LOG1 ja serveri olek ei ole kooskõlalised'
        raise Exception(self._errmsg)
开发者ID:100dBsound,项目名称:evalimine,代码行数:39,代码来源:htsbase.py

示例4: __init__

# 需要导入模块: from election import Election [as 别名]
# 或者: from election.Election import path [as 别名]
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
开发者ID:IGBAnet,项目名称:evalimine,代码行数:18,代码来源:evfiles.py

示例5: main_function

# 需要导入模块: from election import Election [as 别名]
# 或者: from election.Election import path [as 别名]
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)
开发者ID:Augustyn,项目名称:evalimine,代码行数:19,代码来源:config_hlr_input.py

示例6: __load_bdoc

# 需要导入模块: from election import Election [as 别名]
# 或者: from election.Election import path [as 别名]
    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
开发者ID:IGBAnet,项目名称:evalimine,代码行数:20,代码来源:htsall.py

示例7: __load_bdoc

# 需要导入模块: from election import Election [as 别名]
# 或者: from election.Election import path [as 别名]
    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
开发者ID:Cougar,项目名称:evalimine,代码行数:21,代码来源:htsall.py

示例8: __init__

# 需要导入模块: from election import Election [as 别名]
# 或者: from election.Election import path [as 别名]
class HLR:
    """
    Häältelugemisrakendus
    """

    def __init__(self, elid, tmpdir):

        self._elid = elid
        evlog.AppLog().set_app('HLR', self._elid)
        self._reg = Election().get_sub_reg(self._elid)
        self._log4 = evlog.Logger('log4')
        self._log5 = evlog.Logger('log5')
        self._log4.set_format(evlog.EvLogFormat())
        self._log5.set_format(evlog.EvLogFormat())
        self._log4.set_logs(self._reg.path(['common', 'log4']))
        self._log5.set_logs(self._reg.path(['common', 'log5']))

        tmpreg = evreg.Registry(root=tmpdir)
        tmpreg.ensure_key([])
        tmpreg.delete_sub_keys([])
        self.output_file = tmpreg.path(['decrypted_votes'])
        self.decrypt_prog = DECRYPT_PROGRAM
        self.sign_prog = SIGN_PROGRAM
        self.__cnt = ChoicesCounter()

    def __del__(self):
        try:
            os.remove(self.output_file)
        except:
            pass

    def _decrypt_votes(self, pin):

        input_file = self._reg.path(['hlr', 'input', 'votes'])
        token_name = Election().get_hsm_token_name()
        priv_key_label = Election().get_hsm_priv_key()
        pkcs11lib = Election().get_pkcs11_path()
        args = [input_file, self.output_file, \
            token_name, priv_key_label, pin, pkcs11lib]

        exit_code = 0

        try:
            exit_code = subprocess.call([self.decrypt_prog] + args)
        except OSError, oserr:
            errstr = "Häälte faili '%s' dekrüpteerimine nurjus: %s" % \
                (input_file, oserr)
            evlog.log_error(errstr)
            return False

        if exit_code == 0:
            return True

        if exit_code > 0:
            errstr2 = "Tundmatu viga"
            if exit_code in G_DECRYPT_ERRORS:
                errstr2 = G_DECRYPT_ERRORS[exit_code]

            errstr = \
                "Häälte faili '%s' dekrüpteerimine nurjus: %s (kood %d)" % \
                (input_file, errstr2, exit_code)
            evlog.log_error(errstr)
            return False

        errstr = "Häälte faili '%s' dekrüpteerimine nurjus (signaal %d)" % \
                (input_file, exit_code)
        evlog.log_error(errstr)
        return False
开发者ID:Cougar,项目名称:evalimine,代码行数:70,代码来源:hlr.py

示例9: __init__

# 需要导入模块: from election import Election [as 别名]
# 或者: from election.Election import path [as 别名]
class HTSBase:

    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]))

    def haaletanud(self, isikukood):
        latest = self.get_latest_vote(isikukood)
        return latest is not None

    def get_revoked_path(self, pc):
        user_key = htscommon.get_user_key(pc)
        return self._reg.path(user_key + ['reason'])

    def get_latest_vote(self, pc):
        user_key = htscommon.get_user_key(pc)
        if self._reg.check(user_key):
            files = self._reg.list_keys(user_key)
            votes = []
            for el in files:
                if htscommon.VALID_VOTE_PATTERN.match(el):
                    votes.append(el)
            votes.sort()
            latest = votes.pop()
            if latest:
                return htscommon.get_votefile_time(latest)

        return None

    def restore_vote(self, revline, operator):
        timest = self.get_latest_vote(revline[0])
        os.unlink(self.get_revoked_path(revline[0]))
        self._revlog.log_info(
            tegevus='ennistamine',
            isikukood=revline[0],
            nimi=revline[1],
            timestamp=timest,
            operaator=operator,
            pohjus=revline[2])

    def revoke_vote(self, revline, operator):
        timest = self.get_latest_vote(revline[0])
        nowstr = time.strftime("%Y%m%d%H%M%S", time.localtime())
        self._reg.create_string_value(
            htscommon.get_user_key(revline[0]), 'reason',
            "%s\t%s" % (nowstr, revline[2]))

        self._revlog.log_info(
            tegevus='tühistamine',
            testtime=nowstr,
            isikukood=revline[0],
            nimi=revline[1],
            timestamp=timest,
            operaator=operator,
            pohjus=revline[2])

    def is_user_revoked(self, pc):
        user_key = htscommon.get_user_key(pc)
        if self._reg.check(user_key + ['reason']):
            line = self._reg.read_string_value(user_key, 'reason').value
            data = line.split('\t')
            return True, data[1], data[0]
        return False, '', ''

    def save_log(self, lines, log):
        fn = self._reg.path(['common', 'log%s' % log])
        lf = htscommon.LoggedFile(fn)
        lf.open('w')
        lf.write(evcommon.VERSION + "\n")
        lf.write(self._elid + "\n")
        lf.write("%s\n" % log)
        for el in lines:
            lf.write(el + '\n')
        lf.close()

    def save_revocation_report(self, report):
        fn = self._reg.path(['hts', 'output', evcommon.REVREPORT_FILE])
        outfile = htscommon.LoggedFile(fn)
        outfile.open('a')
        for el in report:
            outfile.write("\t".join(el) + "\n")

        outfile.close()

    def talletaja(self, ik):
        vl = None
        try:
            vl = inputlists.VotersList('hts', self._reg)
            if not vl.has_voter(ik):
                return None
            ret = vl.get_voter(ik)
            return ret
        finally:
            if vl is not None:
                vl.close()
#.........这里部分代码省略.........
开发者ID:Augustyn,项目名称:evalimine,代码行数:103,代码来源:htsbase.py

示例10: main_function

# 需要导入模块: from election import Election [as 别名]
# 或者: from election.Election import path [as 别名]
def main_function():

    try:

        if Election().is_hes():
            server = 'hes'
        elif Election().is_hts():
            server = 'hts'
        else:
            raise Exception('Vigane serveri tüüp')

        election_ids = Election().get_questions()

        if len(election_ids) == 0:
            print "Valijanimekirju pole laaditud"
        else:
            election_ids.sort()
            for el_i in election_ids:
                print "%s" % el_i
                reg_i = Election().get_sub_reg(el_i, [server])
                if not reg_i.check(['voters_files']):
                    print "\tValijanimekirju pole laaditud"
                    continue

                file_list = reg_i.list_keys(['voters_files'])
                file_list.sort()
                if len(file_list) == 0:
                    print "\tValijanimekirju pole laaditud"
                else:
                    prefix_len = 8 + 1 + 14 + 1
                    j = 1
                    added_total = 0
                    for vf_i in file_list:
                        file_date = vf_i[0:4] + "." + vf_i[4:6] + \
                            "." + vf_i[6:8] + " " + vf_i[8:10] + \
                            ":" + vf_i[10:12] + ":" + vf_i[12:14]
                        file_name = vf_i[15:]
                        if len(file_name) > prefix_len:
                            file_name = file_name[prefix_len:]
                        print "\t%02d. %s - %s" % (j, file_date, file_name)
                        j += 1

                        # nimekirja kokkulugemine
                        _rf = file(reg_i.path(['voters_files', vf_i]), "r")
                        line = _rf.readline()      # päise 1. rida
                        line = _rf.readline()      # päise 2. rida
                        filetype = _rf.readline()  # päise 3. rida
                        added = 0
                        removed = 0
                        while 1:
                            line = _rf.readline()
                            if len(line) == 0:
                                break
                            fields = line.split("\t")
                            if fields[2] == "lisamine":
                                added += 1
                                added_total += 1
                            else:
                                removed += 1
                                added_total -= 1
                        print \
                            "\t    Faili tüüp: %s\n" % filetype.strip() + \
                            "\t    Lisamisi %d, " % added + \
                                  "eemaldamisi %d\n" % removed + \
                            "\t    Kokku peale laadimist: %d" % added_total

    except Exception, ex:
        print 'Viga valijanimekirjade uuenduste ajaloo kuvamisel: ' + str(ex)
        sys.exit(1)
开发者ID:Cougar,项目名称:evalimine,代码行数:71,代码来源:show_voters_files_history.py

示例11: __init__

# 需要导入模块: from election import Election [as 别名]
# 或者: from election.Election import path [as 别名]
class HLR:

    """
    Häältelugemisrakendus
    """

    def __init__(self, elid, tmpdir):

        self._elid = elid
        evlog.AppLog().set_app('HLR', self._elid)
        self._reg = Election().get_sub_reg(self._elid)
        self._log4 = evlog.Logger('log4')
        self._log5 = evlog.Logger('log5')
        self._log4.set_format(evlog.EvLogFormat())
        self._log5.set_format(evlog.EvLogFormat())
        self._log4.set_logs(self._reg.path(['common', 'log4']))
        self._log5.set_logs(self._reg.path(['common', 'log5']))

        tmpreg = evreg.Registry(root=tmpdir)
        tmpreg.ensure_key([])
        tmpreg.delete_sub_keys([])
        self.output_file = tmpreg.path(['decrypted_votes'])
        self.decrypt_prog = DECRYPT_PROGRAM
        self.sign_prog = SIGN_PROGRAM
        self.__cnt = ChoicesCounter()

    def __del__(self):
        try:
            os.remove(self.output_file)
        except:
            pass

    def _decrypt_votes(self, pin):

        input_file = self._reg.path(['hlr', 'input', 'votes'])
        token_name = Election().get_hsm_token_name()
        priv_key_label = Election().get_hsm_priv_key()
        pkcs11lib = Election().get_pkcs11_path()
        args = [input_file,
                self.output_file,
                token_name,
                priv_key_label,
                pin,
                pkcs11lib]

        exit_code = 0

        try:
            exit_code = subprocess.call([self.decrypt_prog] + args)
        except OSError as oserr:
            errstr = "Häälte faili '%s' dekrüpteerimine nurjus: %s" % \
                (input_file, oserr)
            evlog.log_error(errstr)
            return False

        if exit_code == 0:
            return True

        if exit_code > 0:
            errstr2 = "Tundmatu viga"
            if exit_code in G_DECRYPT_ERRORS:
                errstr2 = G_DECRYPT_ERRORS[exit_code]

            errstr = \
                "Häälte faili '%s' dekrüpteerimine nurjus: %s (kood %d)" % \
                (input_file, errstr2, exit_code)
            evlog.log_error(errstr)
            return False

        errstr = "Häälte faili '%s' dekrüpteerimine nurjus (signaal %d)" % \
            (input_file, exit_code)
        evlog.log_error(errstr)
        return False

    def _sign_result(self, pin, input_file):

        token_name = Election().get_hsm_token_name()
        priv_key_label = Election().get_hsm_priv_key()
        pkcs11lib = Election().get_pkcs11_path()
        args = [input_file,
                _sig(input_file),
                token_name,
                priv_key_label,
                pin,
                pkcs11lib]

        exit_code = 0

        try:
            exit_code = subprocess.call([self.sign_prog] + args)
        except OSError as oserr:
            errstr = "Tulemuste faili '%s' allkirjastamine nurjus: %s" % \
                (input_file, oserr)
            evlog.log_error(errstr)
            return False

        if exit_code == 0:
            return True

        if exit_code > 0:
#.........这里部分代码省略.........
开发者ID:Augustyn,项目名称:evalimine,代码行数:103,代码来源:hlr.py


注:本文中的election.Election.path方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。