• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1from __future__ import print_function
2
3import os
4import sys
5import tempfile
6
7"""Shared functions for use in i18n scripts."""
8
9def CheckDirExists(dir, dirname):
10  if not os.path.isdir(dir):
11    print("Couldn't find %s (%s)!" % (dirname, dir))
12    sys.exit(1)
13
14
15def GetAndroidRootOrDie():
16  value = os.environ.get('ANDROID_BUILD_TOP')
17  if not value:
18    print("ANDROID_BUILD_TOP not defined: run envsetup.sh / lunch")
19    sys.exit(1);
20  CheckDirExists(value, '$ANDROID_BUILD_TOP')
21  return value
22
23
24def GetAndroidHostOutOrDie():
25  value = os.environ.get('ANDROID_HOST_OUT')
26  if not value:
27    print("ANDROID_HOST_OUT not defined: run envsetup.sh / lunch")
28    sys.exit(1);
29  CheckDirExists(value, '$ANDROID_HOST_OUT')
30  return value
31
32
33def SwitchToNewTemporaryDirectory():
34  tmp_dir = tempfile.mkdtemp('-i18n')
35  os.chdir(tmp_dir)
36  print('Created temporary directory "%s"...' % tmp_dir)
37
38
39