예제 #1
0
파일: tasks.py 프로젝트: slapec/rlscloud
            def run(self, information: dict) -> Tuple[List, Dict]:
                download_task = parent.download_task

                name = information['title']
                source = information['filepath']
                file_hash = hash_file(source, progress_hook=parent._hash_progress_hook)
                destination = os.path.join(settings.RELEASE_DIR, file_hash + os.path.splitext(source)[-1])

                # TODO: Check if file already exists
                shutil.move(source, destination)

                # TODO: This doesn't rolls back
                with transaction.atomic():
                    release = Release()
                    release.name = name
                    release.file = destination
                    release.created_by = download_task.created_by
                    release.file_hash = file_hash
                    release.save()

                    download_task.state = DownloadTask.FINISHED
                    download_task.finished_at = timezone.now()
                    download_task.release = release
                    download_task.save()

                return super().run(information)
예제 #2
0
파일: forms.py 프로젝트: slapec/rlscloud
    def clean_file(self):
        file = self.cleaned_data['file']
        self._file_name_original = file.name

        hash_ = hash_file(file.temporary_file_path())
        self.cleaned_data['file_hash'] = hash_
        file.name = hash_ + os.path.splitext(file.name)[-1]

        return file