def from_args(cls, host, args): """Constructs a Device from command line arguments.""" device_finder_cmd = ['device-finder', 'list'] default_device = '{}.device'.format(host.build_dir) if args.device or os.path.exists(default_device): device_finder_cmd = ['device-finder', 'resolve'] if args.device: device_finder_cmd.append(args.device) else: with open(default_device) as f: device_finder_cmd.append(f.read().strip()) try: netaddr = host.fx_command(device_finder_cmd) if len(netaddr.split('\n')) > 1: raise RuntimeError( 'Multiple devices found; set a device with `fx set-device`.' ) except subprocess.CalledProcessError: raise RuntimeError('Unable to find device; try `fx set-device`.') device = cls(host, netaddr) if not host.build_dir: raise Host.ConfigError('Unable to find SSH configuration.') device.set_ssh_config( Host.join(host.build_dir, 'ssh-keys', 'ssh_config')) return device
def from_args(cls, host, args): """Constructs a Device from command line arguments.""" netaddr_cmd = ['netaddr', '--fuchsia', '--nowait'] if args.device: netaddr_cmd.append(args.device) try: netaddr = host.zircon_tool(netaddr_cmd) except subprocess.CalledProcessError: raise RuntimeError('Unable to find device') device = cls(host, netaddr) if not host.build_dir: raise Host.ConfigError('Unable to find SSH configuration.') device.set_ssh_config(Host.join(host.build_dir, 'ssh-keys', 'ssh_config')) return device
def from_args(cls, host, args): """Constructs a Device from command line arguments.""" netaddr_cmd = ['netaddr', '--fuchsia', '--nowait'] default_device = '{}.device'.format(host.build_dir) if args.device: netaddr_cmd.append(args.device) elif os.path.exists(default_device): with open(default_device) as f: netaddr_cmd.append(f.read().strip()) try: netaddr = host.zircon_tool(netaddr_cmd) except subprocess.CalledProcessError: raise RuntimeError('Unable to find device; try `fx set-device`.') device = cls(host, netaddr) if not host.build_dir: raise Host.ConfigError('Unable to find SSH configuration.') device.set_ssh_config(Host.join(host.build_dir, 'ssh-keys', 'ssh_config')) return device
def set_ssh_identity(self, identity_file): if not os.path.exists(identity_file): raise Host.ConfigError('Unable to find SSH identity.') self._ssh_opts['i'] = [identity_file]
def set_ssh_config(self, config_file): """Sets the SSH arguments to use a config file.""" if not os.path.exists(config_file): raise Host.ConfigError('Unable to find SSH configuration.') self._ssh_opts['F'] = [config_file]