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 'json_parse.py'] |
19 | 22 |
20 def MakeInit(path): | 23 def MakeInit(path): |
21 path = os.path.join(path, '__init__.py') | 24 path = os.path.join(path, '__init__.py') |
22 with open(os.path.join(path), 'w') as f: | 25 with open(os.path.join(path), 'w') as f: |
23 os.utime(os.path.join(path), None) | 26 os.utime(os.path.join(path), None) |
24 | 27 |
25 def OnError(function, path, excinfo): | 28 def OnError(function, path, excinfo): |
26 os.chmod(path, stat.S_IWUSR) | 29 os.chmod(path, stat.S_IWUSR) |
27 function(path) | 30 function(path) |
28 | 31 |
29 def CopyThirdParty(src, dest, files=None): | 32 def CopyThirdParty(src, dest, files=None, make_init=True): |
30 dest_path = os.path.join(LOCAL_THIRD_PARTY_DIR, dest) | 33 dest_path = os.path.join(LOCAL_THIRD_PARTY_DIR, dest) |
31 if not files: | 34 if not files: |
32 shutil.copytree(src, dest_path) | 35 shutil.copytree(src, dest_path) |
33 MakeInit(dest_path) | 36 if make_init: |
| 37 MakeInit(dest_path) |
34 return | 38 return |
35 try: | 39 try: |
36 os.makedirs(dest_path) | 40 os.makedirs(dest_path) |
37 except Exception: | 41 except Exception: |
38 pass | 42 pass |
39 MakeInit(dest_path) | 43 if make_init: |
| 44 MakeInit(dest_path) |
40 for filename in files: | 45 for filename in files: |
41 shutil.copy(os.path.join(src, filename), os.path.join(dest_path, filename)) | 46 shutil.copy(os.path.join(src, filename), os.path.join(dest_path, filename)) |
42 | 47 |
43 def main(): | 48 def main(): |
44 if os.path.isdir(LOCAL_THIRD_PARTY_DIR): | 49 if os.path.isdir(LOCAL_THIRD_PARTY_DIR): |
45 try: | 50 try: |
46 shutil.rmtree(LOCAL_THIRD_PARTY_DIR, False, OnError) | 51 shutil.rmtree(LOCAL_THIRD_PARTY_DIR, False, OnError) |
47 except OSError: | 52 except OSError: |
48 print('*-------------------------------------------------------------*\n' | 53 print('*-------------------------------------------------------------*\n' |
49 '| If you are receiving an upload error, try removing |\n' | 54 '| If you are receiving an upload error, try removing |\n' |
50 '| chrome/common/extensions/docs/server2/third_party manually. |\n' | 55 '| chrome/common/extensions/docs/server2/third_party manually. |\n' |
51 '*-------------------------------------------------------------*\n') | 56 '*-------------------------------------------------------------*\n') |
52 | 57 |
53 | 58 |
54 CopyThirdParty(os.path.join(THIRD_PARTY_DIR, 'handlebar'), 'handlebar') | 59 CopyThirdParty(os.path.join(THIRD_PARTY_DIR, 'handlebar'), 'handlebar') |
55 CopyThirdParty(os.path.join(SRC_DIR, 'ppapi', 'generators'), | 60 CopyThirdParty(os.path.join(SRC_DIR, 'ppapi', 'generators'), |
56 'json_schema_compiler') | 61 'json_schema_compiler') |
57 CopyThirdParty(os.path.join(THIRD_PARTY_DIR, 'ply'), | 62 CopyThirdParty(os.path.join(THIRD_PARTY_DIR, 'ply'), |
58 os.path.join('json_schema_compiler', 'ply')) | 63 os.path.join('json_schema_compiler', 'ply')) |
59 CopyThirdParty(os.path.join(TOOLS_DIR, 'json_schema_compiler'), | 64 CopyThirdParty(os.path.join(TOOLS_DIR, 'json_schema_compiler'), |
60 'json_schema_compiler', | 65 'json_schema_compiler', |
61 SCHEMA_COMPILER_FILES) | 66 SCHEMA_COMPILER_FILES) |
62 CopyThirdParty(TOOLS_DIR, 'json_schema_compiler', ['json_comment_eater.py']) | 67 CopyThirdParty(TOOLS_DIR, 'json_schema_compiler', ['json_comment_eater.py']) |
| 68 CopyThirdParty(os.path.join(THIRD_PARTY_DIR, 'simplejson'), |
| 69 os.path.join('json_schema_compiler', 'simplejson'), |
| 70 make_init=False) |
63 MakeInit(LOCAL_THIRD_PARTY_DIR) | 71 MakeInit(LOCAL_THIRD_PARTY_DIR) |
64 | 72 |
65 # To be able to use the Handlebar class we need this import in __init__.py. | 73 # 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, | 74 with open(os.path.join(LOCAL_THIRD_PARTY_DIR, |
67 'handlebar', | 75 'handlebar', |
68 '__init__.py'), 'a') as f: | 76 '__init__.py'), 'a') as f: |
69 f.write('from handlebar import Handlebar\n') | 77 f.write('from handlebar import Handlebar\n') |
70 | 78 |
71 if __name__ == '__main__': | 79 if __name__ == '__main__': |
72 main() | 80 main() |
OLD | NEW |