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') 21 22 23def create_asset(local_svgs_dir, target_dir): 24 """Create the asset.""" 25 target_dir = os.path.realpath(target_dir) 26 27 if not os.path.exists(target_dir): 28 os.makedirs(target_dir) 29 30 # Download the SVGs specified in tools/svg/svgs.txt 31 download_svgs_cmd = [ 32 'python', os.path.join(SVG_TOOLS, 'svg_downloader.py'), 33 '--output_dir', target_dir, 34 ] 35 subprocess.check_call(download_svgs_cmd) 36 37 # Copy over the SVGs from local_svgs_dir (if any). 38 if local_svgs_dir and os.path.exists(local_svgs_dir): 39 for svg_filename in os.listdir(local_svgs_dir): 40 shutil.copy(src=os.path.join(local_svgs_dir, svg_filename), 41 dst=os.path.join(target_dir, svg_filename)) 42 43 44def main(): 45 parser = argparse.ArgumentParser() 46 parser.add_argument('--local_svgs_dir', '-l', default='') 47 parser.add_argument('--target_dir', '-t', required=True) 48 args = parser.parse_args() 49 create_asset(args.local_svgs_dir, args.target_dir) 50 51 52if __name__ == '__main__': 53 main() 54