예제 #1
0
    def attach_filepath_raw(self, datablock: T.ID):
        if hasattr(datablock, "filepath"):
            filepath = datablock.filepath
            if len(filepath) == 0:
                return
            if filepath[0] == "<" and filepath[-1] == ">":
                # various builtin names, like "<builtin>" for VectorFont, or "<startup.blend>" for Library
                return

            try:
                path_string = get_source_file_path(bpy.path.abspath(filepath))
            except OSError as e:
                logger.warning(
                    f"{datablock!r}: invalid file path {filepath} ...")
                logger.warning(f"... {e!r}")
                return

            path = pathlib.Path(path_string)
            if not path.exists():
                logger.warning(
                    f"{datablock!r}: file with computed source path does not exist ..."
                )
                logger.warning(f"... filepath: '{filepath}'")
                logger.warning(f"... abspath:  '{bpy.path.abspath(filepath)}'")
                logger.warning(f"... source:   '{path_string}'")
            self._filepath_raw = str(path)
예제 #2
0
    def attach_media_descriptor(self, datablock: T.ID, context: Context):
        # if Image, Sound, Library, MovieClip, Text, VectorFont, Volume
        # create a self._media with the data to be sent
        # - filepath
        # - reference to the packed data if packed
        #
        #
        if hasattr(datablock, "packed_file"):
            self._is_in_shared_folder = False
            packed_file = datablock.packed_file
            data = None
            if packed_file is not None:
                data = packed_file.data
                self._media = (get_source_file_path(self._filepath_raw), data)
                return

            if self._filepath_raw is None:
                return

            relative_to_shared_folder_path = self.matches_shared_folder(
                self._filepath_raw, context)
            if relative_to_shared_folder_path is not None:
                self._filepath_raw = relative_to_shared_folder_path
                self._is_in_shared_folder = True
                self._media = None
                return

            path = get_source_file_path(self._filepath_raw)
            try:
                abspath = bpy.path.abspath(path)
                with open(abspath, "rb") as data_file:
                    data = data_file.read()
            except Exception as e:
                logger.error(f"Error while loading {abspath!r} ...")
                logger.error(
                    f"... for {datablock!r}. Check shared folders ...")
                logger.error(f"... {e!r}")
                self._media = None
            else:
                self._media = (path, data)
예제 #3
0
 def attach_filepath_raw(self, datablock: T.ID):
     if hasattr(datablock, "filepath"):
         if len(datablock.filepath) == 0:
             return
         path_string = get_source_file_path(
             bpy.path.abspath(datablock.filepath))
         path = pathlib.Path(path_string)
         if not path.exists():
             logger.warning(
                 f"{datablock!r}: file with computed source path does not exist ..."
             )
             logger.warning(f"... filepath: '{datablock.filepath}'")
             logger.warning(
                 f"... abspath:  '{bpy.path.abspath(datablock.filepath)}'")
             logger.warning(f"... source:   '{path_string}'")
         self._filepath_raw = str(path)
예제 #4
0
 def attach_media_descriptor(self, datablock: T.ID):
     # if Image, Sound, Library, MovieClip, Text, VectorFont, Volume
     # create a self._media with the data to be sent
     # - filepath
     # - reference to the packed data if packed
     #
     #
     if isinstance(datablock, T.Image):
         path = get_source_file_path(datablock.filepath)
         packed_file = datablock.packed_file
         data = None
         if packed_file is not None:
             data = packed_file.data
         else:
             with open(bpy.path.abspath(path), "rb") as data_file:
                 data = data_file.read()
         self._media = (path, data)