def on_started(self, launched_app_id): if launched_app_id == self.appid: #Do NOT change this line, its interpreted by the IDE print("Sdk-Launcher> Application started: " + str(UAL.get_primary_pid(self.appid)), file=sys.stderr, flush=True)
def _stop_application(self, app_id): state = {} state['loop'] = self._get_glib_loop() state['expected_app_id'] = app_id UbuntuAppLaunch.observer_add_app_stop(self._on_stopped, state) GLib.timeout_add_seconds(10.0, self._on_timeout, state) UbuntuAppLaunch.stop_application(app_id) state['loop'].run() UbuntuAppLaunch.observer_delete_app_stop(self._on_stopped) if state.get('status', None) == UpstartApplicationLauncher.Timeout: _logger.error( "Timed out waiting for Application with app_id '%s' to stop.", app_id)
def stop(self): UAL.stop_application(self.appid)
def launch(self): UAL.observer_add_app_failed(self.on_failed) UAL.observer_add_app_started(self.on_started) UAL.observer_add_app_focus(self.on_focus) UAL.observer_add_app_stop(self.on_stopped) UAL.observer_add_app_resume(self.on_resume) #start up the application UAL.start_application(self.appid) try: self.loop.run() except KeyboardInterrupt: pass print("Sdk-Launcher> The Application exited, cleaning up") UAL.observer_delete_app_failed(self.on_failed) UAL.observer_delete_app_started(self.on_started) UAL.observer_delete_app_focus(self.on_focus) UAL.observer_delete_app_stop(self.on_stopped) UAL.observer_delete_app_resume(self.on_resume) return self.exitCode
def launch(self, app_id, app_uris=[]): """Launch an application with upstart. This method launches an application via the ``upstart-app-launch`` library, on platforms that support it. Usage is similar to NormalApplicationLauncher:: from autopilot.application import UpstartApplicationLauncher launcher = UpstartApplicationLauncher() launcher.setUp() app_proxy = launcher.launch('gallery-app') :param app_id: name of the application to launch :param app_uris: list of separate application uris to launch :raises RuntimeError: If the specified application cannot be launched. :returns: proxy object for the launched package application """ if isinstance(app_uris, str): app_uris = [app_uris] if isinstance(app_uris, bytes): app_uris = [app_uris.decode()] _logger.info( "Attempting to launch application '%s' with URIs '%s' via " "upstart-app-launch", app_id, ','.join(app_uris)) state = {} state['loop'] = self._get_glib_loop() state['expected_app_id'] = app_id state['message'] = '' UbuntuAppLaunch.observer_add_app_failed(self._on_failed, state) UbuntuAppLaunch.observer_add_app_started(self._on_started, state) UbuntuAppLaunch.observer_add_app_focus(self._on_started, state) GLib.timeout_add_seconds(10.0, self._on_timeout, state) self._launch_app(app_id, app_uris) state['loop'].run() UbuntuAppLaunch.observer_delete_app_failed(self._on_failed) UbuntuAppLaunch.observer_delete_app_started(self._on_started) UbuntuAppLaunch.observer_delete_app_focus(self._on_started) self._maybe_add_application_cleanups(state) self._check_status_error(state.get('status', None), state.get('message', '')) pid = self._get_pid_for_launched_app(app_id) return self._get_proxy_object(pid)
def _launch_app(app_name, app_uris): UbuntuAppLaunch.start_application_test(app_name, app_uris)
def _get_pid_for_launched_app(app_id): return UbuntuAppLaunch.get_primary_pid(app_id)