def __call__(self, args): super(LogOutCommand, self).__call__(args) account = get_default_account() if account.is_logged_in: account.logout() else: print("You aren't logged in anyway.")
def _spawn_pypkjs(self): phonesim_bin = os.environ.get('PHONESIM_PATH', 'phonesim.py') layout_file = os.path.join(sdk_manager.path_for_sdk(self.version), 'pebble', self.platform, 'qemu', "layouts.json") command = [ sys.executable, phonesim_bin, "--qemu", "localhost:{}".format(self.qemu_port), "--port", str(self.pypkjs_port), "--persist", get_sdk_persist_dir(self.platform, self.version), "--layout", layout_file, '--debug', ] account = get_default_account() if account.is_logged_in: command.extend(['--oauth', account.bearer_token]) if logger.getEffectiveLevel() <= logging.DEBUG: command.append('--debug') logger.info("pypkjs command: %s", subprocess.list2cmdline(command)) process = subprocess.Popen(command, stdout=self._get_output(), stderr=self._get_output()) time.sleep(0.5) if process.poll() is not None: try: subprocess.check_output(command, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: raise MissingEmulatorError("Couldn't launch pypkjs:\n{}".format(e.output.strip())) self.pypkjs_pid = process.pid
def connect(self): account = get_default_account() if not account.is_logged_in: raise ToolError("You must be logged in ('pebble login') to use the CloudPebble connection.") self.ws = websocket.create_connection(CP_TRANSPORT_HOST) self._authenticate() self._wait_for_phone() self._phone_connected = True
def _get_identity(self): account = get_default_account() identity = { 'sdk_client_id': self._get_machine_identifier() } if account.is_logged_in: identity['user'] = account.id return identity
def _authenticate(self): oauth = get_default_account().bearer_token self.send_packet(WebSocketProxyAuthenticationRequest(token=oauth), target=MessageTargetPhone()) target, packet = self.read_packet() if isinstance(packet, WebSocketProxyAuthenticationResponse): if packet.status != WebSocketProxyAuthenticationResponse.StatusCode.Success: raise ToolError("Failed to authenticate to the CloudPebble proxy.") else: logger.info("Got unexpected message from proxy: %s", packet) raise ToolError("Unexpected message from CloudPebble proxy.")
def __call__(self, args): super(LogInCommand, self).__call__(args) account = get_default_account() account.login(args)