예제 #1
0
    def load_from_path(path):
        """
        Creates a new Solution object from a file at path and returns it
        """
        newSolution = Solution(solutionPath=path)
        filename = fileops.get_basename_less_extension(path)
        filenameMatcher = Definitions.get_value_matcher(Solution.NAMING_DEFINITION_KEY)
        newSolution.problemNumber = filenameMatcher.get_variable_value(
            filename, Variables.get_variable_key_name(Variables.NAME_PROBLEM_NUMBER)
        )
        from util.writer import Writer

        newSolution.solutionWriter = fileops.get_basename(fileops.get_parent_dir(path))
        newSolution.solutionLanguage = Languages.get_language_from_extension(fileops.get_extension(path))

        return newSolution
예제 #2
0
    def get_applied_language(cls, solutionPath, solutionLanguage):
        if solutionPath in cls._appliedLanguages:
            return cls._appliedLanguages[solutionPath]

        variableDictionary = {
                Variables.get_variable_key_name(Variables.NAME_FILENAME): fileops.get_basename(solutionPath),
                Variables.get_variable_key_name(Variables.NAME_FILENAME_LESS_EXT): fileops.get_basename_less_extension(solutionPath),
                Variables.get_variable_key_name(Variables.NAME_DIRECTORY): fileops.get_parent_dir(solutionPath)
                }

        cls._appliedLanguages[solutionPath] = AppliedLanguage(solutionLanguage.name,
                cls._get_formatted_str_rec(variableDictionary, solutionLanguage._compileExtension),
                cls._get_formatted_str_rec(variableDictionary, solutionLanguage._compileCommand),
                cls._get_formatted_str_rec(variableDictionary, solutionLanguage._compileArguments),
                cls._get_formatted_str_rec(variableDictionary, solutionLanguage._runExtension),
                cls._get_formatted_str_rec(variableDictionary, solutionLanguage._runCommand),
                cls._get_formatted_str_rec(variableDictionary, solutionLanguage._runArguments),
                solutionPath)

        return cls._appliedLanguages[solutionPath]
예제 #3
0
def _get_file_problemnumber_type_tuple(path):
    """
    Extracts the problem number and case type from the file name at path

    :returns: (problemnumber:int, casetype:int)
    """
    filename = fileops.get_basename_less_extension(path)

    # Extract problem number
    filenameMatcher = Definitions.get_value_matcher(Case.NAMING_DEFINITION_KEY)
    problemNumber = filenameMatcher.get_variable_value(filename,
            Variables.get_variable_key_name(Variables.NAME_PROBLEM_NUMBER))

    # Extract case type
    caseType = filenameMatcher.get_variable_value(filename,
            Variables.get_variable_key_name(Variables.NAME_CASE_TYPE))
    if problemNumber is None:
        return None

    # Return the tuple
    return (int(problemNumber), CaseType.from_string(caseType))
예제 #4
0
 def is_solution_file(path):
     """
     Checks to see if basename of file matches solution naming scheme from definitions
     """
     filename = fileops.get_basename_less_extension(path)
     return Definitions.get_value_matcher(Solution.NAMING_DEFINITION_KEY).matches(filename)