start removing conform

master
“christopheseux” 2022-12-28 17:44:15 +01:00
parent 92f275fcea
commit ab72a15a2c
6 changed files with 35 additions and 37 deletions

View File

@ -1,5 +1,5 @@
from asset_library.common.functions import (norm_asset_datas,)
#from asset_library.common.functions import (norm_asset_datas,)
from asset_library.common.bl_utils import get_addon_prefs, load_datablocks
from asset_library.common.file_utils import read_file, write_file
from asset_library.common.template import Template
@ -57,7 +57,7 @@ class AssetLibraryAdapter(PropertyGroup):
if self.is_conform:
return self.library.conform.directory
return self.library.bundle_dir
return self.library.bundle_directory
@property
def blend_depth(self):
@ -359,16 +359,10 @@ class AssetLibraryAdapter(PropertyGroup):
print(f'Read cache from {self.cache_file}')
return self.read_file(self.cache_file)
def norm_asset_datas(self, asset_file_datas):
''' Return a new flat list of asset data
the filepath keys are merge with the assets keys
'''
return norm_asset_datas(asset_file_datas)
def write_cache(self, asset_datas):
path = self.cache_file
print(f'cache file writen to {path}')
return write_file(path, list(asset_datas))
def write_cache(self, asset_descriptions):
cache_path = self.cache_file
print(f'cache file writen to {cache_path}')
return write_file(cache_path, list(asset_descriptions))
def prop_rel_path(self, path, prop):
'''Get a filepath relative to a property of the adapter'''
@ -686,13 +680,14 @@ class AssetLibraryAdapter(PropertyGroup):
self.generate_previews(asset_descriptions)
#print()
#print(cache)
#raise Exception()
elif isinstance(cache_diff, (Path, str)):
cache_diff = json.loads(Path(cache_diff).read_text(encoding='utf-8'))
if self.blend_depth == 0:
raise Exception('Blender depth must be 1 at min')
#groups = [(cache_diff)]
@ -777,7 +772,7 @@ class AssetLibraryAdapter(PropertyGroup):
bpy.ops.wm.save_as_mainfile(filepath=str(blend_path), compress=True)
if write_cache:
self.write_cache(cache)
self.write_cache(asset_descriptions)
self.write_catalog(catalog_data)
@ -851,10 +846,11 @@ class AssetLibraryAdapter(PropertyGroup):
def format_path(self, template, **kargs):
params = dict(self.to_dict(),
params = dict(
bundle_dir=Path(self.library.bundle_directory),
conform_dir=Path(self.library.conform.directory),
**kargs
**kargs,
**self.to_dict(),
)
return Template(template).format(params).resolve()

View File

@ -19,9 +19,9 @@ class CopyFolderLibrary(AssetLibraryAdapter):
includes : StringProperty()
excludes : StringProperty()
def bundle(self):
def bundle(self, cache_diff=None):
src = expandvars(self.source_directory)
dst = expandvars(self.library_path)
dst = expandvars(self.target_directory)
includes = [inc.strip() for inc in self.includes.split(',')]
excludes = [ex.strip() for ex in self.excludes.split(',')]

View File

@ -27,6 +27,7 @@ class KitsuLibrary(AssetLibraryAdapter):
name = "Kitsu"
template_name : StringProperty()
template_file : StringProperty()
source_directory : StringProperty(subtype='DIR_PATH')
url: StringProperty()
login: StringProperty()
@ -65,15 +66,15 @@ class KitsuLibrary(AssetLibraryAdapter):
directory = directory or self.source_directory
return Path(directory, self.get_asset_relative_path(name, catalog))
def get_asset_description(self, data, path):
def get_asset_description(self, data, asset_path):
modified = time.time_ns()
catalog = data['entity_type_name']
asset_path = Path(path)
asset_name = self.norm_file_name(data['name'])
asset_path = self.prop_rel_path(asset_path, 'source_directory')
#asset_name = self.norm_file_name(data['name'])
asset_description = dict(
filepath=asset_path.as_posix(),
filepath=asset_path,
modified=modified,
library_id=self.library.id,
assets=[dict(
@ -82,8 +83,8 @@ class KitsuLibrary(AssetLibraryAdapter):
description=data['description'],
tags=[],
type=self.data_type,
image=str(self.template_image.format(name=asset_name)),
video=str(self.template_video.format(name=asset_name)),
image=self.template_image.raw,
video=self.template_video.raw,
name=data['name'])
]
)
@ -125,7 +126,7 @@ class KitsuLibrary(AssetLibraryAdapter):
asset_data['entity_type_name'] = entity_types_ids[asset_data.pop('entity_type_id')]
asset_name = asset_data['name']
asset_field_data = dict(name=asset_name, type=asset_data['entity_type_name'])
asset_field_data = dict(name=asset_name, type=asset_data['entity_type_name'], source_directory=self.source_directory)
try:
asset_field_data.update(template_name.parse(asset_name))

View File

@ -63,7 +63,8 @@ class ASSETLIB_OT_load_asset(Operator):
self.report({"ERROR"}, 'No asset selected')
return {'CANCELLED'}
fp = expandvars(asset.asset_data['filepath'])
asset_path = asset.asset_data['filepath']
fp = lib.adapter.format_path(asset_path)
name = asset.name
## set mode to object

View File

@ -85,7 +85,7 @@ def get_active_catalog():
return ''
"""
def norm_asset_datas(asset_file_datas):
''' Return a new flat list of asset data
the filepath keys are merge with the assets keys'''
@ -180,7 +180,7 @@ def get_asset_source(replace_local=False):
source_path = re.sub(actionlib_dir_local, actionlib_dir, source_path)
return source_path
""""
'''
def get_catalog_path(filepath=None):
filepath = filepath or bpy.data.filepath

View File

@ -12,17 +12,17 @@ class Template:
def __init__(self, template):
#asset_data_path = Path(lib_path) / ASSETLIB_FILENAME
self.template = template
self.raw = template
@property
def glob_pattern(self):
pattern = self.field_pattern_recursive.sub('**', self.template)
pattern = self.field_pattern_recursive.sub('**', self.raw)
pattern = self.field_pattern.sub('*', pattern)
return pattern
@property
def re_pattern(self):
pattern = self.field_pattern_recursive.sub('([\\\w -_.\/]+)', self.template)
pattern = self.field_pattern_recursive.sub('([\\\w -_.\/]+)', self.raw)
pattern = self.field_pattern.sub('([\\\w -_.]+)', pattern)
pattern = pattern.replace('?', '.')
pattern = pattern.replace('*', '.*')
@ -31,7 +31,7 @@ class Template:
@property
def fields(self):
return self.field_pattern.findall(self.template)
return self.field_pattern.findall(self.raw)
#return [f or '0' for f in fields]
def parse(self, path):
@ -57,9 +57,9 @@ class Template:
data = {**(data or {}), **kargs}
try:
path = self.template.format(**data)
path = self.raw.format(**data)
except KeyError as e:
print(f'Cannot format {self.template} with {data}, field {e} is missing')
print(f'Cannot format {self.raw} with {data}, field {e} is missing')
return
path = os.path.expandvars(path)
@ -84,4 +84,4 @@ class Template:
return Path(paths[0])
def __repr__(self):
return f'Template({self.template})'
return f'Template({self.raw})'