blob: 29c408b46f70786042a3b19a3064adbaf9d51605 [file] [log] [blame]
Chris Sosa7c931362010-10-12 02:49:011# Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved.
[email protected]ded22402009-10-26 22:36:212# 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 08:24:275import os
6import sys
7
Zdenek Behan59d8aa72011-02-24 00:09:028
Sean O'Connor14b6a0a2010-03-21 06:23:489class BuildObject(object):
[email protected]ded22402009-10-26 22:36:2110 """
joychen921e1fb2013-06-28 18:12:2011 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.
[email protected]ded22402009-10-26 22:36:2115 """
Chris Sosa7cd23202013-10-16 00:22:5716 def __init__(self, static_dir):
Zdenek Behan59d8aa72011-02-24 00:09:0217 self.devserver_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
[email protected]64244662009-11-12 00:52:0818 self.static_dir = static_dir
Chris Sosa7cd23202013-10-16 00:22:5719 self.scripts_dir = os.path.join(self.GetSourceRoot(), 'src/scripts')
20
21 @staticmethod
22 def GetSourceRoot():
23 """Returns the path to the source root."""
24 src_root = os.environ.get('CROS_WORKON_SRCROOT')
25 if not src_root:
26 src_root = os.path.join(os.path.dirname(__file__), '..', '..', '..')
27
28 return os.path.realpath(src_root)
joychen921e1fb2013-06-28 18:12:2029
30 def GetLatestImageDir(self, board):
31 """Returns the latest image dir based on shell script."""
32 cmd = '%s/get_latest_image.sh --board %s' % (self.scripts_dir, board)
33 return os.popen(cmd).read().strip()
joychenb0dfe552013-07-30 17:02:0634
35 def GetDefaultBoardID(self):
joychen562699a2013-08-13 22:22:1436 """Returns the default board id stored in .default_board.
37
38 Default to x86-generic, if that isn't set.
39 """
joychenb0dfe552013-07-30 17:02:0640 board_file = '%s/.default_board' % (self.scripts_dir)
41 try:
joychen562699a2013-08-13 22:22:1442 with open(board_file) as bf:
43 return bf.read().strip()
joychenb0dfe552013-07-30 17:02:0644 except IOError:
45 return 'x86-generic'