setup.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:wrath-ctf-framework 作者: WhiteHatCP 项目源码 文件源码
def build_challenges():
    chal_path = path.join(app.root_path, "../",
                          app.config['CTF']['challenges'])
    categories = app.config['CTF']['categories']
    for c in categories:
        problem_config = path.join(chal_path, c, "problems.json")
        with open(problem_config, 'r') as config_file:
            try:
                config = json.load(config_file)
            except ValueError:
                raise ValueError("%s was malformed" % config_file)
            for problem in config["problems"]:
                problem_dict = build_problem_options(problem, c)
                challenge = Challenge(**problem_dict)
                db.session.add(challenge)

                for f in problem["resources"]:
                    file_path = path.join(chal_path, c)
                    resource = Resource(name=f,
                                        path=file_path,
                                        challenge=challenge)
                    db.session.add(resource)
                try:
                    db.session.commit()
                except IntegrityError:
                    db.session.rollback()
                    challenge = Challenge.query.filter_by(
                            title=problem['title'])
                    problem_dict.update({'id': challenge.first().id})
                    challenge.update(problem_dict)
                    db.session.commit()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号