3 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
4 # Copyright (c) 2013 Intel Corporation. All rights reserved.
5 # Use of this source code is governed by a BSD-style license that can be
6 # found in the LICENSE file.
8 ''' This script provides utils for python scripts in crosswalk.
15 def TryAddDepotToolsToPythonPath():
16 depot_tools = FindDepotToolsInPath()
18 sys.path.append(depot_tools)
19 python_path = os.environ.get('PYTHONPATH')
21 os.environ['PYTHONPATH'] = os.path.pathsep.join(
22 python_path.split(os.path.pathsep)+[depot_tools])
24 os.environ['PYTHONPATH'] = depot_tools
26 def FindDepotToolsInPath():
27 paths = os.getenv('PATH').split(os.path.pathsep)
29 if os.path.basename(path) == '':
30 # path is end with os.path.pathsep
31 path = os.path.dirname(path)
32 if os.path.basename(path) == 'depot_tools':
37 return sys.platform == 'cygwin' or sys.platform.startswith('win')
40 return sys.platform.startswith('linux')
43 return sys.platform.startswith('darwin')
51 def GetCommandOutput(command, cwd=None):
52 proc = subprocess.Popen(command, stdout=subprocess.PIPE,
53 stderr=subprocess.STDOUT, bufsize=1,
55 output = proc.communicate()[0]
56 result = proc.returncode
58 raise Exception('%s: %s' % (subprocess.list2cmdline(command), output))