def finish_command(ctx, acommand, stdout, stderr, post_result=True): """Show async error if @acommand returns error output & error status. Else post async result if @post_result. """ max_error_msg=512 pretty.print_debug(__name__, "Exited:", acommand) if acommand.exit_status != 0 and not stdout and stderr: errstr = kupferstring.fromlocale(stderr)[:max_error_msg] ctx.register_late_error(OperationError(errstr)) elif post_result: leaf = TextLeaf(kupferstring.fromlocale(stdout)) ctx.register_late_result(leaf)
def finish_command(token, acommand, stdout, stderr, post_result=True): """Show async error if @acommand returns error output & error status. Else post async result if @post_result. """ max_error_msg=512 pretty.print_debug(__name__, "Exited:", acommand) ctx = commandexec.DefaultActionExecutionContext() if acommand.exit_status != 0 and not stdout and stderr: try: errstr = kupferstring.fromlocale(stderr)[:max_error_msg] raise OperationError(errstr) except OperationError: ctx.register_late_error(token) elif post_result: leaf = TextLeaf(kupferstring.fromlocale(stdout)) ctx.register_late_result(token, leaf)
def get_current_song(): toolProc = subprocess.Popen([AUDTOOL, "current-song"], stdout=subprocess.PIPE) stdout, stderr = toolProc.communicate() for line in stdout.splitlines(): return kupferstring.fromlocale(line) return None
def get_items(self): package = self.query P = subprocess.PIPE acp = subprocess.Popen("apt-cache search --names-only '%s'" % package, shell=True, stdout=P, stderr=P) acp_out, acp_err = acp.communicate() for line in kupferstring.fromlocale(acp_out).splitlines(): if not line.strip(): continue package, desc = line.split(" - ", 1) yield Package(package, desc)
def thread_do(self): P = subprocess.PIPE apt = subprocess.Popen("aptitude show '%s'" % self.text, shell=True, stdout=P, stderr=P) acp = subprocess.Popen("apt-cache policy '%s'" % self.text, shell=True, stdout=P, stderr=P) apt_out, apt_err = apt.communicate() acp_out, acp_err = acp.communicate() # Commandline output is encoded according to locale self.info = u"".join(kupferstring.fromlocale(s) for s in (apt_err, acp_err, apt_out, acp_out))
def get_items(self): package = kupferstring.tolocale(self.query) p = subprocess.run(['apt-cache', 'search', '--names-only', package], capture_output=True) for line in kupferstring.fromlocale(p.stdout).splitlines(): if not line.strip(): continue if not " - " in line: self.output_error("apt-cache: ", line) continue package, desc = line.split(" - ", 1) yield Package(package, desc)
def get_playlist_songs(): """Yield tuples of (position, name) for playlist songs""" toolProc = subprocess.Popen([AUDTOOL, "playlist-display"], stdout=subprocess.PIPE) stdout, stderr = toolProc.communicate() for line in stdout.splitlines(): if not line.count('|') >= 2: continue position, rest = line.split('|', 1) songname, rest = rest.rsplit('|', 1) pos = int(position.strip()) nam = kupferstring.fromlocale(songname.strip()) yield (pos, nam)
def get_items(self): package = kupferstring.tolocale(self.query) c_in, c_out_err = os.popen4(['apt-cache', 'search', '--names-only', package]) try: c_in.close() acp_out = c_out_err.read() for line in kupferstring.fromlocale(acp_out).splitlines(): if not line.strip(): continue if not " - " in line: self.output_error("apt-cache: ", line) continue package, desc = line.split(" - ", 1) yield Package(package, desc) finally: c_out_err.close()
def get_items(self): package = kupferstring.tolocale(self.query) c_in, c_out_err = os.popen4( ['apt-cache', 'search', '--names-only', package]) try: c_in.close() acp_out = c_out_err.read() for line in kupferstring.fromlocale(acp_out).splitlines(): if not line.strip(): continue if not " - " in line: self.output_error("apt-cache: ", line) continue package, desc = line.split(" - ", 1) yield Package(package, desc) finally: c_out_err.close()
def finish_callback(self, acommand, stdout, stderr): ctx = commandexec.DefaultActionExecutionContext() leaf = TextLeaf(kupferstring.fromlocale(stdout)) ctx.register_late_result(acommand.token, leaf)
def activate(self, leaf): with open(leaf.object, "rb") as infile: l_text = infile.read() us_text = kupferstring.fromlocale(l_text) return TextLeaf(us_text)
def cmd_output_lines(cmd): return kupferstring.fromlocale(os.popen(cmd).read()).splitlines()
def _check_end(self): if self.aptitude is not None and self.apt_cache is not None: self.finish(u"".join(kupferstring.fromlocale(s) for s in (self.aptitude, self.apt_cache)))
def __init__(self, s): OperationError.__init__(self, kupferstring.fromlocale(s))
def get_items(self): for x in self.serverids: yield VimApp(x, _("Vim Session %s") % kupferstring.fromlocale(x))
def get_locate_output(proc, offset=0): out, ignored_err = proc.communicate() return (ConstructFileLeaf(kupferstring.fromlocale(f)) for f in out.split(b'\x00')[offset:-1])
def _check_end(self): if self.aptitude is not None and self.apt_cache is not None: self.finish(u"".join( kupferstring.fromlocale(s) for s in (self.aptitude, self.apt_cache)))