Skip to content

Instantly share code, notes, and snippets.

Created April 14, 2014 02:35
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Python script used for failed project for Edge Cases 82: Asset Catalogs
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:
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