|
23 | 23 | import sys |
24 | 24 | import copy |
25 | 25 | import shutil |
| 26 | +import time |
26 | 27 | import json |
27 | 28 | import logging |
28 | 29 | import tempfile |
29 | 30 | import platform |
30 | 31 | import contextlib |
| 32 | +import string |
31 | 33 | import binascii |
32 | 34 | from pprint import pformat |
33 | 35 | from subprocess import Popen, PIPE |
@@ -118,6 +120,37 @@ def create_clidriver(): |
118 | 120 | return driver |
119 | 121 |
|
120 | 122 |
|
| 123 | +def get_aws_cmd(): |
| 124 | + global AWS_CMD |
| 125 | + import awscli |
| 126 | + if AWS_CMD is None: |
| 127 | + # Try <repo>/bin/aws |
| 128 | + repo_root = os.path.dirname(os.path.abspath(awscli.__file__)) |
| 129 | + aws_cmd = os.path.join(repo_root, 'bin', 'aws') |
| 130 | + if not os.path.isfile(aws_cmd): |
| 131 | + aws_cmd = _search_path_for_cmd('aws') |
| 132 | + if aws_cmd is None: |
| 133 | + raise ValueError('Could not find "aws" executable. Either ' |
| 134 | + 'make sure it is on your PATH, or you can ' |
| 135 | + 'explicitly set this value using ' |
| 136 | + '"set_aws_cmd()"') |
| 137 | + AWS_CMD = aws_cmd |
| 138 | + return AWS_CMD |
| 139 | + |
| 140 | + |
| 141 | +def _search_path_for_cmd(cmd_name): |
| 142 | + for path in os.environ.get('PATH', '').split(os.pathsep): |
| 143 | + full_cmd_path = os.path.join(path, cmd_name) |
| 144 | + if os.path.isfile(full_cmd_path): |
| 145 | + return full_cmd_path |
| 146 | + return None |
| 147 | + |
| 148 | + |
| 149 | +def set_aws_cmd(aws_cmd): |
| 150 | + global AWS_CMD |
| 151 | + AWS_CMD = aws_cmd |
| 152 | + |
| 153 | + |
121 | 154 | @contextlib.contextmanager |
122 | 155 | def temporary_file(mode): |
123 | 156 | """This is a cross platform temporary file creation. |
@@ -606,8 +639,11 @@ def aws(command, collect_memory=False, env_vars=None, |
606 | 639 | """ |
607 | 640 | if platform.system() == 'Windows': |
608 | 641 | command = _escape_quotes(command) |
609 | | - module = "awscli" if sys.version_info[:2] >= (2, 7) else "awscli.__main__" |
610 | | - full_command = '%s -m %s %s' % (sys.executable, module, command) |
| 642 | + if 'AWS_TEST_COMMAND' in os.environ: |
| 643 | + aws_command = os.environ['AWS_TEST_COMMAND'] |
| 644 | + else: |
| 645 | + aws_command = 'python %s' % get_aws_cmd() |
| 646 | + full_command = '%s %s' % (aws_command, command) |
611 | 647 | stdout_encoding = get_stdout_encoding() |
612 | 648 | if isinstance(full_command, six.text_type) and not six.PY3: |
613 | 649 | full_command = full_command.encode(stdout_encoding) |
|
0 commit comments