def test_nonexistent(self):
        path = self.blendfiles / 'nonexistant'
        with self.assertRaises(file_sequence.DoesNotExist) as raises:
            for result in file_sequence.expand_sequence(path):
                self.fail('unexpected result %r' % result)

        self.assertEqual(path, raises.exception.path)
Example #2
0
    def _visit_sequence(self, asset_path: pathlib.Path,
                        usage: result.BlockUsage):
        assert usage.is_sequence

        for first_path in file_sequence.expand_sequence(asset_path):
            if first_path.exists():
                break
        else:
            # At least the first file of a sequence must exist.
            log.warning('Missing file: %s', asset_path)
            self.missing_files.add(asset_path)
            self._progress_cb.missing_file(asset_path)
            return

        # Handle this sequence as an asset.
        self._visit_asset(asset_path, usage)
Example #3
0
    def _visit_asset(self, asset_path: pathlib.Path, usage: result.BlockUsage):
        """Determine what to do with this asset.

        Determines where this asset will be packed, whether it needs rewriting,
        and records the blend file data block referring to it.
        """

        # Sequences are allowed to not exist at this point.
        if not usage.is_sequence and not asset_path.exists():
            log.warning('Missing file: %s', asset_path)
            self.missing_files.add(asset_path)
            self._progress_cb.missing_file(asset_path)
            return

        bfile_path = usage.block.bfile.filepath.absolute()
        self._progress_cb.trace_asset(asset_path)

        # Needing rewriting is not a per-asset thing, but a per-asset-per-
        # blendfile thing, since different blendfiles can refer to it in
        # different ways (for example with relative and absolute paths).
        if usage.is_sequence:
            first_path = next(file_sequence.expand_sequence(asset_path))
        else:
            first_path = asset_path
        path_in_project = self._path_in_project(first_path)
        use_as_is = usage.asset_path.is_blendfile_relative(
        ) and path_in_project
        needs_rewriting = not use_as_is

        act = self._actions[asset_path]
        assert isinstance(act, AssetAction)
        act.usages.append(usage)

        if needs_rewriting:
            log.info('%s needs rewritten path to %s', bfile_path,
                     usage.asset_path)
            act.path_action = PathAction.FIND_NEW_LOCATION
            self._new_location_paths.add(asset_path)
        else:
            log.debug('%s can keep using %s', bfile_path, usage.asset_path)
            asset_pp = self._target_path / asset_path.relative_to(self.project)
            act.new_path = asset_pp
 def test_non_sequence_file(self):
     path = self.blendfiles / 'imgseq/LICENSE.txt'
     actual = list(file_sequence.expand_sequence(path))
     self.assertEqual([path], actual)
 def test_first_file(self):
     path = self.blendfiles / 'imgseq/000210.png'
     actual = list(file_sequence.expand_sequence(path))
     self.assertEqual(self.imgseq, actual)