1*0e209d39SAndroid Build Coastguard Worker# Copyright 2015 The Android Open Source Project 2*0e209d39SAndroid Build Coastguard Worker# 3*0e209d39SAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); 4*0e209d39SAndroid Build Coastguard Worker# you may not use this file except in compliance with the License. 5*0e209d39SAndroid Build Coastguard Worker# You may obtain a copy of the License at 6*0e209d39SAndroid Build Coastguard Worker# 7*0e209d39SAndroid Build Coastguard Worker# http://www.apache.org/licenses/LICENSE-2.0 8*0e209d39SAndroid Build Coastguard Worker# 9*0e209d39SAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software 10*0e209d39SAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, 11*0e209d39SAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*0e209d39SAndroid Build Coastguard Worker# See the License for the specific language governing permissions and 13*0e209d39SAndroid Build Coastguard Worker# limitations under the License. 14*0e209d39SAndroid Build Coastguard Worker 15*0e209d39SAndroid Build Coastguard Worker"""Utility methods associated with Android source and builds.""" 16*0e209d39SAndroid Build Coastguard Worker 17*0e209d39SAndroid Build Coastguard Workerfrom __future__ import print_function 18*0e209d39SAndroid Build Coastguard Worker 19*0e209d39SAndroid Build Coastguard Workerimport os 20*0e209d39SAndroid Build Coastguard Workerimport sys 21*0e209d39SAndroid Build Coastguard Workerimport tempfile 22*0e209d39SAndroid Build Coastguard Worker 23*0e209d39SAndroid Build Coastguard Worker"""Shared functions for use in i18n scripts.""" 24*0e209d39SAndroid Build Coastguard Worker 25*0e209d39SAndroid Build Coastguard Workerdef CheckDirExists(dir, dirname): 26*0e209d39SAndroid Build Coastguard Worker if not os.path.isdir(dir): 27*0e209d39SAndroid Build Coastguard Worker print("Couldn't find %s (%s)!" % (dirname, dir)) 28*0e209d39SAndroid Build Coastguard Worker sys.exit(1) 29*0e209d39SAndroid Build Coastguard Worker 30*0e209d39SAndroid Build Coastguard Worker 31*0e209d39SAndroid Build Coastguard Workerdef GetAndroidRootOrDie(): 32*0e209d39SAndroid Build Coastguard Worker value = os.environ.get('ANDROID_BUILD_TOP') 33*0e209d39SAndroid Build Coastguard Worker if not value: 34*0e209d39SAndroid Build Coastguard Worker print("ANDROID_BUILD_TOP not defined: run envsetup.sh / lunch") 35*0e209d39SAndroid Build Coastguard Worker sys.exit(1); 36*0e209d39SAndroid Build Coastguard Worker CheckDirExists(value, '$ANDROID_BUILD_TOP') 37*0e209d39SAndroid Build Coastguard Worker return value 38*0e209d39SAndroid Build Coastguard Worker 39*0e209d39SAndroid Build Coastguard Worker 40*0e209d39SAndroid Build Coastguard Workerdef GetAndroidHostOutOrDie(): 41*0e209d39SAndroid Build Coastguard Worker value = os.environ.get('ANDROID_HOST_OUT') 42*0e209d39SAndroid Build Coastguard Worker if not value: 43*0e209d39SAndroid Build Coastguard Worker print("ANDROID_HOST_OUT not defined: run envsetup.sh / lunch") 44*0e209d39SAndroid Build Coastguard Worker sys.exit(1); 45*0e209d39SAndroid Build Coastguard Worker CheckDirExists(value, '$ANDROID_HOST_OUT') 46*0e209d39SAndroid Build Coastguard Worker return value 47*0e209d39SAndroid Build Coastguard Worker 48*0e209d39SAndroid Build Coastguard Worker 49*0e209d39SAndroid Build Coastguard Workerdef SwitchToNewTemporaryDirectory(): 50*0e209d39SAndroid Build Coastguard Worker tmp_dir = tempfile.mkdtemp('-i18n') 51*0e209d39SAndroid Build Coastguard Worker os.chdir(tmp_dir) 52*0e209d39SAndroid Build Coastguard Worker print('Created temporary directory "%s"...' % tmp_dir) 53*0e209d39SAndroid Build Coastguard Worker return tmp_dir 54*0e209d39SAndroid Build Coastguard Worker 55