def _init_common(env): logger.debug('ANDROID_HOME: {}'.format(env.android_home)) build_tools_directory = os.path.join(env.android_home, 'build-tools') if os.path.isdir(build_tools_directory): versions = os.listdir(build_tools_directory) for version in reversed(sorted(versions)): aapt_path = os.path.join(build_tools_directory, version, 'aapt') if os.path.isfile(aapt_path): logger.debug('Using aapt for version {}'.format(version)) env.aapt = aapt_path break else: raise HostError( 'aapt not found. Please make sure at least one Android platform is installed.' ) else: # User may already installed 'aapt' from package provided by distro's # Try finding in $PATH aapt_path = which('aapt') if aapt_path: logger.debug('Using aapt from {}'.format(aapt_path)) env.aapt = aapt_path else: msg = 'ANDROID_HOME ({}) does not appear to have valid Android SDK install (cannot find build-tools)' raise HostError(msg.format(env.android_home))
def _initialize_without_android_home(env): if os.name == 'nt': raise HostError('Please set ANDROID_HOME to point to the location of the Android SDK.') # Assuming Unix in what follows. if subprocess.call('adb version >{}'.format(get_null()), shell=True): raise HostError('ANDROID_HOME is not set and adb is not in PATH. Have you installed Android SDK?') logger.debug('Discovering ANDROID_HOME from adb path.') env.platform_tools = os.path.dirname(subprocess.check_output('which adb', shell=True)) env.android_home = os.path.dirname(env.platform_tools) _init_common(env) return env
def _init_common(env): logger.debug('ANDROID_HOME: {}'.format(env.android_home)) build_tools_directory = os.path.join(env.android_home, 'build-tools') if not os.path.isdir(build_tools_directory): msg = 'ANDROID_HOME ({}) does not appear to have valid Android SDK install (cannot find build-tools)' raise HostError(msg.format(env.android_home)) versions = os.listdir(build_tools_directory) for version in reversed(sorted(versions)): aapt_path = os.path.join(build_tools_directory, version, 'aapt') if os.path.isfile(aapt_path): logger.debug('Using aapt for version {}'.format(version)) env.aapt = aapt_path break else: raise HostError('aapt not found. Please make sure at least one Android platform is installed.')
def get_connection(timeout, init_dtr=None, *args, **kwargs): if init_dtr is not None: kwargs['dsrdtr'] = True try: conn = serial.Serial(*args, **kwargs) except serial.SerialException as e: raise HostError(e.message) if init_dtr is not None: conn.setDTR(init_dtr) conn.nonblocking() conn.flushOutput() target = fdpexpect.fdspawn(conn.fileno(), timeout=timeout) target.logfile_read = PexpectLogger('read') target.logfile_send = PexpectLogger('send') # Monkey-patching sendline to introduce a short delay after # chacters are sent to the serial. If two sendline s are issued # one after another the second one might start putting characters # into the serial device before the first one has finished, causing # corruption. The delay prevents that. tsln = target.sendline def sendline(x): tsln(x) time.sleep(0.1) target.sendline = sendline return target, conn
def _give_password(password, command): if not sshpass: raise HostError( 'Must have sshpass installed on the host in order to use password-based auth.' ) pass_string = "sshpass -p '{}' ".format(password) return pass_string + command
def _check_env(): global ssh, scp, sshpass # pylint: disable=global-statement if not ssh: ssh = which('ssh') scp = which('scp') sshpass = which('sshpass') if not (ssh and scp): raise HostError('OpenSSH must be installed on the host.')
def update_result(self, context): timeout_secs = 10 for _ in xrange(timeout_secs): if self.subprocess.poll() is not None: break time.sleep(1) else: output = _read_nonblock(self.subprocess.stdout) self.subprocess.kill() self.logger.error('iio-capture did not terminate gracefully') if self.subprocess.poll() is None: msg = 'Could not terminate iio-capture:\n{}' raise HostError(msg.format(output)) if not os.path.isfile(self.outfile): raise HostError('Output CSV not generated.') context.add_iteration_artifact('iio-capture', self.outfile, 'data') if os.stat(self.outfile).st_size == 0: self.logger.warning('"{}" appears to be empty'.format( self.outfile)) return self._compute_stats(context)
def __init__(self, cros_path, password=''): self.logger = logging.getLogger(self.__class__.__name__) self.in_chroot = True if which('dut-control') else False ON_POSIX = 'posix' in sys.builtin_module_names if self.in_chroot: self.cros_sdk_session = Popen(['/bin/sh'], bufsize=1, stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=cros_path, close_fds=ON_POSIX, shell=True) else: cros_sdk_bin_path = which('cros_sdk') potential_path = os.path.join( "cros_path", "chromium/tools/depot_tools/cros_sdk") if not cros_sdk_bin_path and os.path.isfile(potential_path): cros_sdk_bin_path = potential_path if not cros_sdk_bin_path: raise HostError( "Failed to locate 'cros_sdk' make sure it is in your PATH") self.cros_sdk_session = Popen( ['sudo -Sk {}'.format(cros_sdk_bin_path)], bufsize=1, stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=cros_path, close_fds=ON_POSIX, shell=True) self.cros_sdk_session.stdin.write(password) self.cros_sdk_session.stdin.write('\n') self.stdout_queue = Queue() self.stdout_thread = OutputPollingThread(self.cros_sdk_session.stdout, self.stdout_queue, 'stdout') self.stdout_thread.daemon = True self.stdout_thread.start() self.stderr_queue = Queue() self.stderr_thread = OutputPollingThread(self.cros_sdk_session.stderr, self.stderr_queue, 'stderr') self.stderr_thread.daemon = True self.stderr_thread.start()
def check_match_state_dependencies(): if np is None or cv2 is None or imutils is None: raise HostError("State detection requires numpy, opencv (cv2) and imutils.")
def initialize(self, context): if self.iio_capture is None: raise HostError('Missing iio-capture binary') self.command = None self.subprocess = None