Chris Sosa | 7c93136 | 2010-10-12 02:49:01 | [diff] [blame] | 1 | # Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved. |
[email protected] | ded2240 | 2009-10-26 22:36:21 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
Gilad Arnold | abb352e | 2012-09-23 08:24:27 | [diff] [blame] | 5 | import os |
| 6 | import sys |
| 7 | |
Zdenek Behan | 59d8aa7 | 2011-02-24 00:09:02 | [diff] [blame] | 8 | |
Sean O'Connor | 14b6a0a | 2010-03-21 06:23:48 | [diff] [blame] | 9 | class BuildObject(object): |
[email protected] | ded2240 | 2009-10-26 22:36:21 | [diff] [blame] | 10 | """ |
joychen | 921e1fb | 2013-06-28 18:12:20 | [diff] [blame] | 11 | 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] | ded2240 | 2009-10-26 22:36:21 | [diff] [blame] | 15 | """ |
Chris Sosa | 7cd2320 | 2013-10-16 00:22:57 | [diff] [blame] | 16 | def __init__(self, static_dir): |
Zdenek Behan | 59d8aa7 | 2011-02-24 00:09:02 | [diff] [blame] | 17 | self.devserver_dir = os.path.dirname(os.path.abspath(sys.argv[0])) |
[email protected] | 6424466 | 2009-11-12 00:52:08 | [diff] [blame] | 18 | self.static_dir = static_dir |
Chris Sosa | 7cd2320 | 2013-10-16 00:22:57 | [diff] [blame] | 19 | 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) |
joychen | 921e1fb | 2013-06-28 18:12:20 | [diff] [blame] | 29 | |
| 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() |
joychen | b0dfe55 | 2013-07-30 17:02:06 | [diff] [blame] | 34 | |
| 35 | def GetDefaultBoardID(self): |
joychen | 562699a | 2013-08-13 22:22:14 | [diff] [blame] | 36 | """Returns the default board id stored in .default_board. |
| 37 | |
| 38 | Default to x86-generic, if that isn't set. |
| 39 | """ |
joychen | b0dfe55 | 2013-07-30 17:02:06 | [diff] [blame] | 40 | board_file = '%s/.default_board' % (self.scripts_dir) |
| 41 | try: |
joychen | 562699a | 2013-08-13 22:22:14 | [diff] [blame] | 42 | with open(board_file) as bf: |
| 43 | return bf.read().strip() |
joychen | b0dfe55 | 2013-07-30 17:02:06 | [diff] [blame] | 44 | except IOError: |
| 45 | return 'x86-generic' |