From ff5bed3a13116d71e83efe3e9c2028574e159c01 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Fri, 10 Dec 2021 15:15:18 +0100 Subject: [PATCH] base of farm cleanup plugin --- openpype/plugins/publish/cleanup_farm.py | 45 ++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 openpype/plugins/publish/cleanup_farm.py diff --git a/openpype/plugins/publish/cleanup_farm.py b/openpype/plugins/publish/cleanup_farm.py new file mode 100644 index 0000000000..5a41dbbd54 --- /dev/null +++ b/openpype/plugins/publish/cleanup_farm.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +"""Cleanup leftover files from publish.""" +import os +import shutil +import pyblish.api +import avalon.api + + +class CleanUpFarm(pyblish.api.ContextPlugin): + """Cleans up the staging directory after a successful publish. + + This will also clean published renders and delete their parent directories. + """ + + order = pyblish.api.IntegratorOrder + 11 + label = "Clean Up Farm" + enabled = True + + # Keep "filesequence" for backwards compatibility of older jobs + targets = ["filesequence", "farm"] + + def process(self, context): + """Plugin entry point.""" + if avalon.api.Session["AVALON_APP"] != "maya": + self.log.info("Not in farm publish of maya renders. Skipping") + return + + dirpaths_to_remove = set() + for instance in context: + staging_dir = instance.data.get("stagingDir") + if staging_dir: + dirpaths_to_remove.add(os.path.normpath(staging_dir)) + + # clean dirs which are empty + for dirpath in dirpaths_to_remove: + if not os.path.exists(dirpath): + continue + + try: + shutil.rmtree(dirpath) + except OSError: + self.log.warning( + "Failed to remove directory \"{}\"".format(dirpath), + exc_info=True + )