| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium 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 """This module contains util functions that local scripts can use.""" | 5 """This module contains util functions that local scripts can use.""" |
| 6 | 6 |
| 7 import logging |
| 7 import os | 8 import os |
| 9 import subprocess |
| 8 import sys | 10 import sys |
| 9 | 11 |
| 10 | 12 |
| 11 def SetUpSystemPaths(): | 13 def SetUpSystemPaths(): # pragma: no cover |
| 12 """Sets system paths so as to import modules in findit, third_party and | 14 """Sets system paths so as to import modules in findit, third_party and |
| 13 appengine.""" | 15 appengine.""" |
| 14 findit_root_dir = os.path.join(os.path.dirname(__file__), os.path.pardir) | 16 findit_root_dir = os.path.join(os.path.dirname(__file__), os.path.pardir) |
| 15 third_party_dir = os.path.join(findit_root_dir, 'third_party') | 17 third_party_dir = os.path.join(findit_root_dir, 'third_party') |
| 16 appengine_sdk_dir = os.path.join(findit_root_dir, os.path.pardir, | 18 appengine_sdk_dir = os.path.join(findit_root_dir, os.path.pardir, |
| 17 os.path.pardir, os.path.pardir, | 19 os.path.pardir, os.path.pardir, |
| 18 'google_appengine') | 20 'google_appengine') |
| 19 | 21 |
| 20 # Add App Engine SDK dir to sys.path. | 22 # Add App Engine SDK dir to sys.path. |
| 21 sys.path.insert(1, appengine_sdk_dir) | 23 sys.path.insert(1, appengine_sdk_dir) |
| 22 sys.path.insert(1, third_party_dir) | 24 sys.path.insert(1, third_party_dir) |
| 23 import dev_appserver | 25 import dev_appserver |
| 24 dev_appserver.fix_sys_path() | 26 dev_appserver.fix_sys_path() |
| 25 | 27 |
| 26 # Add Findit root dir to sys.path so that modules in Findit is available. | 28 # Add Findit root dir to sys.path so that modules in Findit is available. |
| 27 sys.path.insert(1, findit_root_dir) | 29 sys.path.insert(1, findit_root_dir) |
| 30 |
| 31 |
| 32 # TODO(katesonia): Add local cache for this function. |
| 33 def GetCommandOutput(command): |
| 34 """Gets the output stream of executable command. |
| 35 |
| 36 Args: |
| 37 command (str): Command to execute to get output. |
| 38 |
| 39 Return: |
| 40 Output steam of the command. |
| 41 """ |
| 42 p = subprocess.Popen( |
| 43 command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) |
| 44 stdoutdata, stderrdata = p.communicate() |
| 45 |
| 46 if p.returncode != 0: |
| 47 logging.error('Error running command %s: %s', command, stderrdata) |
| 48 return None |
| 49 |
| 50 return stdoutdata |
| OLD | NEW |