[kupfer] apt_tools: Implement InfoTask using AsyncCommand
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [kupfer] apt_tools: Implement InfoTask using AsyncCommand
- Date: Wed, 5 May 2010 21:39:34 +0000 (UTC)
commit 8cd32d477e0c236b985bb6f7ff91e0eaa90c5afe
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Wed May 5 23:10:26 2010 +0200
apt_tools: Implement InfoTask using AsyncCommand
Killing one instance of Threads in Kupfer. Yeah! Threads are bad.
kupfer/plugin/apt_tools.py | 43 +++++++++++++++++++++++++++++--------------
1 files changed, 29 insertions(+), 14 deletions(-)
---
diff --git a/kupfer/plugin/apt_tools.py b/kupfer/plugin/apt_tools.py
index 302f60c..473e46b 100644
--- a/kupfer/plugin/apt_tools.py
+++ b/kupfer/plugin/apt_tools.py
@@ -28,23 +28,38 @@ __kupfer_settings__ = plugin_support.PluginSettings(
},
)
-class InfoTask(task.ThreadTask):
+class InfoTask(task.Task):
def __init__(self, text):
super(InfoTask, self).__init__()
self.text = text
- 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 thread_finish(self):
- uiutils.show_text_result(self.info, title=_("Show Package Information"))
+ self.aptitude = None
+ self.apt_cache = None
+
+ def start(self, finish_callback):
+ self._finish_callback = finish_callback
+ timeout = 60
+ AC = utils.AsyncCommand
+ AC(["aptitude", "show", self.text], self.aptitude_finished, timeout)
+ AC(["apt-cache", "policy", self.text], self.aptcache_finished, timeout)
+
+ def aptitude_finished(self, acommand, stdout, stderr):
+ self.aptitude = stderr
+ self.aptitude += stdout
+ self._check_end()
+
+ def aptcache_finished(self, acommand, stdout, stderr):
+ self.apt_cache = stderr
+ self.apt_cache += stdout
+ self._check_end()
+
+ 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 finish(self, text):
+ uiutils.show_text_result(text, title=_("Show Package Information"))
+ self._finish_callback(self)
class ShowPackageInfo (Action):
def __init__(self):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]