Skip to content

Instantly share code, notes, and snippets.

@alex-shpak
Created July 23, 2015 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alex-shpak/a7319c1980901d3378db to your computer and use it in GitHub Desktop.
Save alex-shpak/a7319c1980901d3378db to your computer and use it in GitHub Desktop.
Script for copying multi-dimen files from material design icon set to working directories
#!/usr/local/bin/python3
import os, re, shutil
white = "white"
grey = "grey600"
black = "black"
dimensions = ["mdpi", "hdpi", "xhdpi", "xxhdpi", "xxxhdpi"]
INPUT="../material-design-icons-1.0.0"
OUTPUT="./module/src/main/res"
icons = [
["ic_menu", [white ], [ 24]],
["ic_arrow_back", [white ], [ 24]],
["ic_more_vert", [white ], [ 24]],
]
# make actual file names from icons
fileNames = set()
for icon in icons:
for color in icon[1]:
for size in icon[2]:
name = "_".join((icon[0], color, str(size))) + "dp.png"
fileNames.add(name)
for dimen in dimensions:
print(dimen, end="\t")
pattern = re.compile(".*_(18|24|36|48)dp.png")
drawableDpi = "drawable-%s" % dimen
outputDpi = os.path.join(OUTPUT, drawableDpi)
# delete old icons matching pattern
for file in os.listdir(outputDpi):
if re.search(pattern, file):
os.remove(os.path.join(outputDpi, file))
print("-", end="")
print()
print("\t", end="")
# find and copy new images
for group in os.listdir(INPUT):
group = os.path.join(INPUT, group)
if os.path.isdir(group):
for file in fileNames:
source = os.path.join(group, drawableDpi, file)
if os.path.exists(source):
shutil.copy(source, os.path.join(outputDpi, file))
print("+", end="")
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment