-
Notifications
You must be signed in to change notification settings - Fork 35
/
util.py
executable file
·76 lines (65 loc) · 3.03 KB
/
util.py
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python
import os
import sys
import shutil
import json
import string
def split_it():
valid_chars = "%s%s" % (string.ascii_letters, string.digits)
with open("assets.json") as assets:
for asset in json.load(assets).get("assets"):
filename = ''.join(c for c in asset["name"] if c in valid_chars)
filename = filename.lower() + ".json"
with open(os.path.join("assets", filename), "w") as out:
json.dump(asset, out, indent=4)
def write_thumbnail():
for filename in os.listdir("assets"):
if filename.endswith(".json"):
with open(os.path.join("assets", filename)) as asset:
print(filename)
a = json.load(asset)
extension = None
jpg = os.path.join("assets", "images", "assets", filename.replace(".json", "-hero.jpg"))
png = os.path.join("assets", "images", "assets", filename.replace(".json", "-hero.png"))
if os.path.exists(jpg):
extension = ".jpg"
os.rename(jpg, jpg.replace("-hero.jpg", "-thumb.jpg"))
elif os.path.exists(png):
extension = ".png"
os.rename(png, png.replace("-hero.png", "-thumb.png"))
if extension:
a["images"]["hero"] = ""
a["images"]["thumb"] = filename.replace(".json", "") + "-thumb" + extension
with open(os.path.join("assets", filename), "w") as out:
json.dump(a, out, indent=4)
def write_hero():
for filename in os.listdir("assets"):
if filename.endswith(".json"):
with open(os.path.join("assets", filename)) as asset:
a = json.load(asset)
if not a.get("images").get("hero"):
hero = a["images"]["thumb"].replace("-thumb", "-hero")
if os.path.exists(os.path.join("assets", "images", "assets", hero)):
a["images"]["hero"] = hero
with open(os.path.join("assets", filename), "w") as out:
json.dump(a, out, indent=4)
def write_id():
for filename in os.listdir("assets"):
if filename.endswith(".json"):
with open(os.path.join("assets", filename)) as asset:
a = json.load(asset)
a["id"] = filename.replace(".json", "")
with open(os.path.join("assets", filename), "w") as out:
json.dump(a, out, indent=4)
def write_asset_url():
for filename in os.listdir("assets"):
if filename.endswith(".json"):
with open(os.path.join("assets", filename)) as asset:
a = json.load(asset)
a["asset_url"] = "https://github.com/defold/asset-portal/blob/master/assets/%s.json" % (filename.replace(".json", ""))
with open(os.path.join("assets", filename), "w") as out:
json.dump(a, out, indent=4)
#split_it()
#write_hero()
#write_id()
write_asset_url()