-
Notifications
You must be signed in to change notification settings - Fork 11
/
utils.py
40 lines (29 loc) · 1.2 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from pathlib import Path
from SourceIO.library.shared.content_providers.content_manager import ContentManager
from SourceIO.library.models.mdl.v49.mdl_file import MdlV49
def collect_materials(mdl: MdlV49):
materials = []
content_manager = ContentManager()
# collect materials
for material in mdl.materials:
for cd_material_path in mdl.materials_paths:
material_full_path = content_manager.find_material(Path(cd_material_path) / material.name)
if material_full_path:
materials.append((normalize_path(material.name), cd_material_path, material_full_path))
break
else:
print(f'\033[91mFailed to find {material.name}\033[0m')
materials.append((normalize_path(material.name), '', None))
return materials
def remove_ext(path):
path = Path(path)
return path.with_suffix("")
def sanitize_name(name):
return (Path(name).stem.lower()
.replace(' ', '_')
.replace('-', '_')
.replace('.', '_')
.replace('[', '')
.replace(']', ''))
def normalize_path(path):
return Path(str(path).lower().replace(' ', '_').replace('-', '_').strip('/\\'))