Refactor combined.json

This commit is contained in:
relikd
2020-09-07 17:11:34 +02:00
parent f2b9e87f01
commit 5f1f6e4124
7 changed files with 158 additions and 129 deletions

View File

@@ -77,6 +77,19 @@ def valid_bundle_id(bundle_id):
return regex_bundle_id.match(bundle_id)
def app_name(bundle_id, fallback=None):
def name_for(lang):
try:
return json_read_meta(bundle_id, lang)['trackCensoredName']
except Exception:
return None
for lang in ['us', 'de']:
name = name_for(lang)
if name:
return name
return fallback
def err(scope, msg, logOnly=False):
if isinstance(msg, Exception):
msg = traceback.format_exc()
@@ -146,6 +159,14 @@ def meta_json_exists(bundle_id, lang):
return file_exists(path_data_app(bundle_id, 'info_{}.json'.format(lang)))
def mkdir_out_app(bundle_id):
out_dir = path_out_app(bundle_id)
if not dir_exists(out_dir):
mkdir(out_dir)
return True
return False
def next_path(path_pattern):
i = 1
while os.path.exists(path_pattern % i):
@@ -249,7 +270,7 @@ def json_write(path, obj, pretty=False):
def json_write_combined(bundle_id, obj):
fname = path_data_app(bundle_id, 'combined.json')
json_write(fname, obj, pretty=True)
json_write(fname, obj, pretty=False)
def json_write_meta(bundle_id, obj, lang):