-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature #78 : Add option to remove empty catalogs
- Loading branch information
1 parent
51041b2
commit 4f2e525
Showing
12 changed files
with
131 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from bpy.types import Operator, PropertyGroup | ||
from bpy.props import PointerProperty | ||
|
||
from asset_browser_utilities.core.operator.tool import BatchExecute, BatchFolderOperator | ||
from asset_browser_utilities.core.cache.tool import get_from_cache | ||
from asset_browser_utilities.core.filter.main import AssetFilterSettings | ||
from asset_browser_utilities.core.log.logger import Logger | ||
from asset_browser_utilities.module.asset.tool import all_assets | ||
from asset_browser_utilities.module.catalog.tool import CatalogsHelper | ||
|
||
|
||
class CatalogRemoveEmptyBatchExecute(BatchExecute): | ||
def execute_one_file_and_the_next_when_finished(self): | ||
asset_uuids = set(asset.asset_data.catalog_id for asset in all_assets()) | ||
helper = CatalogsHelper() | ||
|
||
asset_filter_settings = get_from_cache(AssetFilterSettings) | ||
filter_name = asset_filter_settings.filter_name | ||
filter_func = lambda name: filter_name.filter(name) if filter_name.active else lambda: True | ||
|
||
catalogs = {cat[0]: cat[1] for cat in helper.get_catalogs() if filter_func(cat[1])} | ||
catalog_uuids = set(catalogs.keys()) | ||
|
||
empty_catalogs = catalog_uuids.difference(asset_uuids) | ||
for empty_catalog_uuid in empty_catalogs: | ||
helper.remove_catalog_by_uuid(empty_catalog_uuid) | ||
Logger.display(f"Removed empty catalog '{catalogs[empty_catalog_uuid]}'") | ||
|
||
self.save_file() | ||
self.execute_next_blend() | ||
|
||
|
||
class CatalogRemoveEmptyOperatorProperties(PropertyGroup): | ||
pass | ||
|
||
|
||
class ABU_OT_catalog_remove_empty(Operator, BatchFolderOperator): | ||
bl_idname = "abu.catalog_remove_empty" | ||
bl_label = "Batch Remove Empty Catalogs" | ||
|
||
operator_settings: PointerProperty(type=CatalogRemoveEmptyOperatorProperties) | ||
logic_class = CatalogRemoveEmptyBatchExecute | ||
|
||
def invoke(self, context, event): | ||
return self._invoke( | ||
context, filter_assets=False, filter_type=False, filter_selection=False, custom_operation=False | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import bpy | ||
from asset_browser_utilities.core.test.prop import TestOperator | ||
|
||
from asset_browser_utilities.module.catalog.operator.remove_empty import CatalogRemoveEmptyBatchExecute | ||
|
||
from asset_browser_utilities.module.catalog.tool import all_catalogs | ||
from asset_browser_utilities.module.asset.tool import all_assets | ||
|
||
|
||
def test_removing_all_empty_catalogs(filepath): | ||
test_op = TestOperator( | ||
filepath=filepath, | ||
filter_assets=False, | ||
op_name="op_catalog_remove_empty", | ||
logic_class=CatalogRemoveEmptyBatchExecute, | ||
) | ||
|
||
catalogs_uuids = set(cat[0] for cat in all_catalogs()) | ||
# /!\ Assets with no catalog have a catalog uuid of '00000000-0000-0000-0000-000000000000' | ||
catalogs_uuids_assets = set(asset.asset_data.catalog_id for asset in all_assets()) | ||
assert len(catalogs_uuids) + 1 > len(catalogs_uuids_assets) | ||
|
||
test_op.execute() | ||
|
||
catalogs_uuids = [cat[0] for cat in all_catalogs()] | ||
assert len(catalogs_uuids) + 1 == len(catalogs_uuids_assets) | ||
|
||
|
||
def test_removing_an_empty_catalog_by_name(filepath): | ||
# TODO | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters