diff options
author | René 'Necoro' Neumann <necoro@necoro.net> | 2008-09-02 13:01:17 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.net> | 2008-09-02 13:01:17 +0200 |
commit | afa1de13f0576ace6dcbb0176490fd20922950cd (patch) | |
tree | 056a5fd646f53dfa83f2fe231ec0943747b15ffc /portato/gui/updater.py | |
parent | 02d96210d9102f0cdec95b4e0f595cbd8fdd1e10 (diff) | |
download | portato-afa1de13f0576ace6dcbb0176490fd20922950cd.tar.gz portato-afa1de13f0576ace6dcbb0176490fd20922950cd.tar.bz2 portato-afa1de13f0576ace6dcbb0176490fd20922950cd.zip |
Switch from tabs to 4 spaces
Diffstat (limited to '')
-rw-r--r-- | portato/gui/updater.py | 200 |
1 files changed, 100 insertions, 100 deletions
diff --git a/portato/gui/updater.py b/portato/gui/updater.py index c4c81e7..c4ad2a5 100644 --- a/portato/gui/updater.py +++ b/portato/gui/updater.py @@ -18,109 +18,109 @@ import threading, subprocess, time from ..helper import debug, warning, error class Updater (object): - """ - This class is intended to check what package is currently being installed and remove this one from the queue. + """ + 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""" + @cvar SED_EXP: The sed expression to strip the package name out of the qlop call. + """ + + SED_EXP = r""" /\*/{ s/ \* // n } d""" - - 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() - self.removed = set() - - 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 = set() - 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] - - this = set(this.split()) if this else set() - for removed in curr - this: - self.remove(self.find(removed)) # remove the previous - curr = this - - time.sleep(2.0) - - self.removed = set() - - def stop (self): - """ - Stops the current updater. - """ - self.stopEvent.set() - - def find (self, pv, masked = False): - """ - As qlop only returns 'package-version' we need to assign it to a cpv. - This is done here. - """ - - pkgs = system.find_packages("=%s" % pv, only_cpv = True, masked = masked) - - 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 =| - if not masked: - warning(_("No unmasked version of package '%s' found. Trying masked ones. This normally should not happen..."), pv) - return self.find(pv, True) - - else: - error(_("Trying to remove package '%s' from queue which does not exist in system."), pv) - return None - else: # only one choice =) - return pkgs[0] - - def remove (self, cpv): - """ - Remove a package from the queue. - """ - - if cpv is None: - debug("Nothing to remove.") - return - - if cpv in self.removed: - return - - self.removed.add(cpv) - - try: - self.queue.remove_with_children(self.iterators[cpv]) - except KeyError: - debug("'%s' should be removed, but is not in queue.", cpv) + + 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() + self.removed = set() + + 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 = set() + 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] + + this = set(this.split()) if this else set() + for removed in curr - this: + self.remove(self.find(removed)) # remove the previous + curr = this + + time.sleep(2.0) + + self.removed = set() + + def stop (self): + """ + Stops the current updater. + """ + self.stopEvent.set() + + def find (self, pv, masked = False): + """ + As qlop only returns 'package-version' we need to assign it to a cpv. + This is done here. + """ + + pkgs = system.find_packages("=%s" % pv, only_cpv = True, masked = masked) + + 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 =| + if not masked: + warning(_("No unmasked version of package '%s' found. Trying masked ones. This normally should not happen..."), pv) + return self.find(pv, True) + + else: + error(_("Trying to remove package '%s' from queue which does not exist in system."), pv) + return None + else: # only one choice =) + return pkgs[0] + + def remove (self, cpv): + """ + Remove a package from the queue. + """ + + if cpv is None: + debug("Nothing to remove.") + return + + if cpv in self.removed: + return + + self.removed.add(cpv) + + try: + self.queue.remove_with_children(self.iterators[cpv]) + except KeyError: + debug("'%s' should be removed, but is not in queue.", cpv) |