OLD | NEW |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 """Defines the client library.""" | 5 """Defines the client library.""" |
6 | 6 |
7 import argparse | 7 import argparse |
8 import datetime | 8 import datetime |
9 import logging | 9 import logging |
10 import os | 10 import os |
11 import socket | 11 import socket |
12 import subprocess | 12 import subprocess |
13 import sys | 13 import sys |
14 import tempfile | 14 import tempfile |
15 import threading | 15 import threading |
16 import xmlrpclib | 16 import xmlrpclib |
17 | 17 |
18 #pylint: disable=relative-import | 18 #pylint: disable=relative-import |
19 import common_lib | 19 import common_lib |
20 | 20 |
21 THIS_DIR = os.path.dirname(os.path.abspath(__file__)) | 21 ISOLATE_PY = os.path.join(common_lib.SWARMING_DIR, 'isolate.py') |
22 SWARMING_DIR = os.path.join(THIS_DIR, '..', '..', 'tools/swarming_client') | 22 SWARMING_PY = os.path.join(common_lib.SWARMING_DIR, 'swarming.py') |
23 ISOLATE_PY = os.path.join(SWARMING_DIR, 'isolate.py') | |
24 SWARMING_PY = os.path.join(SWARMING_DIR, 'swarming.py') | |
25 | 23 |
26 | 24 |
27 class Error(Exception): | 25 class Error(Exception): |
28 pass | 26 pass |
29 | 27 |
30 | 28 |
31 class ConnectionTimeoutError(Error): | 29 class ConnectionTimeoutError(Error): |
32 pass | 30 pass |
33 | 31 |
34 | 32 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 ]) | 193 ]) |
196 | 194 |
197 self._ExecuteProcess(cmd) | 195 self._ExecuteProcess(cmd) |
198 | 196 |
199 def _ExecuteProcess(self, cmd): | 197 def _ExecuteProcess(self, cmd): |
200 """Executes a process, waits for it to complete, and checks for success.""" | 198 """Executes a process, waits for it to complete, and checks for success.""" |
201 logging.debug('Running %s', ' '.join(cmd)) | 199 logging.debug('Running %s', ' '.join(cmd)) |
202 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | 200 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
203 _, stderr = p.communicate() | 201 _, stderr = p.communicate() |
204 if p.returncode != 0: | 202 if p.returncode != 0: |
205 stderr.seek(0) | |
206 raise Error(stderr) | 203 raise Error(stderr) |
207 | 204 |
208 def OnConnect(self, ip_address): | 205 def OnConnect(self, ip_address): |
209 """Receives client ip address on connection.""" | 206 """Receives client ip address on connection.""" |
210 self._ip_address = ip_address | 207 self._ip_address = ip_address |
211 self._connected = True | 208 self._connected = True |
212 self._rpc = common_lib.ConnectToServer(self._ip_address) | 209 self._rpc = common_lib.ConnectToServer(self._ip_address) |
213 logging.info('%s connected from %s', self._name, ip_address) | 210 logging.info('%s connected from %s', self._name, ip_address) |
214 self._connect_event.set() | 211 self._connect_event.set() |
OLD | NEW |