def _edit_tag(self, action, variant): """ Run tag editor @param SimpleAction @param GVariant """ album_path = Lp().albums.get_path(self._object_id) argv = [self._tag_editor, album_path, None] GLib.spawn_async_with_pipes( None, argv, None, GLib.SpawnFlags.SEARCH_PATH | GLib.SpawnFlags.DO_NOT_REAP_CHILD, None)
def __edit_tag(self, action, variant): """ Run tag editor @param SimpleAction @param GVariant """ album_path = Lp().albums.get_path(self._object_id) argv = [self.__tag_editor, album_path, None] GLib.spawn_async_with_pipes( None, argv, None, GLib.SpawnFlags.SEARCH_PATH | GLib.SpawnFlags.DO_NOT_REAP_CHILD, None)
def __edit_tag(self, action, variant): """ Run tag editor @param SimpleAction @param GVariant """ try: argv = [self.__tag_editor, GLib.filename_from_uri(self._object.uri)[0], None] GLib.spawn_async_with_pipes( None, argv, None, GLib.SpawnFlags.SEARCH_PATH | GLib.SpawnFlags.DO_NOT_REAP_CHILD, None) except: pass
def spawn(self, command: str, working_dir: Path, stdout_cb: Callable, use_sudo: True) -> bool: if use_sudo: command = f"{shutil.which('sudo')} -p '{SUDO_PROMPT_TEXT}' -S " + command (success, pid, stdin, stdout, stderr) = GLib.spawn_async_with_pipes( str(working_dir), shlex.split(command), [k + '=' + v for k, v in os.environ.items()], GLib.SpawnFlags.DO_NOT_REAP_CHILD, None) if success: if use_sudo: sudo_pwd = self.get_sudo_pwd() if sudo_pwd is None: sudo_pwd = password_prompt_dialog( self.props.active_window, 'Please enter sudo password', 'Sudo password') if sudo_pwd is not None: self.set_sudo_pwd(sudo_pwd) if sudo_pwd is None: sudo_pwd = '' os.write(stdin, f"{sudo_pwd}\r".encode('utf-8')) os.close(stdin) def callback(*args, **kwargs): cmd_out = None with os.fdopen(stdout) as out: cmd_out = out.read() stdout_cb(cmd_out) GLib.child_watch_add(GLib.PRIORITY_DEFAULT_IDLE, pid, callback) return success
def __edit_tags(self, args): """ Edit tags @param args as [] """ try: argv = [ self.__tag_editor, GLib.filename_from_uri(self.__object.uri)[0], None ] GLib.spawn_async_with_pipes( None, argv, None, GLib.SpawnFlags.SEARCH_PATH | GLib.SpawnFlags.DO_NOT_REAP_CHILD, None) except: pass self.__button.emit('clicked')
def _load_youtube(self, track, play=True): """ Load track url and play it @param track as Track @param play as bool @return True if loading """ if not Gio.NetworkMonitor.get_default().get_network_available(): # Force widgets to update (spinners) self.emit('current-changed') return False argv = ["youtube-dl", "-g", "-f", "bestaudio", track.uri, None] try: self.emit('loading-changed') (s, pid, i, o, err) = GLib.spawn_async_with_pipes( None, argv, None, GLib.SpawnFlags.SEARCH_PATH | GLib.SpawnFlags.DO_NOT_REAP_CHILD, None) io = GLib.IOChannel(o) io.add_watch(GLib.IO_IN | GLib.IO_HUP, self.__set_gv_uri, track, play, priority=GLib.PRIORITY_HIGH) return True except Exception as e: print("Youtube::__get_youtube_uri()", e)
def _edit_tag(self, action, variant): """ Run tag editor @param SimpleAction @param GVariant """ album_path = Lp.albums.get_path(self._object_id) argv = [self._tag_editor, album_path, None] (s, pid, i, o, e) = GLib.spawn_async_with_pipes( None, argv, None, GLib.SpawnFlags.SEARCH_PATH | GLib.SpawnFlags.DO_NOT_REAP_CHILD, None) GLib.child_watch_add(GLib.PRIORITY_DEFAULT_IDLE, pid, self._on_exit)
def _edit_tag(self, action, variant): """ Run tag editor @param SimpleAction @param GVariant """ album_path = Lp().albums.get_path(self._object_id) argv = [self._tag_editor, album_path, None] (s, pid, i, o, e) = GLib.spawn_async_with_pipes( None, argv, None, GLib.SpawnFlags.SEARCH_PATH | GLib.SpawnFlags.DO_NOT_REAP_CHILD, None) GLib.child_watch_add(GLib.PRIORITY_DEFAULT_IDLE, pid, self._on_exit)
def run(self, devicePath): (retval, self._pid, _stdin, stdout, _stderr) = \ GLib.spawn_async_with_pipes(None, ["checkisomd5", "--gauge", devicePath], [], GLib.SpawnFlags.DO_NOT_REAP_CHILD|GLib.SpawnFlags.SEARCH_PATH, None, None) if not retval: return # This function waits for checkisomd5 to end and then cleans up after it. GLib.child_watch_add(self._pid, self._checkisoEndsCB) # This function watches the process's stdout. GLib.io_add_watch(stdout, GLib.IOCondition.IN|GLib.IOCondition.HUP, self._checkisoStdoutWatcher) self.window.run()
def test_spawn_async_with_pipes(self): res, pid, stdin, stdout, stderr = GLib.spawn_async_with_pipes( working_directory=None, argv=['cat'], envp=None, flags=GLib.SpawnFlags.SEARCH_PATH) os.write(stdin, b'hello world!\n') os.close(stdin) out = os.read(stdout, 50) os.close(stdout) err = os.read(stderr, 50) os.close(stderr) GLib.spawn_close_pid(pid) self.assertEqual(out, b'hello world!\n') self.assertEqual(err, b'')
def run(self, devicePath): (retval, self._pid, _stdin, stdout, _stderr) = \ GLib.spawn_async_with_pipes(None, ["checkisomd5", "--gauge", devicePath], [], GLib.SpawnFlags.DO_NOT_REAP_CHILD|GLib.SpawnFlags.SEARCH_PATH, None, None) if not retval: return # This function waits for checkisomd5 to end and then cleans up after it. GLib.child_watch_add(self._pid, self._checkisoEndsCB) # This function watches the process's stdout. GLib.io_add_watch(stdout, GLib.IOCondition.IN | GLib.IOCondition.HUP, self._checkisoStdoutWatcher) self.window.run()
def on_ping_clicked(self, button): requests = self.builder.get_object("requests") radio = self.builder.get_object("requests_num") address = self.builder.get_object("address") treeview = self.treeview # Create a new tree model with five columns for ping output. store = Gtk.ListStore.new((str, str, str, str, str)) self.treeview.set_model(store) # Retrieve the current ping parameters entered by the user. num = requests.get_value_as_int() location = address.get_text() # Return if an address was not entered into the GtkEntry widget. if len(location) == 0: return # Otherwise, build the command based upon the user's preferences. elif radio.get_active(): if num == 0: return command = "ping " + location + " -c " + str(num) else: command = "ping " + location # Parse the command and launch the process, monitoring standard output. (bool, argvp) = GLib.shell_parse_argv(command) if bool: (ret, self.cpid, fin, fout, ferr) = GLib.spawn_async_with_pipes(None, argvp, None, GLib.SpawnFlags.SEARCH_PATH, None, None) if not ret: print("The 'ping' instruction has failed!") else: # Disable the Ping button and enable the Stop button. stop = self.builder.get_object("stop") stop.set_sensitive(True) ping = self.builder.get_object("ping") ping.set_sensitive(False) # Create a new IO channel and monitor it for data to read. channel = GLib.IOChannel.unix_new(fout) channel.add_watch( GLib.IOCondition.IN | GLib.IOCondition.ERR | GLib.IOCondition.HUP, self.read_output, None)
def status_icon_activate(sender, *args): app = args[-1] if not app.current: return if app.password_dialog: app.password_dialog.present() return app.password_dialog = create_password_dialog( app.status_icon.get_property('tooltip_text'), app.status_icon.get_property('icon_name')) result = app.password_dialog.run() password = app.password_dialog.entry.get_text() app.password_dialog.destroy() app.password_dialog = None if result in [Gtk.ResponseType.REJECT, Gtk.ResponseType.DELETE_EVENT, Gtk.ResponseType.CANCEL]: return reply_argv = ['/usr/bin/pkexec', '/lib/systemd/systemd-reply-password', '1' if result == Gtk.ResponseType.OK else '0', app.socket] try: child = GLib.spawn_async_with_pipes(None, reply_argv, None, GLib.SpawnFlags.DO_NOT_REAP_CHILD) GLib.child_watch_add(child.child_pid, lambda pid, status: GLib.spawn_close_pid(pid)) with os.fdopen(child.standard_input, 'w') as child_stdin: child_stdin.write(password) except Exception as e: log('error replying password: {}', e)