Esempio n. 1
0
    def handle_operation(self) -> flask.Response:
        git_operation = self._extract_git_operation()
        repository_folder = self.repository_folder / 'config'

        new_repository = not repository_folder.exists()
        if new_repository:
            self._initialize_bare_repository()

        if not git_operation.supported:
            raise OSError

        data_out = self._execute_git_operation(git_operation)

        if git_operation.format_response:
            data_out = git_operation.format_response(data_out)

        if git_operation.contain_new_commits:
            files = self._load_files_from_repository()
            solution_hash = hashing.by_content(str(files))
            upload.upload_solution(
                course_id=self._course_id,
                exercise_number=self._exercise_number,
                files=files,
                solution_hash=solution_hash,
                user_id=self._user.id,
            )

        return self.build_response(data_out, git_operation)
Esempio n. 2
0
 def __iter__(self) -> Iterator[Tuple[int, List[File], str]]:
     for cls in self.__class__.__subclasses__():
         log.debug(f'Trying extractor: {cls.__name__}')
         extractor = cls(to_extract=self.to_extract)
         if extractor.can_extract():
             yield from (
                 (solution_id, files, hashing.by_content(str(files)))
                 for solution_id, files in extractor.get_exercises()
             )
Esempio n. 3
0
 def create_hash(content: Union[str, bytes], *args, **kwargs) -> str:
     return hashing.by_content(content, *args, **kwargs)