diff --git a/blender_cloud/blender.py b/blender_cloud/blender.py index 49192c4..1dfd612 100644 --- a/blender_cloud/blender.py +++ b/blender_cloud/blender.py @@ -426,6 +426,8 @@ class BlenderCloudPreferences(AddonPreferences): text='Local Cloud Project Path') def draw_flamenco_buttons(self, flamenco_box, bcp: flamenco.FlamencoManagerGroup, context): + from .flamenco import bam_interface + header_row = flamenco_box.row(align=True) header_row.label('Flamenco:', icon_value=icon('CLOUD')) @@ -461,7 +463,15 @@ class BlenderCloudPreferences(AddonPreferences): props = path_box.operator('flamenco.explore_file_path', text='', icon='DISK_DRIVE') props.path = self.flamenco_job_output_path - job_output_box.prop(self, 'flamenco_exclude_filter') + show_warning = bool(self.flamenco_exclude_filter and + not bam_interface.bam_supports_exclude_option()) + job_output_box.alert = show_warning + job_output_box.prop(self, 'flamenco_exclude_filter', + icon='ERROR' if show_warning else 'NONE') + if show_warning: + job_output_box.label( + text='Warning, the exclusion filter requires a newer version of Blender!') + job_output_box.alert = False prop_split = job_output_box.split(0.32, align=True) prop_split.label('Strip Components:') diff --git a/blender_cloud/flamenco/bam_interface.py b/blender_cloud/flamenco/bam_interface.py index e37a4bb..a75f50b 100644 --- a/blender_cloud/flamenco/bam_interface.py +++ b/blender_cloud/flamenco/bam_interface.py @@ -1,5 +1,6 @@ """BAM packing interface for Flamenco.""" +import functools import logging from pathlib import Path import typing @@ -14,6 +15,28 @@ class CommandExecutionError(Exception): pass +if 'bam_supports_exclude_option' in locals(): + locals()['bam_supports_exclude_option'].cache_clear() + + +@functools.lru_cache(maxsize=1) +def bam_supports_exclude_option() -> bool: + """Returns True if the version of BAM bundled with Blender supports --exclude. + + This feature was added to BAM 1.1.7, so we can do a simple version check. + """ + + try: + import io_blend_utils + except ImportError: + # If this happens, BAM won't work at all. However, this function can be called from + # the GUI; by being a bit careful while importing, we avoid breaking Blender's GUI. + log.exception('Error importing io_blend_utils module.') + return False + + return io_blend_utils.bl_info['version'] >= (1, 1, 7) + + async def bam_copy(base_blendfile: Path, target_blendfile: Path, exclusion_filter: str) -> typing.List[Path]: """Uses BAM to copy the given file and dependencies to the target blendfile. @@ -43,7 +66,11 @@ async def bam_copy(base_blendfile: Path, target_blendfile: Path, ] if exclusion_filter: - args.extend(['--exclude', exclusion_filter]) + if bam_supports_exclude_option(): + args.extend(['--exclude', exclusion_filter]) + else: + log.warning('Your version of Blender does not support the exclusion filter, ' + 'copying all files.') cmd_to_log = ' '.join(shlex.quote(s) for s in args) log.info('Executing %s', cmd_to_log)