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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | lib/cros_build_lib_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/cros_build_lib.py
diff --git a/lib/cros_build_lib.py b/lib/cros_build_lib.py
index d8467576772d4048fa86c7bf171cfccfbe7eb59b..6f331a0b3b933e478a53c5e3c2d59be4ff34773e 100644
--- a/lib/cros_build_lib.py
+++ b/lib/cros_build_lib.py
@@ -11,8 +11,6 @@ import subprocess
import sys
_STDOUT_IS_TTY = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()
-CROSUTILS_DIRECTORY = os.path.dirname(os.path.dirname(
- os.path.realpath(__file__)))
# TODO(sosa): Move logging to logging module.
@@ -326,3 +324,40 @@ def UnmountImage(root_dir, stateful_dir):
'--stateful_mountpt=%s' % stateful_dir,
], print_cmd=False, redirect_stdout=True, redirect_stderr=True,
cwd=CROSUTILS_DIRECTORY)
+
+
+def GetCrosUtilsPath(source_dir_path=True):
+ """Return the path to src/scripts.
+
+ Args:
+ source_dir_path: If True, returns the path from the source code directory.
+ """
+ if IsInsideChroot():
+ if source_dir_path:
+ return os.path.join(os.getenv('HOME'), 'trunk', 'src', 'scripts')
+
+ return os.path.join('/usr/lib/crosutils')
+
+ # Outside the chroot => from_source.
+ return os.path.join(os.path.dirname(os.path.realpath(__file__)), '..')
+
+
+def GetCrosUtilsBinPath(source_dir_path=True):
+ """Return the path to crosutils/bin.
+
+ Args:
+ source_dir_path: If True, returns the path from the source code directory.
+ """
+ if IsInsideChroot() and not source_dir_path:
+ return '/usr/bin'
+
+ return os.path.join(GetCrosUtilsPath(source_dir_path), 'bin')
+
+
+def IsInsideChroot():
+ """Returns True if we are inside chroot."""
+ return os.path.exists('/etc/debian_chroot')
+
+
+# TODO(sosa): Remove once all callers use method.
+CROSUTILS_DIRECTORY = GetCrosUtilsPath(True)
« 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