3 ## func command line interface & client lib
5 ## Copyright 2007,2008 Red Hat, Inc
6 ## Adrian Likins <alikins@redhat.com>
9 ## This software may be freely redistributed under the terms of the GNU
10 ## general public license.
12 ## You should have received a copy of the GNU General Public License
13 ## along with this program; if not, write to the Free Software
14 ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 # this module lets you define groups of systems to work with from the
19 # commandline. It uses an "ini" style config parser like:
22 #host = foobar, baz, blip
32 def __init__(self
, filename
="/etc/func/groups"):
33 self
.filename
= filename
40 self
.cp
= ConfigParser
.SafeConfigParser()
41 self
.cp
.read(self
.filename
)
43 for section
in self
.cp
.sections():
44 self
.add_group(section
)
45 options
= self
.cp
.options(section
)
46 for option
in options
:
48 self
.add_hosts_to_group(section
, self
.cp
.get(section
, option
))
49 if option
== "subgroup":
54 print self
.cp
.sections()
57 def add_group(self
, group
):
60 def __parse_hoststrings(self
, hoststring
):
62 bits
= hoststring
.split(';')
64 blip
= bit
.strip().split(' ')
67 hosts
.append(host
.strip())
71 def add_hosts_to_group(self
, group
, hoststring
):
72 hosts
= self
.__parse
_hoststrings
(hoststring
)
74 self
.add_host_to_group(group
, host
)
78 def add_host_to_group(self
, group
, host
):
79 if not self
.groups
.has_key(group
):
80 self
.groups
[group
] = []
81 self
.groups
[group
].append(host
)
89 g
= Groups("/tmp/testgroups")
94 if __name__
== "__main__":