Skip to content

Instantly share code, notes, and snippets.

@apontious
Created April 14, 2014 02:35
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apontious/10611853 to your computer and use it in GitHub Desktop.
Save apontious/10611853 to your computer and use it in GitHub Desktop.
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