preserve a single trailing newline when reformatting JSON files

This commit is contained in:
SoftFever
2026-05-05 14:58:26 +08:00
parent 7ecf2225a4
commit aa35d3ae17

View File

@@ -132,6 +132,7 @@ def update_profile_library(vendor="",profile_type="filament"):
library[profile_section] = sorted_profiles
f.seek(0)
json.dump(library, f, indent="\t", ensure_ascii=False)
f.write('\n')
f.truncate()
print(f"Profile library for {vendor} updated successfully!")
@@ -230,6 +231,7 @@ def clean_up_profile(vendor="", profile_type="", force=False):
f.seek(0)
ordered_profile = create_ordered_profile(_profile, ['type', 'name', 'renamed_from', 'inherits', 'from', 'setting_id', 'filament_id', 'instantiation'])
json.dump(ordered_profile, f, indent="\t", ensure_ascii=False)
f.write('\n')
f.truncate()
print(f"Updated profile: {full_path}")
except Exception as e:
@@ -274,6 +276,7 @@ def rename_filament_system(vendor="OrcaFilamentLibrary"):
if modified:
with open(full_path, 'w', encoding='utf-8') as f:
json.dump(data, f, indent="\t", ensure_ascii=False)
f.write('\n')
print(f"Updated {full_path}")
except Exception as e: