MCPcopy Index your code
hub / github.com/diffgram/diffgram / init_file

Method init_file

shared/annotation.py:679–734  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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

Callers 1

__post_init__Method · 0.95

Calls 3

get_frame_from_videoMethod · 0.80
get_by_idMethod · 0.45
newMethod · 0.45

Tested by

no test coverage detected