Created
February 13, 2015 02:36
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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