From 8d41902b1a8a480d71e4ec56afee7326991c9313 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= Date: Fri, 26 Jul 2019 14:00:30 +0200 Subject: [PATCH 1/3] feat: deleting rendered frames from working area after publishing --- .../global/publish/collect_filesequences.py | 11 +++++--- pype/plugins/global/publish/integrate_new.py | 25 ++++++++++++++++--- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/pype/plugins/global/publish/collect_filesequences.py b/pype/plugins/global/publish/collect_filesequences.py index ed48404a98..8b87068a09 100644 --- a/pype/plugins/global/publish/collect_filesequences.py +++ b/pype/plugins/global/publish/collect_filesequences.py @@ -160,10 +160,13 @@ class CollectRenderedFrames(pyblish.api.ContextPlugin): # Get family from the data families = data.get("families", ["render"]) - assert isinstance(families, (list, tuple)), "Must be iterable" - assert families, "Must have at least a single family" - families.append("ftrack") - families.append("review") + if "render" not in families: + families.append("render") + if "ftrack" not in families: + families.append("ftrack") + if "review" not in families: + families.append("review") + for collection in collections: instance = context.create_instance(str(collection)) self.log.info("Collection: %s" % list(collection)) diff --git a/pype/plugins/global/publish/integrate_new.py b/pype/plugins/global/publish/integrate_new.py index 0d077ca65e..3070a1f759 100644 --- a/pype/plugins/global/publish/integrate_new.py +++ b/pype/plugins/global/publish/integrate_new.py @@ -403,19 +403,36 @@ class IntegrateAssetNew(pyblish.api.InstancePlugin): self.log.info("Registered {} items".format(len(representations))) def integrate(self, instance): - """Move the files + """ Move the files. If files are in render family, they will be + deleted after copy. - Through `instance.data["transfers"]` + Through `instance.data["transfers"]` - Args: - instance: the instance to integrate + Args: + instance: the instance to integrate """ transfers = instance.data.get("transfers", list()) + current_families = instance.data.get("families", list()) + instance_family = instance.data.get("family", None) + dirnames = [] + for src, dest in transfers: if os.path.normpath(src) != os.path.normpath(dest): self.copy_file(src, dest) + if instance_family == 'render' or 'render' in current_families: + os.remove(src) + dirnames.append(os.path.dirname(src)) + + # make unique set + cleanup_dirs = set(dirnames) + for dir in cleanup_dirs: + try: + os.rmdir(dir) + except OSError: + # directory is not empty, skipping + continue # Produce hardlinked copies # Note: hardlink can only be produced between two files on the same From c77578be01393413f83ab64c1591ede60852caab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= Date: Mon, 29 Jul 2019 11:37:24 +0200 Subject: [PATCH 2/3] moved render cleanup code to cleanup instance plugin --- pype/plugins/global/publish/cleanup.py | 28 ++++++++++++++++++-- pype/plugins/global/publish/integrate_new.py | 22 --------------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/pype/plugins/global/publish/cleanup.py b/pype/plugins/global/publish/cleanup.py index f31477faca..34123b31cf 100644 --- a/pype/plugins/global/publish/cleanup.py +++ b/pype/plugins/global/publish/cleanup.py @@ -3,11 +3,33 @@ import shutil import pyblish.api +def clean_renders(instance): + transfers = instance.data.get("transfers", list()) + + current_families = instance.data.get("families", list()) + instance_family = instance.data.get("family", None) + dirnames = [] + + for src, dest in transfers: + if os.path.normpath(src) != os.path.normpath(dest): + if instance_family == 'render' or 'render' in current_families: + os.remove(src) + dirnames.append(os.path.dirname(src)) + + # make unique set + cleanup_dirs = set(dirnames) + for dir in cleanup_dirs: + try: + os.rmdir(dir) + except OSError: + # directory is not empty, skipping + continue + + class CleanUp(pyblish.api.InstancePlugin): """Cleans up the staging directory after a successful publish. - The removal will only happen for staging directories which are inside the - temporary folder, otherwise the folder is ignored. + This will also clean published renders and delete their parent directories. """ @@ -36,3 +58,5 @@ class CleanUp(pyblish.api.InstancePlugin): self.log.info("Removing temporary folder ...") shutil.rmtree(staging_dir) + self.log.info("Cleaning renders ...") + clean_renders(instance) diff --git a/pype/plugins/global/publish/integrate_new.py b/pype/plugins/global/publish/integrate_new.py index 3070a1f759..bca12dc62e 100644 --- a/pype/plugins/global/publish/integrate_new.py +++ b/pype/plugins/global/publish/integrate_new.py @@ -412,28 +412,6 @@ class IntegrateAssetNew(pyblish.api.InstancePlugin): instance: the instance to integrate """ - transfers = instance.data.get("transfers", list()) - - current_families = instance.data.get("families", list()) - instance_family = instance.data.get("family", None) - dirnames = [] - - for src, dest in transfers: - if os.path.normpath(src) != os.path.normpath(dest): - self.copy_file(src, dest) - if instance_family == 'render' or 'render' in current_families: - os.remove(src) - dirnames.append(os.path.dirname(src)) - - # make unique set - cleanup_dirs = set(dirnames) - for dir in cleanup_dirs: - try: - os.rmdir(dir) - except OSError: - # directory is not empty, skipping - continue - # Produce hardlinked copies # Note: hardlink can only be produced between two files on the same # server/disk and editing one of the two will edit both files at once. From 31f709b2a455620d48d0c2044b8adad0f5c7d80c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= Date: Mon, 29 Jul 2019 11:39:24 +0200 Subject: [PATCH 3/3] fixed docstring in integrate --- pype/plugins/global/publish/integrate_new.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pype/plugins/global/publish/integrate_new.py b/pype/plugins/global/publish/integrate_new.py index bca12dc62e..acb5555ba9 100644 --- a/pype/plugins/global/publish/integrate_new.py +++ b/pype/plugins/global/publish/integrate_new.py @@ -403,8 +403,7 @@ class IntegrateAssetNew(pyblish.api.InstancePlugin): self.log.info("Registered {} items".format(len(representations))) def integrate(self, instance): - """ Move the files. If files are in render family, they will be - deleted after copy. + """ Move the files. Through `instance.data["transfers"]`