(self)
| 677 | return self.file |
| 678 | |
| 679 | def init_file(self): |
| 680 | # https://diffgram.readme.io/docs/init-annotation-update |
| 681 | |
| 682 | if self.video_mode is True and self.file.type == "frame": |
| 683 | self.log['error']['video_mismatch'] = "In video mode but sending frame." |
| 684 | return |
| 685 | |
| 686 | # For now there is no extra init needed if it's an image |
| 687 | if self.file.type == "image": |
| 688 | if self.force_lock: |
| 689 | try: |
| 690 | self.file = File.get_by_id(session = self.session, |
| 691 | file_id = self.file.id, |
| 692 | with_for_update = True, |
| 693 | nowait = True) |
| 694 | except Exception as e: |
| 695 | self.log['error'][ |
| 696 | 'file_lock'] = "File is locked or being saved by another user, please try saving again." |
| 697 | self.log['error']['trace'] = traceback.format_exc() |
| 698 | return |
| 699 | |
| 700 | if self.file.type == "video": |
| 701 | |
| 702 | self.video_parent_file = self.file |
| 703 | |
| 704 | # Switch -> self.file becomes the frame |
| 705 | # Create frame file when first instance is created |
| 706 | # Can be done prior to an instance - just current way |
| 707 | |
| 708 | # If this is set to true, we'll attach the instance list to the video parent file |
| 709 | if self.set_parent_instance_list: |
| 710 | self.file = self.video_parent_file |
| 711 | else: |
| 712 | # Default case, file already exists. |
| 713 | self.file = File.get_frame_from_video( |
| 714 | session = self.session, |
| 715 | video_parent_file_id = self.video_parent_file.id, |
| 716 | frame_number = self.frame_number, |
| 717 | with_for_update = True, |
| 718 | nowait = True |
| 719 | ) |
| 720 | |
| 721 | if self.file: |
| 722 | return |
| 723 | |
| 724 | # File does not exist, so create it. |
| 725 | |
| 726 | self.file = File.new( |
| 727 | session = self.session, |
| 728 | file_type = "frame", |
| 729 | video_parent_file = self.video_parent_file, |
| 730 | frame_number = self.frame_number, |
| 731 | project_id = self.project.id, |
| 732 | task = self.task |
| 733 | ) |
| 734 | self.is_new_file = True |
| 735 | |
| 736 | # Tested |
no test coverage detected