Feature/add_snapmaker_u1_profiles (#10225)

* add snapmaker u1 profiles

* tweak some parameters for U1
This commit is contained in:
SoftFever 2025-07-25 22:25:28 +08:00 committed by GitHub
parent 1ef427f661
commit 68110eeecc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
105 changed files with 4619 additions and 221 deletions

View file

@ -49,16 +49,16 @@ def topological_sort(filaments):
return result
def update_filament_library(vendor="OrcaFilamentLibrary"):
def update_profile_library(vendor="OrcaFilamentLibrary",profile_type="filament"):
# change current working directory to the relative path(..\resources\profiles) compare to script location
os.chdir(os.path.join(os.path.dirname(__file__), '..', 'resources', 'profiles'))
# Collect current filament entries
current_filaments = []
# Collect current profile entries
current_profiles = []
base_dir = vendor
filament_dir = os.path.join(base_dir, 'filament')
profile_dir = os.path.join(base_dir, profile_type)
for root, dirs, files in os.walk(filament_dir):
for root, dirs, files in os.walk(profile_dir):
for file in files:
if file.lower().endswith('.json'):
full_path = os.path.join(root, file)
@ -79,32 +79,34 @@ def update_filament_library(vendor="OrcaFilamentLibrary"):
}
if inherits:
entry['inherits'] = inherits
current_filaments.append(entry)
current_profiles.append(entry)
else:
print(f"Warning: Missing 'name' in {full_path}")
except Exception as e:
print(f"Error reading {full_path}: {str(e)}")
continue
# Sort filaments based on inheritance
sorted_filaments = topological_sort(current_filaments)
# Sort profiles based on inheritance
sorted_profiles = topological_sort(current_profiles)
# Remove the inherits field as it's not needed in the final JSON
for filament in sorted_filaments:
filament.pop('inherits', None)
for p in sorted_profiles:
p.pop('inherits', None)
# Update library file
lib_path = f'{vendor}.json'
profile_section = profile_type+'_list'
try:
with open(lib_path, 'r+', encoding='utf-8') as f:
library = json.load(f)
library['filament_list'] = sorted_filaments
library[profile_section] = sorted_profiles
f.seek(0)
json.dump(library, f, indent=4, ensure_ascii=False)
f.truncate()
print(f"Filament library for {vendor} updated successfully!")
print(f"Profile library for {vendor} updated successfully!")
except Exception as e:
print(f"Error updating library file: {str(e)}")
@ -161,6 +163,7 @@ if __name__ == '__main__':
args = parser.parse_args()
if args.mode == 'update':
update_filament_library(args.vendor)
update_profile_library(args.vendor, 'filament')
update_profile_library(args.vendor, 'process')
else:
rename_filament_system(args.vendor)