Created
June 1, 2016 04:05
-
-
Save enginebai/bf5c9af39cc572659f3e6c64945a24c7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# !/usr/bin/python | |
# -*- coding: utf8 -*- | |
import os | |
import sys | |
import re | |
__author__ = 'enginebai' | |
drawable_root = 'drawable' | |
drawable_dirs = (drawable_root + '-mdpi', drawable_root + '-hdpi', | |
drawable_root + '-xhdpi', drawable_root + '-xxhdpi') | |
suffixs = ('@1x', '@1.5x', '@2x', '@3x') | |
current_directory = '.' | |
if sys.argv[1]: | |
current_directory = sys.argv[1] | |
for dir in drawable_dirs: | |
drawable_dir = current_directory + '/' + dir | |
if not os.path.exists(drawable_dir): | |
print("Make dir " + drawable_dir) | |
os.makedirs(drawable_dir) | |
i = 0 | |
for suffix in suffixs: | |
for file in os.listdir(current_directory): | |
file_pattern = re.compile(".*" + suffix + ".*") | |
if file_pattern.match(file): | |
# print(file, drawable_dirs[i], suffixs[i]) | |
old_path = current_directory + '/' + file | |
new_path = current_directory + '/' + drawable_dirs[i] + '/' + re.sub(suffix, '', file) | |
print('Move ' + old_path + ' to ' + new_path) | |
os.rename(old_path, new_path) | |
i += 1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment