OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 # This script is used to copy all dependencies into the local directory. | 6 # This script is used to copy all dependencies into the local directory. |
7 # The package of files can then be uploaded to App Engine. | 7 # The package of files can then be uploaded to App Engine. |
8 import os | 8 import os |
9 import shutil | 9 import shutil |
10 import stat | 10 import stat |
11 import sys | 11 import sys |
12 | 12 |
13 SRC_DIR = os.path.join(sys.path[0], os.pardir, os.pardir, os.pardir, os.pardir, | 13 SRC_DIR = os.path.join(sys.path[0], os.pardir, os.pardir, os.pardir, os.pardir, |
14 os.pardir) | 14 os.pardir) |
15 THIRD_PARTY_DIR = os.path.join(SRC_DIR, 'third_party') | 15 THIRD_PARTY_DIR = os.path.join(SRC_DIR, 'third_party') |
16 LOCAL_THIRD_PARTY_DIR = os.path.join(sys.path[0], 'third_party') | 16 LOCAL_THIRD_PARTY_DIR = os.path.join(sys.path[0], 'third_party') |
17 TOOLS_DIR = os.path.join(SRC_DIR, 'tools') | 17 TOOLS_DIR = os.path.join(SRC_DIR, 'tools') |
18 SCHEMA_COMPILER_FILES = ['model.py', 'idl_schema.py', 'schema_util.py'] | 18 SCHEMA_COMPILER_FILES = ['model.py', |
| 19 'idl_schema.py', |
| 20 'schema_util.py', |
| 21 'ordered_dict.py', |
| 22 'json_parse.py'] |
19 | 23 |
20 def MakeInit(path): | 24 def MakeInit(path): |
21 path = os.path.join(path, '__init__.py') | 25 path = os.path.join(path, '__init__.py') |
22 with open(os.path.join(path), 'w') as f: | 26 with open(os.path.join(path), 'w') as f: |
23 os.utime(os.path.join(path), None) | 27 os.utime(os.path.join(path), None) |
24 | 28 |
25 def OnError(function, path, excinfo): | 29 def OnError(function, path, excinfo): |
26 os.chmod(path, stat.S_IWUSR) | 30 os.chmod(path, stat.S_IWUSR) |
27 function(path) | 31 function(path) |
28 | 32 |
29 def CopyThirdParty(src, dest, files=None): | 33 def CopyThirdParty(src, dest, files=None, make_init=True): |
30 dest_path = os.path.join(LOCAL_THIRD_PARTY_DIR, dest) | 34 dest_path = os.path.join(LOCAL_THIRD_PARTY_DIR, dest) |
31 if not files: | 35 if not files: |
32 shutil.copytree(src, dest_path) | 36 shutil.copytree(src, dest_path) |
33 MakeInit(dest_path) | 37 if make_init: |
| 38 MakeInit(dest_path) |
34 return | 39 return |
35 try: | 40 try: |
36 os.makedirs(dest_path) | 41 os.makedirs(dest_path) |
37 except Exception: | 42 except Exception: |
38 pass | 43 pass |
39 MakeInit(dest_path) | 44 if make_init: |
| 45 MakeInit(dest_path) |
40 for filename in files: | 46 for filename in files: |
41 shutil.copy(os.path.join(src, filename), os.path.join(dest_path, filename)) | 47 shutil.copy(os.path.join(src, filename), os.path.join(dest_path, filename)) |
42 | 48 |
43 def main(): | 49 def main(): |
44 if os.path.isdir(LOCAL_THIRD_PARTY_DIR): | 50 if os.path.isdir(LOCAL_THIRD_PARTY_DIR): |
45 try: | 51 try: |
46 shutil.rmtree(LOCAL_THIRD_PARTY_DIR, False, OnError) | 52 shutil.rmtree(LOCAL_THIRD_PARTY_DIR, False, OnError) |
47 except OSError: | 53 except OSError: |
48 print('*-------------------------------------------------------------*\n' | 54 print('*-------------------------------------------------------------*\n' |
49 '| If you are receiving an upload error, try removing |\n' | 55 '| If you are receiving an upload error, try removing |\n' |
(...skipping 13 matching lines...) Expand all Loading... |
63 MakeInit(LOCAL_THIRD_PARTY_DIR) | 69 MakeInit(LOCAL_THIRD_PARTY_DIR) |
64 | 70 |
65 # To be able to use the Handlebar class we need this import in __init__.py. | 71 # To be able to use the Handlebar class we need this import in __init__.py. |
66 with open(os.path.join(LOCAL_THIRD_PARTY_DIR, | 72 with open(os.path.join(LOCAL_THIRD_PARTY_DIR, |
67 'handlebar', | 73 'handlebar', |
68 '__init__.py'), 'a') as f: | 74 '__init__.py'), 'a') as f: |
69 f.write('from handlebar import Handlebar\n') | 75 f.write('from handlebar import Handlebar\n') |
70 | 76 |
71 if __name__ == '__main__': | 77 if __name__ == '__main__': |
72 main() | 78 main() |
OLD | NEW |