Exemple #1
0
    def filelink(self, src, dst):
        import filecmp
        import os
        import shutil

        import filelink

        # Compare files to check whether they are the same.
        if os.path.exists(dst) and filecmp.cmp(src, dst):
            return

        # Remove existing destination file.
        if os.path.exists(dst):
            os.remove(dst)

        try:
            filelink.create(src, dst, filelink.HARDLINK)
            self.log.debug("Linking: \"{0}\" to \"{1}\"".format(src, dst))
        except WindowsError as e:
            if e.winerror == 17:
                self.log.warning("File linking failed due to: \"{0}\". "
                                 "Resorting to copying instead.".format(e))
                shutil.copy(src, dst)
            else:
                raise e
    def filelink(self, src, dst):
        import filecmp
        import os
        import shutil

        import filelink

        # Compare files to check whether they are the same.
        if os.path.exists(dst) and filecmp.cmp(src, dst):
            return

        # Remove existing destination file.
        if os.path.exists(dst):
            os.remove(dst)

        try:
            filelink.create(src, dst, filelink.HARDLINK)
            self.log.debug("Linking: \"{0}\" to \"{1}\"".format(src, dst))
        except WindowsError as e:
            if e.winerror == 17:
                self.log.warning(
                    "File linking failed due to: \"{0}\". "
                    "Resorting to copying instead.".format(e)
                )
                shutil.copy(src, dst)
            else:
                raise e
 def manage_data(self, src, dst):
     try:
         filelink.create(src, dst)
         self.log.debug("Linking: \"{0}\" to \"{1}\"".format(src, dst))
     except WindowsError as e:
         if e.winerror == 17:
             self.log.warning("File linking failed due to: \"{0}\". "
                              "Resorting to copying instead.".format(e))
             shutil.copy(src, dst)
         else:
             raise e
Exemple #4
0
def test_hardlink_creation():
    """Test link creation of hardlink."""

    with tempdir() as root_dir:

        src = os.path.join(root_dir, "source.txt")
        with open(src, "w") as f:
            f.write("")
        dst = os.path.join(root_dir, "destination.txt")

        filelink.create(src, dst, filelink.HARDLINK)

        assert os.path.exists(dst)
Exemple #5
0
    def process_image(self, instance):

        collection = instance.data.get("collection", [])

        if not list(collection):
            msg = "Skipping \"{0}\" because no frames was found."
            self.log.warning(msg.format(instance.data["name"]))
            return

        # Temporary fill the missing frames.
        missing = collection.holes()
        if not collection.is_contiguous():
            pattern = collection.format("{head}{padding}{tail}")
            for index in missing.indexes:
                dst = pattern % index
                src_index = self.find_previous_index(
                    index, list(collection.indexes)
                )
                src = pattern % src_index

                filelink.create(src, dst)

        # Generate args.
        # Has to be yuv420p for compatibility with older players and smooth
        # playback. This does come with a sacrifice of more visible banding
        # issues.
        # -crf 18 is visually lossless.
        args = [
            "ffmpeg", "-y",
            "-start_number", str(min(collection.indexes)),
            "-framerate", str(instance.context.data["framerate"]),
            "-i", collection.format("{head}{padding}{tail}"),
            "-pix_fmt", "yuv420p",
            "-crf", "18",
            "-timecode", "00:00:00:01",
            "-vframes",
            str(max(collection.indexes) - min(collection.indexes) + 1),
            "-vf",
            "scale=trunc(iw/2)*2:trunc(ih/2)*2",
        ]

        if instance.data.get("baked_colorspace_movie"):
            args = [
                "ffmpeg", "-y",
                "-i", instance.data["baked_colorspace_movie"],
                "-pix_fmt", "yuv420p",
                "-crf", "18",
                "-timecode", "00:00:00:01",
            ]

        args.append(collection.format("{head}.mov"))

        self.log.debug("Executing args: {0}".format(args))

        # Can't use subprocess.check_output, cause Houdini doesn't like that.
        p = subprocess.Popen(
            args,
            stdout=subprocess.PIPE,
            stderr=subprocess.STDOUT,
            stdin=subprocess.PIPE,
            cwd=os.path.dirname(args[-1])
        )

        output = p.communicate()[0]

        # Remove temporary frame fillers
        for f in missing:
            os.remove(f)

        if p.returncode != 0:
            raise ValueError(output)

        self.log.debug(output)
Exemple #6
0
import filelink

src = 'P:/projects/filelink/test_file.mov'

for i in range(1000):
    dst = 'P:/projects/filelink/test_file_{}.mov'.format(i)
    filelink.create(src, dst, filelink.HARDLINK)