示例#1
0
def _get_cases_from_json_file_given_problem_type(path, problemNumber, caseType):
    """
    Return a list of Case object from a JSON file located at path given
    the case type and problem number
    """
    return get_cases_from_json(fileops.get_json_dict(path), problemNumber,
            caseType)
示例#2
0
    def load_languages(cls):
        """
        Loads the languages into cache from the languages file
        """
        if cls._languagesDict is None:
            cls._languagesDict = {}

        languagesItems = fileops.get_json_dict(cls.get_languages_filepath())
        for languageBlock in languagesItems['languages']:
            cls._languagesDict[Languages.get_prevalent_extension_from_block(languageBlock)] = (
                    Language.load_from_dict(languageBlock))
示例#3
0
def load_config_file(path=None):
    """
    Loads the config file into the global config variable

    Keyword Arguments:
    path: str - The path to load the config from (default: conf/packages.json)
    """
    if path is None:
        path = fileops.join_path(PathMapper.get_config_path(), 
                CONFIGURATION_FILE)

    global config
    config = fileops.get_json_dict(path)
示例#4
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
示例#5
0
 def _load_from_config(cls):
     loadedContents = fileops.get_json_dict(cls._get_config_path())
     if isinstance(loadedContents, list):
         cls.writers = loadedContents
     else:
         cls.writers = []
示例#6
0
 def load_definitions(cls):
     """
     Load the definitions dictionary from the definitions file
     """
     cls._definitionsDict = fileops.get_json_dict(cls.get_definitions_filepath())
示例#7
0
 def load_variables(cls):
     """
     Load the variables dictionary from the variables file
     """
     cls._variablesDict = fileops.get_json_dict(cls.get_variables_filepath())