Example #1
0
    def load_from_path(cls, path):
        """
        Loads a writer and all their solutions from a specified path
        """
        # Check if writer directoroy exists. If not, return nothing
        if not fileops.exists(path, fileops.FileType.DIRECTORY):
            return None

        loadedWriter = Writer(writerPath=path)

        # Load the user data from the data file
        dataDictionary = fileops.get_json_dict(loadedWriter._get_datafile_path())

        # Populate the data if available
        # Load name
        if cls.DATAFILE_NAME_FIELD in dataDictionary:
            loadedWriter.name = dataDictionary[cls.DATAFILE_NAME_FIELD]

        # Load email
        if cls.DATAFILE_EMAIL_FIELD in dataDictionary:
            loadedWriter.email = dataDictionary[cls.DATAFILE_EMAIL_FIELD]

        # Load languages
        if cls.DATAFILE_LANGS_FIELD in dataDictionary:
            for languageName in dataDictionary[cls.DATAFILE_LANGS_FIELD]:
                loadedWriter._add_known_language_from_name(languageName)

        # Load assigned
        if cls.DATAFILE_ASSIGNED_PROBLEMS in dataDictionary:
            for assignedProblem in dataDictionary[cls.DATAFILE_ASSIGNED_PROBLEMS]:
                loadedWriter._add_assigned_problem(assignedProblem[0], assignedProblem[1])

        # Load all solutions
        for possibleSolution in fileops.get_files_in_dir(path):
            if Solution.is_solution_file(possibleSolution):
                if not Languages.is_prevalent_extension(fileops.get_extension(possibleSolution)):
                    continue

                solutionObject = Solution.load_from_path(possibleSolution)
                loadedWriter._add_solution(solutionObject)

        return loadedWriter
Example #2
0
def _get_all_cases(directory, problemNumber=None):
    """
    Looks through directory and creates Case objects from all files in
    the directory.

    :return: A dictionary of cases keyed by the problem number
    """
    cases = {}

    for possibleCaseFile in fileops.get_files_in_dir(directory):
        #if "general" in possibleCaseFile:
            #continue
        problemTypeTuple = _get_file_problemnumber_type_tuple(possibleCaseFile)
        if (not problemNumber is None and 
            not problemTypeTuple[0] == int(problemNumber)):
            continue
        if not problemTypeTuple[0] in cases:
            cases[problemTypeTuple[0]] = []
        cases[problemTypeTuple[0]].extend(
                _get_cases_from_json_file_given_problem_type(possibleCaseFile,
                problemTypeTuple[0], problemTypeTuple[1]))

    return cases
Example #3
0
def validate_defined_case_dir():
    testDir = Definitions.get_value('test_directory')
    validate_casefiles(fileops.get_files_in_dir(testDir))