Exemplo n.º 1
0
    def from_file(path: str, unit_name: str, copy_executable: bool,
                  write_to: Optional[str], target_arch: Arch,
                  grader_map: Dict[Language, GraderInfo]) -> "SourceFile":
        """
        Handy constructor to build a SourceFile
        :param path: path to the source file
        :param unit_name: name of the unit of this source file. Usually the name
            of the task
        :param copy_executable: Whether to copy the executable into write_to
        :param write_to: Where to copy the executable, if copy_executable
        :param target_arch: Architecture to target the build
        :param grader_map: Map with the graders for all the languages
        """
        if copy_executable and not write_to:
            raise ValueError(
                "Asked to copy the executable but not specified where")
        old_path = path
        if not os.path.exists(path):
            path = find_executable(path)
        if not path:
            raise ValueError("Cannot find %s" % old_path)

        language = LanguageManager.from_file(path)
        dependencies = language.get_dependencies(path)
        grader = grader_map.get(language)
        exe_name = language.exe_name(path, write_to)
        source_file = SourceFile(path, unit_name, exe_name, dependencies,
                                 language, copy_executable and write_to,
                                 target_arch, grader)
        if not language.need_compilation:
            if not is_executable(source_file.path):
                raise ValueError("The file %s is not an executable. "
                                 "Please check the shebang (#!)" % path)
        return source_file
Exemplo n.º 2
0
def gen_grader_map(graders: List[str]) -> Dict[Language, GraderInfo]:
    """
    Given the list of the paths to the supported grader files computes the
    association between language and grader metadata.
    """
    grader_map = dict()

    for grader in graders:
        name = os.path.basename(grader)
        language = LanguageManager.from_file(grader)
        info = GraderInfo(
            language,
            [Dependency(name, grader)] + language.get_dependencies(grader))
        grader_map[info.for_language] = info
    return grader_map
Exemplo n.º 3
0
def list_files(patterns: List[str],
               exclude: Optional[List[str]] = None,
               valid_extensions: List[str] = None) -> List[str]:
    """
    List all the files that match the provided patterns, excluding some files
    and filtering only the one with a valid extension. If valid_extensions is
    not provided LanguageManager.valid_extensions() is used.
    """
    if exclude is None:
        exclude = []
    if valid_extensions is None:
        valid_extensions = LanguageManager.valid_extensions()
    files = [_file for pattern in patterns
             for _file in glob.glob(pattern)]  # type: List[str]
    return [
        res for res in files
        if res not in exclude and os.path.splitext(res)[1] in valid_extensions
    ]
Exemplo n.º 4
0
def register():
    LanguageManager.register_language(LanguageC())
Exemplo n.º 5
0
def register():
    LanguageManager.register_language(LanguageExecutable())
Exemplo n.º 6
0
def register():
    LanguageManager.register_language(LanguageShell())
Exemplo n.º 7
0
def register():
    LanguageManager.register_language(LanguagePython())
Exemplo n.º 8
0
def register():
    LanguageManager.register_language(LanguagePascal())