| 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' |
| (...skipping 13 matching lines...) Expand all Loading... |
| 63 MakeInit(LOCAL_THIRD_PARTY_DIR) | 68 MakeInit(LOCAL_THIRD_PARTY_DIR) |
| 64 | 69 |
| 65 # To be able to use the Handlebar class we need this import in __init__.py. | 70 # 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, | 71 with open(os.path.join(LOCAL_THIRD_PARTY_DIR, |
| 67 'handlebar', | 72 'handlebar', |
| 68 '__init__.py'), 'a') as f: | 73 '__init__.py'), 'a') as f: |
| 69 f.write('from handlebar import Handlebar\n') | 74 f.write('from handlebar import Handlebar\n') |
| 70 | 75 |
| 71 if __name__ == '__main__': | 76 if __name__ == '__main__': |
| 72 main() | 77 main() |
| OLD | NEW |