summaryrefslogtreecommitdiff
path: root/portato/gui/updater.py
blob: d6087ee815ce5f472c2b41d6286ec1ae376ac238 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# -*- 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, error

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 and self.remove(self.find(curr)) # remove the previous
				curr = this
			
			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 = system.find_packages("=%s" % pv, only_cpv = True)

		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)
			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

		try:
			self.queue.remove_with_children(self.iterators[cpv])
		except KeyError:
			debug("'%s' should be removed, but is not in queue.", cpv)
ss='insertions'>+10 2017-08-29emacs: --run-async: Quote shell argumentsDamien Cassou1-4/+5 This is important for filenames with special characters such as spaces and parenthesis. 2017-08-29emacs: Update author's email addressSvend Sorensen1-2/+2 2017-08-29emacs: Fix package-lint violationsSvend Sorensen1-2/+3 2017-07-26emacs: Release version 1.0.0 of Emacs packageSvend Sorensen2-1/+8 2017-07-26emacs: Use with-editor to wrap "pass edit"Svend Sorensen2-9/+17 Instead of editing the password file directly using Emacs, "pass edit" is run. This allows password-store's git change tracking to work. This adds a dependency on the with-editor Emacs package. 2017-04-13Bump version1.7.1Jason A. Donenfeld1-1/+1 2017-04-13init: match only the public keyJason A. Donenfeld1-1/+1 2017-03-28Use $GPG variableJason A. Donenfeld1-3/+3 2017-03-20Fix compatibility with GnuPG 2.2.19Andreas Stieger2-2/+2 GnuPG 2.2.19 added a warning when no command was given. * src/password-store.sh (reencrypt_path): Add --decrypt to --list-only * tests/t0300-reencryption.sh (gpg_keys_from_encrypted_file): same https://bugs.gnupg.org/gnupg/msg9873 http://git.gnupg.org/cgi-bin/gitweb.cgi?p=gnupg.git;a=commit;h=810adfd47801fc01e45fb71af9f05c91f7890cdb https://bugzilla.suse.com/show_bug.cgi?id=1028867 2017-03-01tests: fix on OSX by not using the tr hackJason A. Donenfeld3-5/+2 2017-02-26Bump version1.7Jason A. Donenfeld1-1/+1 2017-02-26Modernize makefileJason A. Donenfeld2-31/+36 2017-02-25CopyrightJason A. Donenfeld1-1/+1 2017-02-25StyleJason A. Donenfeld1-2/+2 2017-02-25git: use inner-most directoryJason A. Donenfeld2-27/+48 2017-02-25clip: sleep may require argv[0] to be sleepJason A. Donenfeld1-1/+1 2017-02-25man: document system extensionsJason A. Donenfeld1-2/+3