feat: Indent generated JSON files

This allows easier version control using Git.
This commit is contained in:
oSumAtrIX 2023-10-29 23:07:24 +01:00
parent 0ccdab1569
commit 47fcdd1ce3
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
2 changed files with 7 additions and 4 deletions

View File

@ -1,7 +1,7 @@
import json
from os.path import join
from app import api
from app.utils import get_repository_name, write_json, read_json, create_if_not_exists
from app.utils import get_repository_name, to_json, write_json, read_json, create_if_not_exists
from abc import abstractmethod
@ -40,7 +40,7 @@ class ReleaseApi(Api):
tag = release["tag"]
release_path = join(path, repository_name)
release_json = json.dumps(release)
release_json = to_json(release)
create_if_not_exists(release_path)

View File

@ -5,10 +5,13 @@ import os
def write_json(text: str | dict | list, to, overwrite=True):
if not os.path.exists(to) or overwrite:
with open(to, "w") as f:
if not isinstance(text, str):
text = json.dumps(text)
text = to_json(text)
f.write(text)
def to_json(text: str | dict | list):
if not isinstance(text, str):
text = json.dumps(text, indent=2)
return text
def read_json(path, default):
if os.path.exists(path):