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