aboutsummaryrefslogtreecommitdiffhomepage
path: root/infra/bots/assets/svg/create.py
blob: 2b9df463e5a0fbc97edaf4d7f263019be261212e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python
#
# Copyright 2016 Google Inc.
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.


"""Create the asset."""


import argparse
import common
import subprocess
import os
import shutil


SVG_TOOLS = os.path.join(common.INFRA_BOTS_DIR, os.pardir, os.pardir, 'tools',
                         'svg')


def create_asset(local_svgs_dir, target_dir):
  """Create the asset."""
  target_dir = os.path.realpath(target_dir)

  if not os.path.exists(target_dir):
    os.makedirs(target_dir)

  # Download the SVGs specified in tools/svg/svgs.txt
  download_svgs_cmd = [
    'python', os.path.join(SVG_TOOLS, 'svg_downloader.py'),
    '--output_dir', target_dir,
  ]
  subprocess.check_call(download_svgs_cmd)

  # Copy over the SVGs from local_svgs_dir (if any).
  if local_svgs_dir and os.path.exists(local_svgs_dir):
    for svg_filename in os.listdir(local_svgs_dir):
      shutil.copy(src=os.path.join(local_svgs_dir, svg_filename),
                  dst=os.path.join(target_dir, svg_filename))


def main():
  parser = argparse.ArgumentParser()
  parser.add_argument('--local_svgs_dir', '-l', default='')
  parser.add_argument('--target_dir', '-t', required=True)
  args = parser.parse_args()
  create_asset(args.local_svgs_dir, args.target_dir)


if __name__ == '__main__':
  main()