blob: 82dc2df0f20bd790a62391754bdd7c10f7fc286a [file] [log] [blame]
Chris Sosa7c931362010-10-11 19:49:01 -07001# Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved.
rtc@google.comded22402009-10-26 22:36:21 +00002# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
Gilad Arnoldabb352e2012-09-23 01:24:27 -07005import os
6import sys
7
Zdenek Behan59d8aa72011-02-24 01:09:02 +01008
Sean O'Connor14b6a0a2010-03-20 23:23:48 -07009class BuildObject(object):
rtc@google.comded22402009-10-26 22:36:21 +000010 """
joychen921e1fb2013-06-28 11:12:20 -070011 Common base class that defines key paths in the source tree.
12
13 Classes that inherit from BuildObject can access scripts in the src/scripts
14 directory, and have a handle to the static directory of the devserver.
rtc@google.comded22402009-10-26 22:36:21 +000015 """
rtc@google.com64244662009-11-12 00:52:08 +000016 def __init__(self, root_dir, static_dir):
Zdenek Behan59d8aa72011-02-24 01:09:02 +010017 self.devserver_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
rtc@google.com64244662009-11-12 00:52:08 +000018 self.static_dir = static_dir
Zdenek Behan92cece82011-03-02 22:35:04 +010019 try:
joychen921e1fb2013-06-28 11:12:20 -070020 chroot_dir = os.environ['CROS_WORKON_SRCROOT']
21 self.scripts_dir = os.path.join(chroot_dir, 'src/scripts')
22 self.images_dir = os.path.join(chroot_dir, 'src/build/images')
Zdenek Behan92cece82011-03-02 22:35:04 +010023 except KeyError:
24 # Outside of chroot: This is a corner case. Since we live either in
25 # platform/dev or /usr/bin/, scripts have to live in ../../../src/scripts
26 self.scripts_dir = os.path.abspath(os.path.join(
27 self.devserver_dir, '../../../src/scripts'))
joychen921e1fb2013-06-28 11:12:20 -070028 self.images_dir = os.path.abspath(os.path.join(
29 self.devserver_dir, '../../../src/build/images'))
30
31 def GetLatestImageDir(self, board):
32 """Returns the latest image dir based on shell script."""
33 cmd = '%s/get_latest_image.sh --board %s' % (self.scripts_dir, board)
34 return os.popen(cmd).read().strip()
joychenb0dfe552013-07-30 10:02:06 -070035
36 def GetDefaultBoardID(self):
joychen562699a2013-08-13 15:22:14 -070037 """Returns the default board id stored in .default_board.
38
39 Default to x86-generic, if that isn't set.
40 """
joychenb0dfe552013-07-30 10:02:06 -070041 board_file = '%s/.default_board' % (self.scripts_dir)
42 try:
joychen562699a2013-08-13 15:22:14 -070043 with open(board_file) as bf:
44 return bf.read().strip()
joychenb0dfe552013-07-30 10:02:06 -070045 except IOError:
46 return 'x86-generic'