Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Python script used for failed project for Edge Cases 82: Asset Catalogs
#!/usr/bin/python
import os
import json
imageInfo = dict()
def AddImageInfoForAssetDir(assetDir):
for root, dirs, files in os.walk(assetDir):
rootNameAndExt = os.path.splitext(os.path.split(root)[1]);
if rootNameAndExt[1] == ".imageset":
imageName = rootNameAndExt[0]
JSONFilePath = os.path.join(root, "Contents.json")
JSONFile = open(JSONFilePath, "r")
JSONContents = json.load(JSONFile)
imageInfo[imageName] = JSONContents
sourceRootDir = os.path.join(os.environ['SOURCE_ROOT'], os.environ['PROJECT'])
assetDirs = [x[0] for x in os.walk(sourceRootDir) if os.path.splitext(x[0])[1] == ".xcassets"]
for assetDir in assetDirs:
AddImageInfoForAssetDir(assetDir)
print imageInfo
assetCatalogJSONFileName = "AssetCatalog.json"
assetCatalogJSONFilePath = os.path.join(sourceRootDir, assetCatalogJSONFileName)
assetCatalogJSONFile = open(assetCatalogJSONFilePath, "w")
json.dump(imageInfo, assetCatalogJSONFile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment