aboutsummaryrefslogtreecommitdiffhomepage
path: root/gyp/copy_file.py
blob: 7268bf216ffbeafed37f81717c70f52bc629e477 (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
#!/usr/bin/python

# Copyright 2015 Google Inc.
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""
Copy a file.
"""

import argparse
import os
import shutil

if __name__ == '__main__':
  parser = argparse.ArgumentParser()
  parser.add_argument('src', help='File to copy.')
  parser.add_argument('dst', help='Location to copy to.')
  args = parser.parse_args()

  src = os.path.abspath(os.path.join(os.getcwd(), args.src))
  dst = os.path.abspath(os.path.join(os.getcwd(), args.dst))

  print 'Copying from %s to %s' % (src, dst)

  src_dir = os.path.dirname(src)
  if not os.path.exists(src_dir):
    raise AssertionError('src directory %s does not exist!' % src_dir)

  if not os.path.exists(src):
    raise AssertionError('file to copy %s does not exist' % src)

  dst_dir = os.path.dirname(dst)
  if not os.path.exists(dst_dir):
    print 'dst directory %s does not exist! creating it!' % dst_dir
    os.makedirs(dst_dir)

  shutil.copyfile(src, dst)