start removing conform
parent
92f275fcea
commit
ab72a15a2c
|
@ -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.bl_utils import get_addon_prefs, load_datablocks
|
||||||
from asset_library.common.file_utils import read_file, write_file
|
from asset_library.common.file_utils import read_file, write_file
|
||||||
from asset_library.common.template import Template
|
from asset_library.common.template import Template
|
||||||
|
@ -57,7 +57,7 @@ class AssetLibraryAdapter(PropertyGroup):
|
||||||
if self.is_conform:
|
if self.is_conform:
|
||||||
return self.library.conform.directory
|
return self.library.conform.directory
|
||||||
|
|
||||||
return self.library.bundle_dir
|
return self.library.bundle_directory
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def blend_depth(self):
|
def blend_depth(self):
|
||||||
|
@ -359,16 +359,10 @@ class AssetLibraryAdapter(PropertyGroup):
|
||||||
print(f'Read cache from {self.cache_file}')
|
print(f'Read cache from {self.cache_file}')
|
||||||
return self.read_file(self.cache_file)
|
return self.read_file(self.cache_file)
|
||||||
|
|
||||||
def norm_asset_datas(self, asset_file_datas):
|
def write_cache(self, asset_descriptions):
|
||||||
''' Return a new flat list of asset data
|
cache_path = self.cache_file
|
||||||
the filepath keys are merge with the assets keys
|
print(f'cache file writen to {cache_path}')
|
||||||
'''
|
return write_file(cache_path, list(asset_descriptions))
|
||||||
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 prop_rel_path(self, path, prop):
|
def prop_rel_path(self, path, prop):
|
||||||
'''Get a filepath relative to a property of the adapter'''
|
'''Get a filepath relative to a property of the adapter'''
|
||||||
|
@ -686,13 +680,14 @@ class AssetLibraryAdapter(PropertyGroup):
|
||||||
|
|
||||||
self.generate_previews(asset_descriptions)
|
self.generate_previews(asset_descriptions)
|
||||||
|
|
||||||
|
#print()
|
||||||
|
#print(cache)
|
||||||
|
#raise Exception()
|
||||||
|
|
||||||
elif isinstance(cache_diff, (Path, str)):
|
elif isinstance(cache_diff, (Path, str)):
|
||||||
cache_diff = json.loads(Path(cache_diff).read_text(encoding='utf-8'))
|
cache_diff = json.loads(Path(cache_diff).read_text(encoding='utf-8'))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if self.blend_depth == 0:
|
if self.blend_depth == 0:
|
||||||
raise Exception('Blender depth must be 1 at min')
|
raise Exception('Blender depth must be 1 at min')
|
||||||
#groups = [(cache_diff)]
|
#groups = [(cache_diff)]
|
||||||
|
@ -777,7 +772,7 @@ class AssetLibraryAdapter(PropertyGroup):
|
||||||
bpy.ops.wm.save_as_mainfile(filepath=str(blend_path), compress=True)
|
bpy.ops.wm.save_as_mainfile(filepath=str(blend_path), compress=True)
|
||||||
|
|
||||||
if write_cache:
|
if write_cache:
|
||||||
self.write_cache(cache)
|
self.write_cache(asset_descriptions)
|
||||||
|
|
||||||
self.write_catalog(catalog_data)
|
self.write_catalog(catalog_data)
|
||||||
|
|
||||||
|
@ -851,10 +846,11 @@ class AssetLibraryAdapter(PropertyGroup):
|
||||||
|
|
||||||
def format_path(self, template, **kargs):
|
def format_path(self, template, **kargs):
|
||||||
|
|
||||||
params = dict(self.to_dict(),
|
params = dict(
|
||||||
bundle_dir=Path(self.library.bundle_directory),
|
bundle_dir=Path(self.library.bundle_directory),
|
||||||
conform_dir=Path(self.library.conform.directory),
|
conform_dir=Path(self.library.conform.directory),
|
||||||
**kargs
|
**kargs,
|
||||||
|
**self.to_dict(),
|
||||||
)
|
)
|
||||||
|
|
||||||
return Template(template).format(params).resolve()
|
return Template(template).format(params).resolve()
|
|
@ -19,9 +19,9 @@ class CopyFolderLibrary(AssetLibraryAdapter):
|
||||||
includes : StringProperty()
|
includes : StringProperty()
|
||||||
excludes : StringProperty()
|
excludes : StringProperty()
|
||||||
|
|
||||||
def bundle(self):
|
def bundle(self, cache_diff=None):
|
||||||
src = expandvars(self.source_directory)
|
src = expandvars(self.source_directory)
|
||||||
dst = expandvars(self.library_path)
|
dst = expandvars(self.target_directory)
|
||||||
|
|
||||||
includes = [inc.strip() for inc in self.includes.split(',')]
|
includes = [inc.strip() for inc in self.includes.split(',')]
|
||||||
excludes = [ex.strip() for ex in self.excludes.split(',')]
|
excludes = [ex.strip() for ex in self.excludes.split(',')]
|
||||||
|
|
|
@ -27,6 +27,7 @@ class KitsuLibrary(AssetLibraryAdapter):
|
||||||
name = "Kitsu"
|
name = "Kitsu"
|
||||||
template_name : StringProperty()
|
template_name : StringProperty()
|
||||||
template_file : StringProperty()
|
template_file : StringProperty()
|
||||||
|
source_directory : StringProperty(subtype='DIR_PATH')
|
||||||
|
|
||||||
url: StringProperty()
|
url: StringProperty()
|
||||||
login: StringProperty()
|
login: StringProperty()
|
||||||
|
@ -65,15 +66,15 @@ class KitsuLibrary(AssetLibraryAdapter):
|
||||||
directory = directory or self.source_directory
|
directory = directory or self.source_directory
|
||||||
return Path(directory, self.get_asset_relative_path(name, catalog))
|
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()
|
modified = time.time_ns()
|
||||||
catalog = data['entity_type_name']
|
catalog = data['entity_type_name']
|
||||||
asset_path = Path(path)
|
asset_path = self.prop_rel_path(asset_path, 'source_directory')
|
||||||
asset_name = self.norm_file_name(data['name'])
|
#asset_name = self.norm_file_name(data['name'])
|
||||||
|
|
||||||
asset_description = dict(
|
asset_description = dict(
|
||||||
filepath=asset_path.as_posix(),
|
filepath=asset_path,
|
||||||
modified=modified,
|
modified=modified,
|
||||||
library_id=self.library.id,
|
library_id=self.library.id,
|
||||||
assets=[dict(
|
assets=[dict(
|
||||||
|
@ -82,8 +83,8 @@ class KitsuLibrary(AssetLibraryAdapter):
|
||||||
description=data['description'],
|
description=data['description'],
|
||||||
tags=[],
|
tags=[],
|
||||||
type=self.data_type,
|
type=self.data_type,
|
||||||
image=str(self.template_image.format(name=asset_name)),
|
image=self.template_image.raw,
|
||||||
video=str(self.template_video.format(name=asset_name)),
|
video=self.template_video.raw,
|
||||||
name=data['name'])
|
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_data['entity_type_name'] = entity_types_ids[asset_data.pop('entity_type_id')]
|
||||||
asset_name = asset_data['name']
|
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:
|
try:
|
||||||
asset_field_data.update(template_name.parse(asset_name))
|
asset_field_data.update(template_name.parse(asset_name))
|
||||||
|
|
|
@ -63,7 +63,8 @@ class ASSETLIB_OT_load_asset(Operator):
|
||||||
self.report({"ERROR"}, 'No asset selected')
|
self.report({"ERROR"}, 'No asset selected')
|
||||||
return {'CANCELLED'}
|
return {'CANCELLED'}
|
||||||
|
|
||||||
fp = expandvars(asset.asset_data['filepath'])
|
asset_path = asset.asset_data['filepath']
|
||||||
|
fp = lib.adapter.format_path(asset_path)
|
||||||
name = asset.name
|
name = asset.name
|
||||||
|
|
||||||
## set mode to object
|
## set mode to object
|
||||||
|
|
|
@ -85,7 +85,7 @@ def get_active_catalog():
|
||||||
|
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
"""
|
||||||
def norm_asset_datas(asset_file_datas):
|
def norm_asset_datas(asset_file_datas):
|
||||||
''' Return a new flat list of asset data
|
''' Return a new flat list of asset data
|
||||||
the filepath keys are merge with the assets keys'''
|
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)
|
source_path = re.sub(actionlib_dir_local, actionlib_dir, source_path)
|
||||||
|
|
||||||
return source_path
|
return source_path
|
||||||
|
""""
|
||||||
'''
|
'''
|
||||||
def get_catalog_path(filepath=None):
|
def get_catalog_path(filepath=None):
|
||||||
filepath = filepath or bpy.data.filepath
|
filepath = filepath or bpy.data.filepath
|
||||||
|
|
|
@ -12,17 +12,17 @@ class Template:
|
||||||
def __init__(self, template):
|
def __init__(self, template):
|
||||||
#asset_data_path = Path(lib_path) / ASSETLIB_FILENAME
|
#asset_data_path = Path(lib_path) / ASSETLIB_FILENAME
|
||||||
|
|
||||||
self.template = template
|
self.raw = template
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def glob_pattern(self):
|
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)
|
pattern = self.field_pattern.sub('*', pattern)
|
||||||
return pattern
|
return pattern
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def re_pattern(self):
|
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 = self.field_pattern.sub('([\\\w -_.]+)', pattern)
|
||||||
pattern = pattern.replace('?', '.')
|
pattern = pattern.replace('?', '.')
|
||||||
pattern = pattern.replace('*', '.*')
|
pattern = pattern.replace('*', '.*')
|
||||||
|
@ -31,7 +31,7 @@ class Template:
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fields(self):
|
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]
|
#return [f or '0' for f in fields]
|
||||||
|
|
||||||
def parse(self, path):
|
def parse(self, path):
|
||||||
|
@ -57,9 +57,9 @@ class Template:
|
||||||
data = {**(data or {}), **kargs}
|
data = {**(data or {}), **kargs}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
path = self.template.format(**data)
|
path = self.raw.format(**data)
|
||||||
except KeyError as e:
|
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
|
return
|
||||||
|
|
||||||
path = os.path.expandvars(path)
|
path = os.path.expandvars(path)
|
||||||
|
@ -84,4 +84,4 @@ class Template:
|
||||||
return Path(paths[0])
|
return Path(paths[0])
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f'Template({self.template})'
|
return f'Template({self.raw})'
|
Loading…
Reference in New Issue