summaryrefslogtreecommitdiff
path: root/portato/gui/updater.py
diff options
context:
space:
mode:
authorNecoro <>2008-01-18 21:19:42 +0000
committerNecoro <>2008-01-18 21:19:42 +0000
commit6a9034fb7a161e441934969553ffff63e49348ee (patch)
treec128d3c23dc9d54dfaabc40e8fd4c35a815dbe92 /portato/gui/updater.py
parente49c33d6114ddc8051c349aa325872bd7840289b (diff)
downloadportato-6a9034fb7a161e441934969553ffff63e49348ee.tar.gz
portato-6a9034fb7a161e441934969553ffff63e49348ee.tar.bz2
portato-6a9034fb7a161e441934969553ffff63e49348ee.zip
r664@Devoty: necoro | 2008-01-18 21:40:29 +0100
First support for 'delete on demand' r665@Devoty: necoro | 2008-01-18 22:18:05 +0100 Finished the 'on demand removal'
Diffstat (limited to '')
-rw-r--r--portato/gui/updater.py107
1 files changed, 107 insertions, 0 deletions
diff --git a/portato/gui/updater.py b/portato/gui/updater.py
new file mode 100644
index 0000000..e468691
--- /dev/null
+++ b/portato/gui/updater.py
@@ -0,0 +1,107 @@
+# -*- coding: utf-8 -*-
+#
+# File: portato/gui/updater.py
+# This file is part of the Portato-Project, a graphical portage-frontend.
+#
+# Copyright (C) 2008 René 'Necoro' Neumann
+# This is free software. You may redistribute copies of it under the terms of
+# the GNU General Public License version 2.
+# There is NO WARRANTY, to the extent permitted by law.
+#
+# Written by René 'Necoro' Neumann <necoro@necoro.net>
+
+from __future__ import absolute_import
+
+from ..backend import system
+
+import threading, subprocess, time
+from ..helper import debug
+
+class Updater (object):
+ """
+ This class is intended to check what package is currently being installed and remove this one from the queue.
+
+ @cvar SED_EXP: The sed expression to strip the package name out of the qlop call.
+ """
+
+ SED_EXP = r"""
+/\*/{
+s/ \* //
+q
+}"""
+
+ def __init__ (self, queue, iterators, threadClass = threading.Thread):
+ """
+ Constructor.
+ Also directly initializes the thread.
+
+ @param queue: an emerge queue instance
+ @type queue: EmergeQueue
+ @param iterators: a dictionary of iterators in the current queue
+ @type iterators: dict(string->Iterator)
+ """
+
+ if not issubclass(threadClass, threading.Thread):
+ raise ValueError, "Only subclasses of threading.Thread are allowed."
+
+ self.queue = queue
+ self.iterators = iterators
+ self.threadClass = threadClass
+ self.stopEvent = threading.Event()
+
+ t = threadClass(name = "Queue Updater Thread", target = self.run)
+ t.setDaemon(True)
+ t.start()
+
+ def run (self):
+ """
+ Run and run and run ...
+ Checks the packages until being stopped.
+ """
+
+ curr = None
+ while not self.stopEvent.isSet():
+
+ # this = $(qlop -cCq | sed $SED_EXP)
+ p1 = subprocess.Popen(["qlop", "--current", "--nocolor", "--quiet"], stdout = subprocess.PIPE)
+ this = subprocess.Popen(["sed", self.SED_EXP], stdout = subprocess.PIPE, stdin = p1.stdout).communicate()[0]
+
+ if this:
+ this = this.strip()
+ if this != curr: # changed package
+ curr = this
+ self.remove(self.find(curr)) # remove it
+
+ time.sleep(2.0)
+
+ def stop (self):
+ """
+ Stops the current updater.
+ """
+ self.stopEvent.set()
+
+ def find (self, pv):
+ """
+ As qlop only returns 'package-version' we need to assign it to a cpv.
+ This is done here.
+ """
+
+ pkgs = [l.get_cpv() for l in system.find_packages("=%s" % pv)]
+
+ if len(pkgs) > 1: # ambigous - try to find the one which is also in the iterators
+ for p in pkgs:
+ if p in self.iterators:
+ return p
+ elif not pkgs: # nothing found =|
+ error(_("Trying to remove package '%s' from queue which does not exist in system."), pv)
+ else: # only one choice =)
+ return pkgs[0]
+
+ def remove (self, cpv):
+ """
+ Remove a package from the queue.
+ """
+ try:
+ self.queue.remove(self.iterators[cpv])
+ except KeyError:
+ debug("'%s' should be removed, but is not in queue.", cpv)