Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Copy image files with dpi suffix (_xdpi, _hdpi etc..) to Android resource folder.
"""
Copy image files with dpi suffix to Android resource folder
usage:
resource_copy.py <target-resource-folder> <source-file>...
"""
import os
import glob
import sys
import re
import shutil
from docopt import docopt
if __name__ == '__main__':
args = docopt(__doc__)
files = args['<source-file>']
target = os.path.abspath(args['<target-resource-folder>'])
for source in files:
name = os.path.basename(source)
expr = re.compile(r'(.+)_([lmhx]{1,3}dpi)\.png')
match = expr.match(name)
if match is None:
continue
base_name = match.group(1)
dpi = match.group(2)
t_dir = os.path.join(target, "drawable-" + dpi)
if os.path.exists(t_dir):
t_fname = os.path.join(t_dir, base_name + ".png")
print(source + " > " + t_fname)
shutil.copyfile(os.path.abspath(source), t_fname)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment