OLD | NEW |
| (Empty) |
1 #!/usr/bin/python | |
2 | |
3 # Copyright 2015 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 Copy a file. | |
10 """ | |
11 | |
12 import argparse | |
13 import os | |
14 import shutil | |
15 | |
16 if __name__ == '__main__': | |
17 parser = argparse.ArgumentParser() | |
18 parser.add_argument('src', help='File to copy.') | |
19 parser.add_argument('dst', help='Location to copy to.') | |
20 args = parser.parse_args() | |
21 | |
22 src = os.path.abspath(os.path.join(os.getcwd(), args.src)) | |
23 dst = os.path.abspath(os.path.join(os.getcwd(), args.dst)) | |
24 | |
25 print 'Copying from %s to %s' % (src, dst) | |
26 | |
27 src_dir = os.path.dirname(src) | |
28 if not os.path.exists(src_dir): | |
29 raise AssertionError('src directory %s does not exist!' % src_dir) | |
30 | |
31 if not os.path.exists(src): | |
32 raise AssertionError('file to copy %s does not exist' % src) | |
33 | |
34 dst_dir = os.path.dirname(dst) | |
35 if not os.path.exists(dst_dir): | |
36 print 'dst directory %s does not exist! creating it!' % dst_dir | |
37 os.makedirs(dst_dir) | |
38 | |
39 shutil.copyfile(src, dst) | |
OLD | NEW |