Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: build/toolchain/mac/copy_bundle_data.py

Issue 2075463002: [Mac/iOS/GN] Use rsync in copy_bundle_data instead of shutil.copytree. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import argparse 5 import argparse
6 import errno
6 import os 7 import os
7 import shutil 8 import shutil
8 import sys 9 import sys
10 import subprocess
9 11
10 12
11 def detect_encoding(data, default_encoding='UTF-8'): 13 def detect_encoding(data, default_encoding='UTF-8'):
12 """Detects the encoding used by |data| from the Byte-Order-Mark if present. 14 """Detects the encoding used by |data| from the Byte-Order-Mark if present.
13 15
14 Args: 16 Args:
15 data: string whose encoding needs to be detected 17 data: string whose encoding needs to be detected
16 default_encoding: encoding returned if no BOM is found. 18 default_encoding: encoding returned if no BOM is found.
17 19
18 Returns: 20 Returns:
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 dest_file.write(data.decode(encoding).encode('UTF-16')) 59 dest_file.write(data.decode(encoding).encode('UTF-16'))
58 60
59 61
60 def copy_file(source, dest): 62 def copy_file(source, dest):
61 """Copies a file or directory from |source| to |dest|. 63 """Copies a file or directory from |source| to |dest|.
62 64
63 Args: 65 Args:
64 source: string, path to the source file 66 source: string, path to the source file
65 dest: string, path to the destination file 67 dest: string, path to the destination file
66 """ 68 """
67 if os.path.isdir(source): 69 try:
68 if os.path.exists(dest): 70 shutil.rmtree(dest)
69 shutil.rmtree(dest) 71 except OSError as e:
70 # Copy tree. 72 if e.errno == errno.ENOENT:
71 # TODO(thakis): This copies file attributes like mtime, while the 73 pass
72 # single-file branch below doesn't. This should probably be changed to 74 elif e.errno == errno.ENOTDIR:
73 # be consistent with the single-file branch. 75 os.unlink(dest)
74 shutil.copytree(source, dest, symlinks=True) 76 else:
75 return 77 raise
76 78
77 if os.path.exists(dest):
78 os.unlink(dest)
79 79
80 _, extension = os.path.splitext(source) 80 _, extension = os.path.splitext(source)
81 if extension == '.strings': 81 if extension == '.strings':
82 copy_strings_file(source, dest) 82 copy_strings_file(source, dest)
83 return 83 return
84 84
85 shutil.copy(source, dest) 85 subprocess.check_call(
86 ['rsync', '--recursive', '--perms', '--links', source, dest])
Dirk Pranke 2016/06/15 22:11:40 I'm not sure if this'll do the right thing. If yo
Robert Sesek 2016/06/15 22:31:16 Good catch. Will strip the trailing slash(es) on t
86 87
87 88
88 def main(): 89 def main():
89 parser = argparse.ArgumentParser( 90 parser = argparse.ArgumentParser(
90 description='copy source to destination for the creation of a bundle') 91 description='copy source to destination for the creation of a bundle')
91 parser.add_argument('source', help='path to source file or directory') 92 parser.add_argument('source', help='path to source file or directory')
92 parser.add_argument('dest', help='path to destination') 93 parser.add_argument('dest', help='path to destination')
93 args = parser.parse_args() 94 args = parser.parse_args()
94 95
95 copy_file(args.source, args.dest) 96 copy_file(args.source, args.dest)
96 97
97 if __name__ == '__main__': 98 if __name__ == '__main__':
98 main() 99 main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698