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