1cb93a386Sopenharmony_ci#!/usr/bin/env python 2cb93a386Sopenharmony_ci# 3cb93a386Sopenharmony_ci# Copyright 2016 Google Inc. 4cb93a386Sopenharmony_ci# 5cb93a386Sopenharmony_ci# Use of this source code is governed by a BSD-style license that can be 6cb93a386Sopenharmony_ci# found in the LICENSE file. 7cb93a386Sopenharmony_ci 8cb93a386Sopenharmony_ci 9cb93a386Sopenharmony_ci"""Create the asset.""" 10cb93a386Sopenharmony_ci 11cb93a386Sopenharmony_ci 12cb93a386Sopenharmony_ciimport argparse 13cb93a386Sopenharmony_ciimport subprocess 14cb93a386Sopenharmony_ciimport os 15cb93a386Sopenharmony_ciimport shutil 16cb93a386Sopenharmony_ci 17cb93a386Sopenharmony_ci 18cb93a386Sopenharmony_ciFILE_DIR = os.path.dirname(os.path.abspath(__file__)) 19cb93a386Sopenharmony_ciINFRA_BOTS_DIR = os.path.realpath(os.path.join(FILE_DIR, os.pardir, os.pardir)) 20cb93a386Sopenharmony_ciSVG_TOOLS = os.path.join(INFRA_BOTS_DIR, os.pardir, os.pardir, 'tools', 'svg') 21cb93a386Sopenharmony_ciSVG_GS_BUCKET = 'gs://skia-svgs' 22cb93a386Sopenharmony_ci 23cb93a386Sopenharmony_ci 24cb93a386Sopenharmony_cidef create_asset(target_dir): 25cb93a386Sopenharmony_ci """Create the asset.""" 26cb93a386Sopenharmony_ci target_dir = os.path.realpath(target_dir) 27cb93a386Sopenharmony_ci target_svg_dir = os.path.join(target_dir, 'svg') 28cb93a386Sopenharmony_ci target_image_dir = os.path.join(target_dir, 'images') 29cb93a386Sopenharmony_ci 30cb93a386Sopenharmony_ci if not os.path.exists(target_svg_dir): 31cb93a386Sopenharmony_ci os.makedirs(target_svg_dir) 32cb93a386Sopenharmony_ci 33cb93a386Sopenharmony_ci if not os.path.exists(target_image_dir): 34cb93a386Sopenharmony_ci os.makedirs(target_image_dir) 35cb93a386Sopenharmony_ci 36cb93a386Sopenharmony_ci # Download the SVGs specified in tools/svg/svgs.txt 37cb93a386Sopenharmony_ci download_svgs_cmd = [ 38cb93a386Sopenharmony_ci 'python', os.path.join(SVG_TOOLS, 'svg_downloader.py'), 39cb93a386Sopenharmony_ci '--output_dir', target_svg_dir, 40cb93a386Sopenharmony_ci '--input_file', os.path.join(SVG_TOOLS, 'svgs.txt'), 41cb93a386Sopenharmony_ci ] 42cb93a386Sopenharmony_ci subprocess.check_call(download_svgs_cmd) 43cb93a386Sopenharmony_ci 44cb93a386Sopenharmony_ci # Download the SVGs specified in tools/svg/svgs_parse_only.txt with a prefix. 45cb93a386Sopenharmony_ci download_svgs_parse_only_cmd = [ 46cb93a386Sopenharmony_ci 'python', os.path.join(SVG_TOOLS, 'svg_downloader.py'), 47cb93a386Sopenharmony_ci '--output_dir', target_svg_dir, 48cb93a386Sopenharmony_ci '--input_file', os.path.join(SVG_TOOLS, 'svgs_parse_only.txt'), 49cb93a386Sopenharmony_ci '--prefix', 'svgparse_', 50cb93a386Sopenharmony_ci ] 51cb93a386Sopenharmony_ci subprocess.check_call(download_svgs_parse_only_cmd) 52cb93a386Sopenharmony_ci 53cb93a386Sopenharmony_ci # Download the image resources specified in tools/svg/svg_images.txt 54cb93a386Sopenharmony_ci download_images_cmd = [ 55cb93a386Sopenharmony_ci 'python', os.path.join(SVG_TOOLS, 'svg_downloader.py'), 56cb93a386Sopenharmony_ci '--output_dir', target_image_dir, 57cb93a386Sopenharmony_ci '--input_file', os.path.join(SVG_TOOLS, 'svg_images.txt'), 58cb93a386Sopenharmony_ci '--keep_common_prefix', 59cb93a386Sopenharmony_ci ] 60cb93a386Sopenharmony_ci subprocess.check_call(download_images_cmd) 61cb93a386Sopenharmony_ci 62cb93a386Sopenharmony_ci # Download SVGs from Google storage. 63cb93a386Sopenharmony_ci # The Google storage bucket will either contain private SVGs or SVGs which we 64cb93a386Sopenharmony_ci # cannot download over the internet using svg_downloader.py. 65cb93a386Sopenharmony_ci for skbug in ['skbug4713', 'skbug6918', 'skbug11244']: 66cb93a386Sopenharmony_ci subprocess.check_call([ 67cb93a386Sopenharmony_ci 'gsutil', '-m', 'cp', os.path.join(SVG_GS_BUCKET, skbug, '*'), 68cb93a386Sopenharmony_ci target_svg_dir 69cb93a386Sopenharmony_ci ]) 70cb93a386Sopenharmony_ci 71cb93a386Sopenharmony_ci 72cb93a386Sopenharmony_cidef main(): 73cb93a386Sopenharmony_ci parser = argparse.ArgumentParser() 74cb93a386Sopenharmony_ci parser.add_argument('--target_dir', '-t', required=True) 75cb93a386Sopenharmony_ci args = parser.parse_args() 76cb93a386Sopenharmony_ci create_asset(args.target_dir) 77cb93a386Sopenharmony_ci 78cb93a386Sopenharmony_ci 79cb93a386Sopenharmony_ciif __name__ == '__main__': 80cb93a386Sopenharmony_ci main() 81