-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileProcessor.py
More file actions
59 lines (51 loc) · 1.98 KB
/
fileProcessor.py
File metadata and controls
59 lines (51 loc) · 1.98 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os
class FileProcessor:
#list all require files, easy to update texture type or mesh type
required_files = {
'_base.usd': 'mesh',
'_texture_diff.png': 'diff',
'_texture_MR.png': 'mr',
'_texture_normal.png': 'normal',
}
def __init__(self, folder_path):
self.folder_path = folder_path
self.type_names = set(self.required_files.values())
def get_assets(self):
assets = {}
if not os.path.isdir(self.folder_path):
raise Exception("Specified path does not exist")
for file_name in os.listdir(self.folder_path):
full_path = os.path.join(self.folder_path, file_name)
if not os.path.isfile(full_path):
continue
for suffix, type_name in self.required_files.items():
if file_name.endswith(suffix):
name = file_name[:-len(suffix)]
if name not in assets:
assets[name] = {t: '' for t in self.type_names}
assets[name][type_name] = full_path
break
return assets
def validate_files(self):
assets = self.get_assets()
valid_prefixes = {}
for name, files in assets.items():
missing_files = [t for t, path in files.items() if not path and t != 'mat']
if missing_files:
print(f"Prefix '{name}' is missing the following files:")
for missing in missing_files:
print(f" - {missing}")
else:
valid_prefixes[name] = files
return valid_prefixes
def main():
folder_path = r"D:\Asset_Pipeline_Test\Assets"
processor = FileProcessor(folder_path)
valid_files = processor.validate_files()
#print sourves relation
for prefix, files in valid_files.items():
print(f"----- {prefix} -----")
for key, value in files.items():
print(f"{key:<10}: {value}")
print()
main()