build_server.py revision 5821806d5e7f356e8fa4b058a389a808ea183019
1#!/usr/bin/env python 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 4# found in the LICENSE file. 5 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. 8import os 9import shutil 10import stat 11import sys 12 13SRC_DIR = os.path.join(sys.path[0], os.pardir, os.pardir, os.pardir, os.pardir, 14 os.pardir) 15THIRD_PARTY_DIR = os.path.join(SRC_DIR, 'third_party') 16LOCAL_THIRD_PARTY_DIR = os.path.join(sys.path[0], 'third_party') 17TOOLS_DIR = os.path.join(SRC_DIR, 'tools') 18SCHEMA_COMPILER_FILES = ['model.py', 'idl_schema.py', 'schema_util.py'] 19 20def MakeInit(path): 21 path = os.path.join(path, '__init__.py') 22 with open(os.path.join(path), 'w') as f: 23 os.utime(os.path.join(path), None) 24 25def OnError(function, path, excinfo): 26 os.chmod(path, stat.S_IWUSR) 27 function(path) 28 29def CopyThirdParty(src, dest, files=None): 30 dest_path = os.path.join(LOCAL_THIRD_PARTY_DIR, dest) 31 if not files: 32 shutil.copytree(src, dest_path) 33 MakeInit(dest_path) 34 return 35 try: 36 os.makedirs(dest_path) 37 except Exception: 38 pass 39 MakeInit(dest_path) 40 for filename in files: 41 shutil.copy(os.path.join(src, filename), os.path.join(dest_path, filename)) 42 43def main(): 44 if os.path.isdir(LOCAL_THIRD_PARTY_DIR): 45 try: 46 shutil.rmtree(LOCAL_THIRD_PARTY_DIR, False, OnError) 47 except OSError: 48 print('*-------------------------------------------------------------*\n' 49 '| If you are receiving an upload error, try removing |\n' 50 '| chrome/common/extensions/docs/server2/third_party manually. |\n' 51 '*-------------------------------------------------------------*\n') 52 53 54 CopyThirdParty(os.path.join(THIRD_PARTY_DIR, 'handlebar'), 'handlebar') 55 CopyThirdParty(os.path.join(SRC_DIR, 'ppapi', 'generators'), 56 'json_schema_compiler') 57 CopyThirdParty(os.path.join(THIRD_PARTY_DIR, 'ply'), 58 os.path.join('json_schema_compiler', 'ply')) 59 CopyThirdParty(os.path.join(TOOLS_DIR, 'json_schema_compiler'), 60 'json_schema_compiler', 61 SCHEMA_COMPILER_FILES) 62 CopyThirdParty(TOOLS_DIR, 'json_schema_compiler', ['json_comment_eater.py']) 63 MakeInit(LOCAL_THIRD_PARTY_DIR) 64 65 # 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, 67 'handlebar', 68 '__init__.py'), 'a') as f: 69 f.write('from handlebar import Handlebar\n') 70 71if __name__ == '__main__': 72 main() 73