def do_get_targets_async(self, cancellable, callback, data): task = Gio.Task.new(self, cancellable, callback) task.set_priority(GLib.PRIORITY_LOW) task.targets = [] context = self.get_context() build_system = Ide.BuildSystem.from_context(context) build_manager = Ide.BuildManager.from_context(context) pipeline = build_manager.get_pipeline() if pipeline is None or type(build_system) != WafBuildSystem: task.return_error( GLib.Error('No access to waf build system', domain=GLib.quark_to_string(Gio.io_error_quark()), code=Gio.IOErrorEnum.NOT_SUPPORTED)) return # For some reason, "waf list" outputs on stderr launcher = build_system._create_launcher(pipeline) launcher.set_flags(Gio.SubprocessFlags.STDOUT_SILENCE | Gio.SubprocessFlags.STDERR_PIPE) launcher.set_cwd(pipeline.get_srcdir()) launcher.push_argv('list') try: subprocess = launcher.spawn(cancellable) subprocess.communicate_utf8_async(None, cancellable, self.communicate_cb, task) except Exception as ex: task.return_error( GLib.Error(repr(ex), domain=GLib.quark_to_string(Gio.io_error_quark()), code=Gio.IOErrorEnum.FAILED))
def do_get_targets_async(self, cancellable, callback, data): task = Gio.Task.new(self, cancellable, callback) task.set_priority(GLib.PRIORITY_LOW) task.targets = [] context = self.get_context() build_system = Ide.BuildSystem.from_context(context) build_manager = Ide.BuildManager.from_context(context) pipeline = build_manager.get_pipeline() if pipeline is None or type(build_system) != WafBuildSystem: task.return_error(GLib.Error('No access to waf build system', domain=GLib.quark_to_string(Gio.io_error_quark()), code=Gio.IOErrorEnum.NOT_SUPPORTED)) return # For some reason, "waf list" outputs on stderr launcher = build_system._create_launcher(pipeline) launcher.set_flags(Gio.SubprocessFlags.STDOUT_SILENCE | Gio.SubprocessFlags.STDERR_PIPE) launcher.set_cwd(pipeline.get_srcdir()) launcher.push_argv('list') try: subprocess = launcher.spawn(cancellable) subprocess.communicate_utf8_async(None, cancellable, self.communicate_cb, task) except Exception as ex: task.return_error(GLib.Error(repr(ex), domain=GLib.quark_to_string(Gio.io_error_quark()), code=Gio.IOErrorEnum.FAILED))
def do_update_async(self, cancellable, callback, data): task = Gio.Task.new(self, cancellable, callback) task.set_priority(GLib.PRIORITY_LOW) context = self.get_context() build_system = context.get_build_system() if type(build_system) != DubBuildSystem: task.return_boolean(True) return build_manager = context.get_build_manager() pipeline = build_manager.get_pipeline() if not pipeline: task.return_error( GLib.Error('Cannot update dependencies without build pipeline', domain=GLib.quark_to_string(Gio.io_error_quark()), code=Gio.IOErrorEnum.FAILED)) return launcher = pipeline.create_launcher() launcher.push_argv("dub") launcher.push_argv("--root=" + get_working_dir(context).get_path()) launcher.push_argv("upgrade") try: subprocess = launcher.spawn() subprocess.wait_check_async(None, self.wait_check_cb, task) except Exception as ex: task.return_error(ex)
def serialize_error_as_json_object(domain, code, detail=None): '''Serialize a GLib.Error as a JSON object.''' return { 'domain': GLib.quark_to_string(domain), 'code': code.value_nick.replace('-', '_').upper(), 'detail': detail or {} }
def do_get_targets_async(self, cancellable, callback, data): task = Ide.Task.new(self, cancellable, callback) task.set_priority(GLib.PRIORITY_LOW) context = self.get_context() build_system = Ide.BuildSystem.from_context(context) if type(build_system) != SwiftBuildSystem: task.return_error( GLib.Error('Not swift build system', domain=GLib.quark_to_string(Gio.io_error_quark()), code=Gio.IOErrorEnum.NOT_SUPPORTED)) return print(Ide.BuildSystem.from_context(context).project_file.get_path()) pkg_dump = check_output( ["swift", "package", "dump-package"], cwd=Ide.BuildSystem.from_context(context).project_file.get_path(), universal_newlines=True) pkg_set = json.loads(pkg_dump) task.targets = [] for target in pkg_set["targets"]: #if target["type"] == "regular": newtarget = SwiftBuildTarget(target["name"]) print("newtarget = ", newtarget.target_name) task.targets.append(build_system.ensure_child_typed(newtarget)) task.return_boolean(True)
def Frame(buffer, caps): caps_structure = caps.get_structure(0) caps_string = GLib.quark_to_string(caps_structure.name) if ("video" in caps_string): return VideoFrame(buffer, caps) elif ("audio" in caps_string): return AudioFrame(buffer, caps)
def get_gquark_string(_id): """ Returns the string associated with the given GQuark ID. :param _id: GQuark ID :return: (str) Associated string :since: v0.2.00 """ # pylint: disable=no-member return _GLib.quark_to_string(_id)
def communicate_cb(self, subprocess, result, task): try: ret, stdout, stderr = subprocess.communicate_utf8_finish(result) lines = stderr.strip().split('\n') if len(lines) > 0: # Trim 'list' finished ... line del lines[-1] for line in lines: task.targets.append(WafBuildTarget(line.strip())) task.return_boolean(True) except Exception as ex: task.return_error(GLib.Error(repr(ex), domain=GLib.quark_to_string(Gio.io_error_quark()), code=Gio.IOErrorEnum.FAILED))
def do_get_targets_async(self, cancellable, callback, data): task = Gio.Task.new(self, cancellable, callback) task.set_priority(GLib.PRIORITY_LOW) context = self.get_context() build_system = context.get_build_system() if type(build_system) != CargoBuildSystem: task.return_error(GLib.Error('Not cargo build system', domain=GLib.quark_to_string(Gio.io_error_quark()), code=Gio.IOErrorEnum.NOT_SUPPORTED)) return task.targets = [CargoBuildTarget(context=self.get_context())] task.return_boolean(True)
def do_get_targets_async(self, cancellable, callback, data): task = Gio.Task.new(self, cancellable, callback) task.set_priority(GLib.PRIORITY_LOW) context = self.get_context() build_system = context.get_build_system() if type(build_system) != MavenBuildSystem: task.return_error(GLib.Error('Not maven build system', domain=GLib.quark_to_string(Gio.io_error_quark()), code=Gio.IOErrorEnum.NOT_SUPPORTED)) return task.targets = [MavenBuildTarget(context=self.get_context())] task.return_boolean(True)
def communicate_cb(self, subprocess, result, task): try: ret, stdout, stderr = subprocess.communicate_utf8_finish(result) lines = stderr.strip().split('\n') if len(lines) > 0: # Trim 'list' finished ... line del lines[-1] for line in lines: task.targets.append(WafBuildTarget(line.strip())) task.return_boolean(True) except Exception as ex: task.return_error( GLib.Error(repr(ex), domain=GLib.quark_to_string(Gio.io_error_quark()), code=Gio.IOErrorEnum.FAILED))
def translate_error(error, error_mappings=None): '''Translate any error type into an EosCompanionAppError error.''' if error.domain == GLib.quark_to_string( EosCompanionAppService.error_quark()): return (EosCompanionAppService.error_quark(), EosCompanionAppService.Error(error.code)) for src_domain, src_code, target_code in generate_error_mappings( error_mappings): if error.matches(src_domain, src_code): return (EosCompanionAppService.error_quark(), EosCompanionAppService.Error(target_code)) return (EosCompanionAppService.error_quark(), EosCompanionAppService.Error.FAILED)
def do_get_targets_async(self, cancellable, callback, data): task = Gio.Task.new(self, cancellable, callback) task.set_priority(GLib.PRIORITY_LOW) context = self.get_context() build_system = context.get_build_system() if type(build_system) != NPMBuildSystem: task.return_error(GLib.Error('Not NPM build system', domain=GLib.quark_to_string(Gio.io_error_quark()), code=Gio.IOErrorEnum.NOT_SUPPORTED)) return project_file = context.get_project_file() project_file.load_contents_async(cancellable, self._on_package_json_loaded, task)
def do_get_targets_async(self, cancellable, callback, data): task = Gio.Task.new(self, cancellable, callback) task.set_priority(GLib.PRIORITY_LOW) context = self.get_context() build_system = Ide.BuildSystem.from_context(context) if type(build_system) != GradleBuildSystem: task.return_error(GLib.Error('Not gradle build system', domain=GLib.quark_to_string(Gio.io_error_quark()), code=Gio.IOErrorEnum.NOT_SUPPORTED)) return task.targets = [build_system.ensure_child_typed(GradleBuildTarget)] task.return_boolean(True)
def do_get_targets_async(self, cancellable, callback, data): task = Gio.Task.new(self, cancellable, callback) task.set_priority(GLib.PRIORITY_LOW) context = self.get_context() build_system = Ide.BuildSystem.from_context(context) if type(build_system) != GradleBuildSystem: task.return_error( GLib.Error('Not gradle build system', domain=GLib.quark_to_string(Gio.io_error_quark()), code=Gio.IOErrorEnum.NOT_SUPPORTED)) return task.targets = [build_system.ensure_child_typed(GradleBuildTarget)] task.return_boolean(True)
def do_run_async(self, test, pipeline, cancellable, callback, data): task = Ide.Task.new(self, cancellable, callback) task.set_priority(GLib.PRIORITY_LOW) context = self.get_context() build_system = context.get_build_system() if type(build_system) != GradleBuildSystem: task.return_error( GLib.Error('Not gradle build system', domain=GLib.quark_to_string(Gio.io_error_quark()), code=Gio.IOErrorEnum.NOT_SUPPORTED)) return task.targets = [GradleBuildTarget(context=self.get_context())] try: runtime = pipeline.get_runtime() runner = runtime.create_runner() if not runner: task.return_error(Ide.NotSupportedError()) runner.set_flags(Gio.SubprocessFlags.STDOUT_PIPE | Gio.SubprocessFlags.STDERR_PIPE) srcdir = pipeline.get_srcdir() runner.set_cwd(srcdir) commands = test.get_command() for command in commands: runner.append_argv(command) test.set_status(Ide.TestStatus.RUNNING) def run_test_cb(runner, result, data): try: runner.run_finish(result) test.set_status(Ide.TestStatus.SUCCESS) except: test.set_status(Ide.TestStatus.FAILED) finally: task.return_boolean(True) runner.run_async(cancellable, run_test_cb, task) except Exception as ex: task.return_error(ex)
def do_run_async(self, test, pipeline, pty, cancellable, callback, data): task = Ide.Task.new(self, cancellable, callback) task.set_priority(GLib.PRIORITY_LOW) context = self.get_context() build_system = Ide.BuildSystem.from_context(context) if type(build_system) != MavenBuildSystem: task.return_error( GLib.Error('Not maven build system', domain=GLib.quark_to_string(Gio.io_error_quark()), code=Gio.IOErrorEnum.NOT_SUPPORTED)) return task.targets = [build_system.ensure_child_typed(MavenBuildTarget)] try: runtime = pipeline.get_runtime() runner = runtime.create_runner() if not runner: task.return_error(Ide.NotSupportedError()) if pty is not None: runner.set_pty(pty) srcdir = pipeline.get_srcdir() runner.set_cwd(srcdir) commands = test.get_command() for command in commands: runner.append_argv(command) test.set_status(Ide.TestStatus.RUNNING) def run_test_cb(runner, result, data): try: runner.run_finish(result) test.set_status(Ide.TestStatus.SUCCESS) except: test.set_status(Ide.TestStatus.FAILED) finally: task.return_boolean(True) runner.run_async(cancellable, run_test_cb, task) except Exception as ex: task.return_error(ex)
def do_run_async(self, test, pipeline, pty, cancellable, callback, data): task = Ide.Task.new(self, cancellable, callback) task.set_priority(GLib.PRIORITY_LOW) context = self.get_context() build_system = Ide.BuildSystem.from_context(context) if type(build_system) != GradleBuildSystem: task.return_error(GLib.Error('Not gradle build system', domain=GLib.quark_to_string(Gio.io_error_quark()), code=Gio.IOErrorEnum.NOT_SUPPORTED)) return task.targets = [build_system.ensure_child_typed(GradleBuildTarget)] try: runtime = pipeline.get_runtime() runner = runtime.create_runner() if not runner: task.return_error(Ide.NotSupportedError()) if pty is not None: runner.set_pty(pty) srcdir = pipeline.get_srcdir() runner.set_cwd(srcdir) commands = test.get_command() for command in commands: runner.append_argv(command) test.set_status(Ide.TestStatus.RUNNING) def run_test_cb(runner, result, data): try: runner.run_finish(result) test.set_status(Ide.TestStatus.SUCCESS) except: test.set_status(Ide.TestStatus.FAILED) finally: task.return_boolean(True) runner.run_async(cancellable, run_test_cb, task) except Exception as ex: task.return_error(ex)
def do_update_async(self, cancellable, callback, data): task = Gio.Task.new(self, cancellable, callback) task.set_priority(GLib.PRIORITY_LOW) context = self.get_context() build_system = Ide.BuildSystem.from_context(context) # Short circuit if not using cargo if type(build_system) != CargoBuildSystem: task.return_boolean(True) return build_manager = Ide.BuildManager.from_context(context) pipeline = build_manager.get_pipeline() if not pipeline: task.return_error( GLib.Error('Cannot update dependencies without build pipeline', domain=GLib.quark_to_string(Gio.io_error_quark()), code=Gio.IOErrorEnum.FAILED)) return config_manager = Ide.ConfigManager.from_context(context) config = config_manager.get_current() cargo = locate_cargo_from_config(config) project_file = build_system.props.project_file if project_file.get_basename() != 'Cargo.toml': project_file = project_file.get_child('Cargo.toml') cargo_toml = project_file.get_path() launcher = pipeline.create_launcher() launcher.setenv('CARGO_TARGET_DIR', pipeline.get_builddir(), True) launcher.push_argv(cargo) launcher.push_argv('update') launcher.push_argv('--manifest-path') launcher.push_argv(cargo_toml) try: subprocess = launcher.spawn() subprocess.wait_check_async(None, self.wait_check_cb, task) except Exception as ex: task.return_error(ex)
def do_update_async(self, cancellable, callback, data): task = Gio.Task.new(self, cancellable, callback) task.set_priority(GLib.PRIORITY_LOW) context = self.get_context() build_system = Ide.BuildSystem.from_context(context) # Short circuit if not using cargo if type(build_system) != CargoBuildSystem: task.return_boolean(True) return build_manager = Ide.BuildManager.from_context(context) pipeline = build_manager.get_pipeline() if not pipeline: task.return_error(GLib.Error('Cannot update dependencies without build pipeline', domain=GLib.quark_to_string(Gio.io_error_quark()), code=Gio.IOErrorEnum.FAILED)) return config_manager = Ide.ConfigManager.from_context(context) config = config_manager.get_current() cargo = locate_cargo_from_config(config) project_file = build_system.props.project_file if project_file.get_basename() != 'Cargo.toml': project_file = project_file.get_child('Cargo.toml') cargo_toml = project_file.get_path() launcher = pipeline.create_launcher() launcher.setenv('CARGO_TARGET_DIR', pipeline.get_builddir(), True) launcher.push_argv(cargo) launcher.push_argv('update') launcher.push_argv('--manifest-path') launcher.push_argv(cargo_toml) try: subprocess = launcher.spawn() subprocess.wait_check_async(None, self.wait_check_cb, task) except Exception as ex: task.return_error(ex)
def load_record_from_shards_async(shards, content_id, attr, callback): '''Load bytes from stream for app and content_id. :attr: must be one of 'data' or 'metadata'. Once loading is complete, callback will be invoked with a GAsyncResult, use EosCompanionAppService.finish_load_all_in_stream_to_bytes to get the result or handle the corresponding error. Returns LOAD_FROM_ENGINE_SUCCESS if a stream could be loaded, LOAD_FROM_ENGINE_NO_SUCH_CONTENT if the content wasn't found. ''' def _callback(_, result): '''Marshal the GAsyncReady callback into an (error, data) callback.''' try: bytes_data = EosCompanionAppService.finish_load_all_in_stream_to_bytes( result) except GLib.Error as error: callback(error, None) return callback(None, bytes_data) status, blob = load_record_blob_from_shards(shards, content_id, attr) if status == LOAD_FROM_ENGINE_NO_SUCH_CONTENT: GLib.idle_add(lambda: callback( GLib.Error( 'EKN ID {} not found in shards'.format(content_id), GLib.quark_to_string(EosCompanionAppService.error_quark()), EosCompanionAppService.Error.INVALID_CONTENT_ID), None)) return EosCompanionAppService.load_all_in_stream_to_bytes( blob.get_stream(), chunk_size=BYTE_CHUNK_SIZE, cancellable=None, callback=_callback)
def foreach(fid, value, unused1, udata): keys.add(GLib.quark_to_string(fid)) return True
def label(self) -> str: return GLib.quark_to_string(self.__roi_meta.roi_type)
def print_field(field, value, pfx): str = Gst.value_serialize(value) print("{0:s} {1:15s}: {2:s}".format( pfx, GLib.quark_to_string(field), str)) return True
def get_roi_type(self) -> str: return GLib.quark_to_string(self.roi_type)
def print_field(field, value, pfx): str = Gst.value_serialize(value) print("{0:s} {1:15s}: {2:s}".format(pfx, GLib.quark_to_string(field), str)) return True
def label(self) -> str: return GLib.quark_to_string(self.__event_meta.event_type)