Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(776)

Side by Side Diff: lib/cros_build_lib.py

Issue 6765001: Add better support for getting the path to crosutils. (Closed) Base URL: http://git.chromium.org/git/crosutils.git@master
Patch Set: Add one more method for crosutils/bin Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | lib/cros_build_lib_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Common python commands used by various build scripts.""" 5 """Common python commands used by various build scripts."""
6 6
7 import inspect 7 import inspect
8 import os 8 import os
9 import re 9 import re
10 import subprocess 10 import subprocess
11 import sys 11 import sys
12 12
13 _STDOUT_IS_TTY = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty() 13 _STDOUT_IS_TTY = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()
14 CROSUTILS_DIRECTORY = os.path.dirname(os.path.dirname(
15 os.path.realpath(__file__)))
16 14
17 # TODO(sosa): Move logging to logging module. 15 # TODO(sosa): Move logging to logging module.
18 16
19 class RunCommandException(Exception): 17 class RunCommandException(Exception):
20 """Raised when there is an error in RunCommand.""" 18 """Raised when there is an error in RunCommand."""
21 pass 19 pass
22 20
23 21
24 def GetCallerName(): 22 def GetCallerName():
25 """Returns the name of the calling module with __main__.""" 23 """Returns the name of the calling module with __main__."""
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 317
320 318
321 def UnmountImage(root_dir, stateful_dir): 319 def UnmountImage(root_dir, stateful_dir):
322 """Unmounts a Chromium OS image specified by mount dir points.""" 320 """Unmounts a Chromium OS image specified by mount dir points."""
323 RunCommand(['./mount_gpt_image.sh', 321 RunCommand(['./mount_gpt_image.sh',
324 '--unmount', 322 '--unmount',
325 '--rootfs_mountpt=%s' % root_dir, 323 '--rootfs_mountpt=%s' % root_dir,
326 '--stateful_mountpt=%s' % stateful_dir, 324 '--stateful_mountpt=%s' % stateful_dir,
327 ], print_cmd=False, redirect_stdout=True, redirect_stderr=True, 325 ], print_cmd=False, redirect_stdout=True, redirect_stderr=True,
328 cwd=CROSUTILS_DIRECTORY) 326 cwd=CROSUTILS_DIRECTORY)
327
328
329 def GetCrosUtilsPath(source_dir_path=True):
330 """Return the path to src/scripts.
331
332 Args:
333 source_dir_path: If True, returns the path from the source code directory.
334 """
335 if IsInsideChroot():
336 if source_dir_path:
337 return os.path.join(os.getenv('HOME'), 'trunk', 'src', 'scripts')
338
339 return os.path.join('/usr/lib/crosutils')
340
341 # Outside the chroot => from_source.
342 return os.path.join(os.path.dirname(os.path.realpath(__file__)), '..')
343
344
345 def GetCrosUtilsBinPath(source_dir_path=True):
346 """Return the path to crosutils/bin.
347
348 Args:
349 source_dir_path: If True, returns the path from the source code directory.
350 """
351 if IsInsideChroot() and not source_dir_path:
352 return '/usr/bin'
353
354 return os.path.join(GetCrosUtilsPath(source_dir_path), 'bin')
355
356
357 def IsInsideChroot():
358 """Returns True if we are inside chroot."""
359 return os.path.exists('/etc/debian_chroot')
360
361
362 # TODO(sosa): Remove once all callers use method.
363 CROSUTILS_DIRECTORY = GetCrosUtilsPath(True)
OLDNEW
« no previous file with comments | « no previous file | lib/cros_build_lib_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698