CAM: Add built-in shapes to asset folder if they do not already exist
This commit is contained in:
@@ -520,6 +520,19 @@ class AssetManager:
|
||||
assets.append(data_or_exc) # Caller must check
|
||||
return assets
|
||||
|
||||
def exists(
|
||||
self,
|
||||
uri: Union[AssetUri, str],
|
||||
store: str = "local",
|
||||
) -> bool:
|
||||
"""
|
||||
Returns True if the asset exists, False otherwise.
|
||||
"""
|
||||
try:
|
||||
return self.get_raw(uri, store) is not None
|
||||
except FileNotFoundError:
|
||||
return False
|
||||
|
||||
def fetch(
|
||||
self,
|
||||
asset_type: Optional[str] = None,
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
import Path
|
||||
from Path import Preferences
|
||||
from Path.Preferences import addToolPreferenceObserver
|
||||
from .assets import AssetManager, FileStore
|
||||
from .assets import AssetManager, AssetUri, FileStore
|
||||
|
||||
|
||||
def ensure_library_assets_initialized(asset_manager: AssetManager, store_name: str = "local"):
|
||||
@@ -56,16 +56,28 @@ def ensure_toolbitshape_assets_initialized(asset_manager: AssetManager, store_na
|
||||
"""
|
||||
builtin_shape_path = Preferences.getBuiltinShapePath()
|
||||
|
||||
if asset_manager.is_empty("toolbitshape", store=store_name):
|
||||
for path in builtin_shape_path.glob("*.fcstd"):
|
||||
for path in builtin_shape_path.glob("*.fcstd"):
|
||||
uri = AssetUri.build(
|
||||
asset_type="toolbitshape",
|
||||
asset_id=path.stem,
|
||||
)
|
||||
if not asset_manager.exists(uri, store=store_name):
|
||||
asset_manager.add_file("toolbitshape", path)
|
||||
|
||||
if asset_manager.is_empty("toolbitshapesvg", store=store_name):
|
||||
for path in builtin_shape_path.glob("*.svg"):
|
||||
for path in builtin_shape_path.glob("*.svg"):
|
||||
uri = AssetUri.build(
|
||||
asset_type="toolbitshapesvg",
|
||||
asset_id=path.stem + ".svg",
|
||||
)
|
||||
if not asset_manager.exists(uri, store=store_name):
|
||||
asset_manager.add_file("toolbitshapesvg", path, asset_id=path.stem + ".svg")
|
||||
|
||||
if asset_manager.is_empty("toolbitshapepng", store=store_name):
|
||||
for path in builtin_shape_path.glob("*.png"):
|
||||
for path in builtin_shape_path.glob("*.png"):
|
||||
uri = AssetUri.build(
|
||||
asset_type="toolbitshapepng",
|
||||
asset_id=path.stem + ".png",
|
||||
)
|
||||
if not asset_manager.exists(uri, store=store_name):
|
||||
asset_manager.add_file("toolbitshapepng", path, asset_id=path.stem + ".png")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user