mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-02 00:44:52 +01:00
base of farm cleanup plugin
This commit is contained in:
parent
4b8dd165d2
commit
ff5bed3a13
1 changed files with 45 additions and 0 deletions
45
openpype/plugins/publish/cleanup_farm.py
Normal file
45
openpype/plugins/publish/cleanup_farm.py
Normal file
|
|
@ -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
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue