Skip to content

Instantly share code, notes, and snippets.

@chibatching
Created February 13, 2015 02:36
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 chibatching/e4ce7d7d983fc9e6b6f8 to your computer and use it in GitHub Desktop.
Save chibatching/e4ce7d7d983fc9e6b6f8 to your computer and use it in GitHub Desktop.
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