Skip to content

Instantly share code, notes, and snippets.

@sveinungkb
Last active July 17, 2020 13:51
Show Gist options
  • Save sveinungkb/b4601d6fc5b85b28f3f122cd9acc9aa1 to your computer and use it in GitHub Desktop.
Save sveinungkb/b4601d6fc5b85b28f3f122cd9acc9aa1 to your computer and use it in GitHub Desktop.
Small python script to pull out all versions of one or more drawables or resources, recreating their paths for all densities. Run with e.g.: python extract_assets.py ic_launcher
import sys, os
def findAsset(asset, folder):
for file in os.listdir(folder):
if os.path.isdir(folder + "/" + file):
findAsset(asset, folder + "/" + file)
if asset in file:
inFile = "%s/%s" % (folder, file)
outFolder = "exported/%s" % (folder)
outFile = "%s/%s" % (outFolder, file)
print(" - copying %s to %s" % (inFile, outFile))
if not os.path.isdir(outFolder):
os.makedirs(outFolder)
with open(inFile, 'rb') as src, open(outFile, 'wb') as dst: dst.write(src.read())
def extractAsset(asset):
findAsset(asset, 'src/main/res')
if len(sys.argv) == 1:
print("Call with the name of the asset you want to extract, like:\npython %s ic_launcher ic_login" % sys.argv[0])
for i in range(1, len(sys.argv)):
print("looking for resource %s" % sys.argv[i])
extractAsset(sys.argv[i])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment