[kupfer] apt_tools: Work around subprocess bug
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [kupfer] apt_tools: Work around subprocess bug
- Date: Tue, 15 Mar 2011 18:12:45 +0000 (UTC)
commit 76dcf2b6336aa5154844c571ff195dca3f9d593a
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Mon Mar 14 00:01:21 2011 +0100
apt_tools: Work around subprocess bug
Possible bug in python's subprocess? Would be python bug
http://bugs.python.org/issue1731717
Launchpad-bug: https://bugs.launchpad.net/kupfer/+bug/711136
kupfer/plugin/apt_tools.py | 27 ++++++++++++++++-----------
1 files changed, 16 insertions(+), 11 deletions(-)
---
diff --git a/kupfer/plugin/apt_tools.py b/kupfer/plugin/apt_tools.py
index aefcabe..a095418 100644
--- a/kupfer/plugin/apt_tools.py
+++ b/kupfer/plugin/apt_tools.py
@@ -11,7 +11,7 @@ __version__ = ""
__author__ = ("Martin Koelewijn <martinkoelewijn gmail com>, "
"Ulrik Sverdrup <ulrik sverdrup gmail com>")
-import subprocess
+import os
from kupfer.objects import Action, Source, Leaf
from kupfer.objects import TextLeaf
@@ -125,16 +125,21 @@ class PackageSearchSource (Source):
return self.query
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)
+ 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 should_sort_lexically(self):
return True
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]