2c95845c839d2fb34e97188da7f7e88856b66d85
1 # Copyright 2007 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
7 from portage
import _unicode_decode
8 from portage
._sets
.base
import PackageSet
9 from portage
._sets
import SetConfigError
11 __all__
= ["CommandOutputSet"]
13 class CommandOutputSet(PackageSet
):
14 """This class creates a PackageSet from the output of a shell command.
15 The shell command should produce one atom per line, that is:
23 name: A string that identifies the set.
24 command: A string or sequence identifying the command to run
25 (see the subprocess.Popen documentaion for the format)
27 _operations
= ["merge", "unmerge"]
29 def __init__(self
, command
):
30 super(CommandOutputSet
, self
).__init__()
31 self
._command
= command
32 self
.description
= "Package set generated from output of '%s'" % self
._command
35 pipe
= subprocess
.Popen(self
._command
, stdout
=subprocess
.PIPE
, shell
=True)
36 stdout
, stderr
= pipe
.communicate()
37 if pipe
.wait() == os
.EX_OK
:
38 self
._setAtoms(_unicode_decode(stdout
).splitlines())
40 def singleBuilder(self
, options
, settings
, trees
):
41 if not "command" in options
:
42 raise SetConfigError("no command specified")
43 return CommandOutputSet(options
["command"])
44 singleBuilder
= classmethod(singleBuilder
)