Index: lib/cros_build_lib.py |
diff --git a/lib/cros_build_lib.py b/lib/cros_build_lib.py |
index a0cd73c6edaac26c2324c7af158a5c00d7bf762d..71c908648f764575433251a16b45ff181df03f2e 100644 |
--- a/lib/cros_build_lib.py |
+++ b/lib/cros_build_lib.py |
@@ -4,11 +4,21 @@ |
"""Common python commands used by various build scripts.""" |
+import inspect |
+import os |
import subprocess |
import sys |
_STDOUT_IS_TTY = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty() |
+# TODO(sosa): Move logging to logging module. |
+ |
+def GetCallerName(): |
+ """Returns the name of the calling module with __main__.""" |
+ top_frame = inspect.stack()[-1][0] |
+ return os.path.basename(top_frame.f_code.co_filename) |
+ |
+ |
def RunCommand(cmd, print_cmd=True, error_ok=False, error_message=None, |
exit_code=False, redirect_stdout=False, redirect_stderr=False, |
cwd=None, input=None, enter_chroot=False): |
@@ -44,7 +54,8 @@ def RunCommand(cmd, print_cmd=True, error_ok=False, error_message=None, |
# Print out the command before running. |
if print_cmd: |
- Info('RunCommand: %s' % ' '.join(cmd)) |
+ Info('PROGRAM(%s) -> RunCommand: %s in dir %s' % |
+ (GetCallerName(), ' '.join(cmd), cwd)) |
try: |
proc = subprocess.Popen(cmd, cwd=cwd, stdin=stdin, |
@@ -56,7 +67,7 @@ def RunCommand(cmd, print_cmd=True, error_ok=False, error_message=None, |
if not error_ok and proc.returncode: |
raise Exception('Command "%s" failed.\n' % (' '.join(cmd)) + |
(error_message or error or output or '')) |
- except Exception,e: |
+ except Exception, e: |
if not error_ok: |
raise |
else: |