continue refactoring

This commit is contained in:
“christopheseux”
2022-12-27 23:49:57 +01:00
parent fc405797d9
commit 575bbade7b
13 changed files with 506 additions and 156 deletions
+3
View File
@@ -332,6 +332,9 @@ def load_datablocks(src, names=None, type='objects', link=True, expr=None) -> li
return_list = not isinstance(names, str)
names = names or []
if type.isupper():
type = f'{type.lower()}s'
if not isinstance(names, (list, tuple)):
names = [names]
+11
View File
@@ -13,6 +13,17 @@ import importlib
import sys
import shutil
import contextlib
@contextlib.contextmanager
def cd(path):
"""Changes working directory and returns to previous on exit."""
prev_cwd = Path.cwd()
os.chdir(path)
try:
yield
finally:
os.chdir(prev_cwd)
def install_module(module_name, package_name=None):
'''Install a python module with pip or return it if already installed'''
+4 -2
View File
@@ -181,6 +181,7 @@ def get_asset_source(replace_local=False):
return source_path
'''
def get_catalog_path(filepath=None):
filepath = filepath or bpy.data.filepath
filepath = Path(filepath)
@@ -195,7 +196,7 @@ def get_catalog_path(filepath=None):
catalog.touch(exist_ok=False)
return catalog
'''
# def read_catalog(path, key='path'):
# cat_data = {}
@@ -219,7 +220,7 @@ def get_catalog_path(filepath=None):
# cat_data[cat_name] = {'id':cat_id, 'path':cat_path}
# return cat_data
"""
def read_catalog(path):
cat_data = {}
@@ -299,6 +300,7 @@ def create_catalog_file(json_path : str|Path, keep_existing_category : bool = Tr
print(f'Catalog saved at: {catalog_path}')
return
"""
def clear_env_libraries():
print('clear_env_libraries')
+2 -4
View File
@@ -54,14 +54,12 @@ class Template:
def format(self, data=None, **kargs):
#print('format', self.template, data, kargs)
data = {**(data or {}), **kargs}
try:
path = self.template.format(**data)
except KeyError:
print(f'Cannot format {self.template} with {data}')
except KeyError as e:
print(f'Cannot format {self.template} with {data}, field {e} is missing')
return
path = os.path.expandvars(path)