Skip to content

Instantly share code, notes, and snippets.

@ekratskih
Last active March 14, 2017 01:10
Show Gist options
  • Save ekratskih/3666d3109356a70590ef28652ce0bd7f to your computer and use it in GitHub Desktop.
Save ekratskih/3666d3109356a70590ef28652ce0bd7f to your computer and use it in GitHub Desktop.
Export AI assets format for android format
""" Export AI format for android format """
import os
import re
import shutil
import argparse
def copy_assets(source_dir='.', destination_dir='.', override=False, is_clean=False):
""" Copy assets from source to destination """
for item in os.listdir(source_dir):
asset = re.match(r"(.*)@(.*dpi)\.png$", item)
if not asset:
continue
(filename, density) = asset.groups()
density_dir = os.path.join(destination_dir, 'drawable-' + density)
if not os.path.isdir(density_dir):
os.makedirs(density_dir)
new_filename = os.path.join(density_dir, filename + ".png")
destination_exists = os.path.exists(new_filename)
if (not destination_exists) or (destination_exists and override):
print(item + " -> " + new_filename)
shutil.copyfile(item, new_filename)
else:
print(new_filename + " already exist.")
if is_clean:
os.remove(item)
print("Remove " + item)
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Translate Adobe Illustrator export format to Android directory hierarchy.')
parser.add_argument('--source', help='Source folder.', default='.')
parser.add_argument('--destination', help='Destination folder.', default='.')
parser.add_argument('--override', help='If asset already exists should we override it?',
default=0, type=int)
parser.add_argument('--clean', help='Remove source?',
default=0, type=int)
args = parser.parse_args()
copy_assets(args.source, args.destination, args.override > 0, args.clean > 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment