Skip to content

Commit

Permalink
Some code cleanup for CleanUp plugin
Browse files Browse the repository at this point in the history
- Use `PublishError` instead of assertion
- Optimize the 'check for errors'
- Optimize the product type check + log debug message when skipped due to that
- Move imports to top
  • Loading branch information
BigRoy committed Jan 15, 2025
1 parent e3b9bfa commit fecce68
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions client/ayon_core/plugins/publish/cleanup.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# -*- coding: utf-8 -*-
"""Cleanup leftover files from publish."""
import os
import re
import shutil
import tempfile

import pyblish.api
import re

from ayon_core.lib import is_in_tests
from ayon_core.pipeline import PublishError


class CleanUp(pyblish.api.InstancePlugin):
Expand Down Expand Up @@ -48,17 +51,15 @@ def process(self, instance):
if is_in_tests():
# let automatic test process clean up temporary data
return
# Get the errored instances
failed = []

# If instance has errors, do not clean up
for result in instance.context.data["results"]:
if (result["error"] is not None and result["instance"] is not None
and result["instance"] not in failed):
failed.append(result["instance"])
assert instance not in failed, (
"Result of '{}' instance were not success".format(
instance.data["name"]
)
)
if result["error"] is not None and result["instance"] is instance:
raise PublishError(
"Result of '{}' instance were not success".format(
instance.data["name"]
)
)

_skip_cleanup_filepaths = instance.context.data.get(
"skipCleanupFilepaths"
Expand All @@ -71,10 +72,12 @@ def process(self, instance):
self.log.debug("Cleaning renders new...")
self.clean_renders(instance, skip_cleanup_filepaths)

if [ef for ef in self.exclude_families
if instance.data["productType"] in ef]:
product_type = instance.data["productType"]
if product_type in self.exclude_families:
self.log.debug(
"Skipping cleanup for instance because product "
f"type is excluded from cleanup: {product_type}")
return
import tempfile

temp_root = tempfile.gettempdir()
staging_dir = instance.data.get("stagingDir", None)
Expand Down

0 comments on commit fecce68

Please sign in to comment.