Exemple #1
0
def _load_questions_from_dir(question_dir):
    # type: (str) -> Dict[str, QuestionMeta]
    question_files = []
    for dirpath, dirnames, filenames in os.walk(question_dir):
        for filename in filenames:
            if filename.endswith(".json"):
                question_files.append(os.path.join(dirpath, filename))
    if len(question_files) == 0:
        bf_logger.warn(
            "WARNING: no .json files found in supplied question directory: {questionDir}".format(
                questionDir=question_dir))
        return {}

    questions = {}
    for questionFile in question_files:
        try:
            (qname, qclass) = _load_question_disk(questionFile)
            questions[qname] = qclass
        except Exception as err:
            bf_logger.error(
                "Could not load question from {questionFile}:{err}".format(
                    questionFile=questionFile,
                    err=err))
    bf_logger.info(
        "Successfully loaded {numQuestions}/{numQuestionFiles} question(s) from local directory".format(
            numQuestions=len(questions), numQuestionFiles=len(question_files)))
    return questions
Exemple #2
0
def load_dir_questions(questionDir, moduleName=bfq.__name__):
    questionFiles = []
    for dirpath, dirnames, filenames in os.walk(questionDir):
        for filename in filenames:
            if filename.endswith(".json"):
                questionFiles.append(os.path.join(dirpath, filename))
    localQuestions = set([])
    if len(questionFiles) == 0:
        bf_logger.warn(
            "WARNING: no .json files found in supplied question directory: {questionDir}"
            .format(questionDir=questionDir))
    else:
        numQuestions = 0
        for questionFile in questionFiles:
            try:
                localQuestions.add(
                    _load_question_disk(questionFile, module_name=moduleName))
                numQuestions += 1
            except ValueError as err:
                bf_logger.error(
                    "Could not load question from {questionFile}:{err}".format(
                        questionFile=questionFile, err=err))
        bf_logger.info(
            "Successfully loaded {numQuestions}/{numQuestionFiles} question(s) from local directory"
            .format(numQuestions=numQuestions,
                    numQuestionFiles=len(questionFiles)))
    return localQuestions
Exemple #3
0
def _load_remote_questions_templates(moduleName=bfq.__name__):
    numQuestions = 0
    remoteQuestions = set([])
    questionsDict = _bf_get_question_templates()
    for (key, value) in questionsDict.items():
        try:
            remoteQuestions.add(
                _load_question_json(value, module_name=moduleName))
            numQuestions += 1
        except Exception as err:
            bf_logger.error("Could not load question {name} : {err}".format(
                name=key, err=err))
    bf_logger.info(
        "Successfully loaded {numQuestions} questions from remote".format(
            numQuestions=numQuestions))
    return remoteQuestions
Exemple #4
0
def _load_remote_questions_templates():
    # type: () -> Set[Tuple[str, QuestionMeta]]
    num_questions = 0
    remote_questions = set()
    questions_dict = _bf_get_question_templates()
    for (key, value) in questions_dict.items():
        try:
            remote_questions.add(_load_question_dict(json.loads(value)))
            num_questions += 1
        except Exception as err:
            bf_logger.error(
                "Could not load question {name} : {err}".format(name=key,
                                                                err=err))
    bf_logger.info(
        "Successfully loaded {numQuestions} questions from remote".format(
            numQuestions=num_questions))
    return remote_questions