summaryrefslogtreecommitdiffstats
path: root/pym/portage/_sets/shell.py
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2010-08-30 00:16:50 -0700
committerZac Medico <zmedico@gentoo.org>2010-08-30 00:16:50 -0700
commit25d8427b3b29cbcee97279186983dae818495f8f (patch)
tree36e05fdb10b3fc418686f59010ae4133428f7884 /pym/portage/_sets/shell.py
parent445f0d70d3624bc108b08da6d370bf194fcfc4ac (diff)
downloadportage-25d8427b3b29cbcee97279186983dae818495f8f.tar.gz
portage-25d8427b3b29cbcee97279186983dae818495f8f.tar.bz2
portage-25d8427b3b29cbcee97279186983dae818495f8f.zip
Rename the portage.sets module to portage._sets since it will be useful
in the upcoming 2.1.9 branch which will not have sets support but will still have the code in private and disabled form.
Diffstat (limited to 'pym/portage/_sets/shell.py')
-rw-r--r--pym/portage/_sets/shell.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/pym/portage/_sets/shell.py b/pym/portage/_sets/shell.py
new file mode 100644
index 000000000..2c95845c8
--- /dev/null
+++ b/pym/portage/_sets/shell.py
@@ -0,0 +1,44 @@
+# Copyright 2007 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+import subprocess
+
+from portage import os
+from portage import _unicode_decode
+from portage._sets.base import PackageSet
+from portage._sets import SetConfigError
+
+__all__ = ["CommandOutputSet"]
+
+class CommandOutputSet(PackageSet):
+ """This class creates a PackageSet from the output of a shell command.
+ The shell command should produce one atom per line, that is:
+
+ >>> atom1
+ atom2
+ ...
+ atomN
+
+ Args:
+ name: A string that identifies the set.
+ command: A string or sequence identifying the command to run
+ (see the subprocess.Popen documentaion for the format)
+ """
+ _operations = ["merge", "unmerge"]
+
+ def __init__(self, command):
+ super(CommandOutputSet, self).__init__()
+ self._command = command
+ self.description = "Package set generated from output of '%s'" % self._command
+
+ def load(self):
+ pipe = subprocess.Popen(self._command, stdout=subprocess.PIPE, shell=True)
+ stdout, stderr = pipe.communicate()
+ if pipe.wait() == os.EX_OK:
+ self._setAtoms(_unicode_decode(stdout).splitlines())
+
+ def singleBuilder(self, options, settings, trees):
+ if not "command" in options:
+ raise SetConfigError("no command specified")
+ return CommandOutputSet(options["command"])
+ singleBuilder = classmethod(singleBuilder)