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